Use a specific format to display numbers with Handsontable - globalization

I need to force Handsontable to display numbers with a specific format (1.000,01 for example) but it seems to ignore what I try to use as thousands separator.
I tried several ways to do that but none worked :
Setting a format to cells that will contain numeric values cell.format = '0.0,00'
Setting the same format when instantiating my handsontable object myTable.handsontable({ format: '0.0,00' })
Create a locale for numeral.js with delimiters { thousands: '.', decimal: ',' }
Changing the format used in a working jsFiddle (from handsontable doc) but I can't get the desired display
Any idea what I'm missing ?

You're right, numeraljs just isn't there yet unfortunately. It works a little better if you use the format using square brackets but it's still not perfect.
Here's a potential format string that seems to work in many cases, but not all:
0.0[,]00 $

Related

sheetJS number format issues - European number format

I am trying to convert the float number to European formats.
I tried to assign a format like below but it's not converting properly.
works fine:
cell.z = "#,###,##0.00";
does not work:
cell.z = "#.###.##0,000"
cell.z = "# ### ##0,000";
If it is not possible can I at least declare decimal values as comma (,) separator?
Can you please provide some pointers?
We do not need to add any special format to the number. I solved the problem by converting it to a number (Not String), excel will open based on user settings. No additional development is required.

Decimal number in string-data-type with large amount of decimals always interpreted as large integer (regional decimal separator issue)

Background: I'm receiving data for my Excel application from an API in JSON format. For this matter I'm receiving numerical values as a string, as everything sent in JSON naturally is a text format - and so does VBA also interpret it. As I'm located in Denmark, using a different decimal separator than the native on in Excel (my Danish version utilizes , as separator rather than .).
Case:
This is causing quite a bit of trouble as Excel interprets this as a thousand-separator when converting the string to a number.
Searching for answers I've found that the best solution, normally, is to convert the string to double when using VBA, utilizing CDbl(string to convert to number).
This usually is the case, but in my case I'm receiving a number with a lot of decimals such as: "9.300000190734863".
When doing a CDbl("9.300000190734863") this results in a very large integer: 9,30000019073486E+15
Also, I don't think utilizing a replace() approach is feasible in my case as I might also have data that uses both decimal- and thousand separators at the same time, making my results prone to replacement errors.
However, inserting the string value directly into a cell within Excel converts the number correctly to 9,30000019073486 in my case.
Question: Can it be right that there's no way to mimic, or tap into, this functionality that Excel obviously is using when inserting the string into a cell?
I've searched for quite some time now, and I haven't found any solution other than the obvious: inserting the value into a cell. The problem here is that it's giving me some performance overhead which I would rather avoid.
You can swap the positions of the periods and commas in your input prior to casting as a double, in three steps:
Replace commas with 'X' (or some other value that won't appear in your data)
Replace periods with commas
Replace 'X' with periods

How to get Str() to left align in MS Access 2013

Using the built in evaluation function Str() to convert a number to a string the resultant number seems to come with a preceding space which is messing with my report formatting. Entries with numbers indent slightly relative to those without. Is there a simple solution to this - or even a complicated one?
Example: Calculated field using:
IIf([NumNights]=1,"Wibble",Str([NumNights])+" nights")
Produces (in the table, but also on any report using this):
Take a look at trim():
Trim(Str([NumNights]))
Or use CStr:
IIf([NumNights]=1,"Wibble",CStr([NumNights])+" nights")

Using POI to find out format for a cell

What is the correct way to get the CellFormatType for a cell (DATE, NUMBER, TEXT, GENERAL) ?
cell.getCellStyle.getDataFormat() returns a Short value, which does not map to the above constants.
I cannot just use cell.getCellType for the following reason. For certain rows, there may be a string prefix like <> or > in front of the value. In that case, getCellType will return CELL_TYPE_STRING. So the only way to get the underlying type appears to be to look at the format for the column.
Thanks
I don't know a direct route from Cell to CellFormatType, but there are various ways to determine particular types:
General? getDataFormat will be 0 (or more reliably, getDataFormatString will be "General")
Date? Check out DateUtil.isCellDateFormatted
Text? Typically you'd check for Cell.getCellType = CELL_TYPE_STRING, but since you say you can't do this (see comments below), you could also try checking if getDataFormatString is "#" or "text" (both are possibilities for plain text)
Number? Again, usually you'd just check for CELL_TYPE_NUMERIC. Note that dates are also considered numbers, so check for dates first.
(If the cell type is CELL_TYPE_FORMULA you should check getCachedFormulaResultType instead)
I cannot just use cell.getCellType for the following reason. For certain rows, there may be a string prefix like <> or > in front of the value
I'm not familiar with this problem. Perhaps you have a custom format which prepends characters before the number? My notes on text detection above might help you in this case, but I suggest you double-check that your spreadsheet actually has the relevant information (i.e. it isn't just Excel being clever when you re-open the sheet): log the cell type, format and format string, and confirm that there actually is a difference on the relevant cells. It's possible that your cell is actually being saved as text, with no distinguishing mark. In this case, you'll need to add some special heuristics for your specific scenario.
Finally, since you seem confused about the returned value from CellStyle.getDataFormat; it's just an index in a sheet-wide index → format-string table. You can (and I'd say usually should) use getDataFormatString to get the string format directly. The standard cell formats are listed in BuiltinFormats, which you can use as a reference to see which format strings you might find (but always check the format string, not the ID, otherwise you'll fail to detect custom formats correctly).

FIxing MS Excel date time format

A reporting service generates a csv file and certain columns (oddly enough) have mixed date/time format , some rows contain datetime expressed as m/d/y, others as d.m.y
When applying =TYPE() it will either return 1 or 2 (Excel will recognize either a text or a number (the Excel timestamp))
How can I convert any kind of wrong date-time format into a "normal" format that can be used and ensure some consistency of data?
I am thinking of 2 solutions at this moment :
i should somehow process the odd data with existing excel functions
i should ask the report to be generated correctly from the very beginning and avoid this hassle in the first place
Thanks
Certainly your second option is the way to go in the medium-to-long term. But if you need a solution now, and if you have access to a text editor that supports Perl-compatible regular expressions (like Notepad++, UltraEdit, EditPad Pro etc.), you can use the following regex:
(^|,)([0-9]+)/([0-9]+)/([0-9]+)(?=,|$)
to search for all dates in the format m/d/y, surrounded by commas (or at the start/end of the line).
Replace that with
\1\3.\2.\4
and you'll get the dates in the format d.m.y.
If you can't get the data changed then you may have to resort to another column that translates the dates: (assumes date you want to change is in A1)
=IF(ISERR(DATEVALUE(A1)),DATE(VALUE(RIGHT(A1,LEN(A1)-FIND(".",A1,4))),VALUE(MID(A1,FIND(".",A1)+1,2)),VALUE(LEFT(A1,FIND(".",A1)-1))),DATEVALUE(A1))
it tests to see if it can read the text as a date, if it fails, then it will chop up the string, and convert it to a date, else it will attempt to read the date directly. Either way, it should convert it to a date you can use

Resources