I am importing excel data using html, spring and apache POI API. I need to do some validations before saving the data.
For a cell, I need to check whether its value is greater than 01 and less than 32.
I have seen like
cell.getStringCellValue().matches(regex);
Using this I have reached in a solution like this
if(cell.getStringCellValue().matches("\b([1-9]|[12][0-9]|3[01])\b"))
But I have read like, using regExp for comparing numbers is not such a good Idea, it is mainly for strings.
So my question is , is there a better way to solve my problem, finding whether the cell value falls within a range.
You need to add 0 before [1-9] inorder to match the number range from 01 to 09.
\b(0[1-9]|[12][0-9]|3[01])\b
Related
I am currently working on a spreadsheet formula where 2 different codes would be generated. Here is the algorithm for the "code" to start with., but I don't know how to construct a proper excel function for it.
There are 10 digits to the code where the first 8 digits are just the date i.e. 20210328_ _
The final 2 digits are dependent on the previous records whether there are records with the same date. If so it would assign a two-digit number starting from 1 to differentiate the different records.
I have tried to use the below formula to achieve what I want but the part where it references the other spreadsheet is bothering me as I need it to be a flexible value where the value is referring to the last row of the spreadsheet. Is there a way to work around this without scripts? I am planning to deploy it on Google Sheets so App scripts solutions would also be workable but not preferable.
=IF(DAY(B2)=RIGHT(Data!A114,2),Data!A114+1,CONCATENATE(YEAR(TODAY()),TEXT(B2,"MM"),DAY(TODAY()),"01"))
FYI B2 is the date of input and Data!A114 is the part where I concern.
Here's what I came up with.
Formula(D3)=IF((TO_PURE_NUMBER(Concatenate(YEAR(A3), TEXT(A3,"MM"),DAY(A3))) - TO_PURE_NUMBER(Concatenate(YEAR(A2),TEXT(A2,"MM"),DAY(A2)))), (TO_PURE_NUMBER(CONCATENATE(TO_PURE_NUMBER(Concatenate(YEAR(A3), TEXT(A3,"MM"),DAY(A3))), "00"))) ,(D2+1))
The data for the dates starts in A3, and continues down.
Link to the Google Sheet I tried it on.
https://docs.google.com/spreadsheets/d/1bwukKFaEow4PysqcJLA9jqjKBLZcY8T1vTN5VpZo8F8/edit?usp=sharing
Let me know if this worked.
I have a Google Sheets Apps Script that uses this method to store data:
sheet.getRange(rowNumber, colNumber).setValue(theString);
Later, those values are retrieved using:
theRowData = sheet.getRange(r, FIRST_DATA_COLUMN, 1, MAX_COLS).getValues()[0];
This seems to be working fairly well except when theString contains a value that looks like a date (such as "6-Dec-2020". Then, getValues() seems to be retrieving a date value (and then converting it to a very verbose string) rather than the string that was written. In this case, I do not want such evaluation of what the data means. I intend to write these values as constants that don't need nor desire interpretation (such as would be done by apostrophe in Excel with a value like "'6-Dec-2020"). Is there a way to retrieve exactly the same value that was stored (or the store exactly the value that was intended), in exactly the same format?
For this specific problem example, I'm getting back "Sun Dec 06 2020 00:00:00 GMT-0500 (Eastern Standard Time)" when what I wrote (and what I want returned) is "6-Dec-2020" . I do realize I could set number formats, but that won't always work, as these values (that admittedly look like dates) are sometimes in other formats, like "6-Dec" among others, and I would need "6-Dec" back when reading in that case.
Use getDisplayValue() or getDisplayValues().
The displayed value takes into account date, time and currency formatting formatting, including formats applied automatically by the spreadsheet's locale setting
Background
I'm converting old 4D code from class queries to ORDA queries. One thing I can't figure out is how to query with a field vs a field, rather than a field vs a value.
Edit: I'm using 4D v17.4.
Example
Classic:
Query([Customers];[Customers]State="IN")
ORDA:
ds.Customers.query("State = 'IN'")
Goal
I want to be able to query a table for results where I'm comparing a field value vs another field value. I can do it in classic querying via the following:
Query([Customers];[Customers]State#[Customers]AdministrativeRegion)
What I Tried
ds.Customers.query("State # AdministrativeRegion") // DOESN'T WORK
Question
Is this possible?
You didn't mention which version of 4D you are using. 4D is changing very rapidly these days and the difference between them can really matter, though in this case not as much.
Using placeholders in your query string is the first step.
Instead of
ds.Customers.query("State # AdministrativeRegion")
do
ds.Customers.query("State # :1 ";"some value")
Each placeholder is referenced by the :n syntax starting at 1. This is a big benefit because 4D will manage converting the comparison value data type. This is also the key to referencing a value in an entity, object, formula, etc.
$entity_selection:=ds.Customers.query("State # :1";$entity.State)
where $entity is the one you want to compare to.
I would rather use ds.Customers.query(":1";Formula(This.State#This.AdministrativeRegion))
I am having a few issues using SSRS-Reports 2005.
The first one is I am trying to use the datediff function to change the background color of a cell based on the two dates being within 30 days of each other.
=iif(
DateDiff("d",DateString,Fields!Insurance_Certificate.Value)<= 30, "Tan", "White"
)
I have my fields formatted through the initial query so they look like mm/dd/yyyy. I guess my first question is how do I see what value is being evaluated because whatever this is returning can't be right.
my [...] question is how do I see what value is being evaluated
There is no real "debugger" available like you would have in -say- a WinForms C# app. Instead, you have several "raw" "debugging" options:
Render Fields!Insureance_Certificate.Value in a seperate cell, as text
Render DateDiff("d",DateString,Fields!Insurance_Certificate.Value) in a seperate cell, as text
Right-click your dataset, select "Query...", and execute the query manually. Inspect the values for your field. Make sure they're what you'd expect.
Render your DateString in a seperate cell, with and without a cast to a date.
Other than that #MarkBannister has a great suggestion, using actual Dates as opposed to strings for your fields and variables. One additional thing to note about this, is that date parsing may be culture-specific. Be sure you understand and know in what culture your DateString is being parsed. The above "debugging" options may help you find out.
I suggest querying your date fields as dates (instead of as strings), comparing them using the DateDiff function as in the question and formatting the date output using the Format property of the appropriate textboxes in SSRS.
An Access DB imports a fixed width text file; one column is mostly dates.
When the date is not available, the file's creator actually uses the string "Null"
Access puts the row in the table with that field actually null.
But, when the files started coming with different field widths, I copied the DB, tweaked the starting/width values in the input spec, and imported. NOW, all the rows with null get logging in (table)_import_errors as an error converting text to date.
I have found no setting (not that I changed any) to explain it. One difference is that although both DBs are in Access 2000 format, the original is on a machine that still has Access 2000, while the new one is being handled by Access 2003.
Is that a behavior change in the Access version? Is pre-processing the file the only solution?
Thanks, David. That's what I would have done (except for the Excel part) if it had not fixed itself. I posted that, but apparently someone didn't like the public admission that Access has bugs.
The only thing that changed was that two other columns in the fixed width plain text input was wider. Yet Access "decided" to discard the whole row instead of just the date field for three consecutive attempts. The fourth time, it still reported it as an error but imported the rest of the row.
So, when Access misbehaves for no good reason, try again a time or two, then try explicitly coding the conversion from text.
Two possibilities:
Use a buffer field or buffer table that imports the date field into a text field. Then you can process that into the appropriate values in the final destination field.
Use a SQL import instead of DoCmd.TransferText. What you do in that case is use a connect string in the FROM clause so you can then process the date field in your SELECT:
SELECT Sheet1.FirstField, Replace(Sheet2.DateField, "NULL", Null) As DateField
FROM Sheet1 IN 'C:\Import\Spreadsheet.xls'[Excel 5.0;HDR=YES;IMEX=1;];
Convert that into an INSERT query and you're golden.