Free Support Forum - aspose.com

Aspose cell gridweb cell input format issue


#1

Hi Aspose team,

I have some problem when input number in gridweb cell . When i input something like ‘1-2’ in a cell, it will convert to number 43102. I would like to have my own validation on cell using setOnAjaxCallFinishedClientFunction(). However, i get the cell value by gridwebins.getCellValueByCell(cell), and it already convert to 43102.
It seems like the cell format is set to number so that it will do the conversion. I tried to set the validation type as following but it does not work:

GridValidationCollection validations = gridwebsheet.getValidations();
GridValidation validation = validations.add();
validation.setShowError(true);
validation.setValidationType(ValidationType.ANY_VALUE);
gridweb.setForceValidation(false);

Is there any ways can i disable the auto conversion?
I am using aspose-cell version 18.7, thanks.

Regards,
Andy


#2

@andy2018,

Thanks for the details.

Well, Aspose.Cells.GridWeb (Java) follows MS Excel standards and works the same way as MS Excel does. When you directly enter “1-2” value into a cell in the worksheet (in MS Excel manually), MS Excel will convert to DateTime notations. In MS Excel DateTime value is saved as numeric value/numbers so you are getting “43102” as output in Aspose.Cells.GridWeb (Java). For your needs, you may try to set formatting as “Text” for your underlying cell, so when you enter such value (e.g “1-2”), it should be displayed as it is and does not convert to numeric value. See the following code segment which will work fine as I tested:
e.g
Sample code:

........
GridWorksheetCollection gridWorksheetCollection = gridweb.getWorkSheets();
GridCells gridCells = gridWorksheetCollection.get(gridWorksheetCollection.getActiveSheetIndex()).getCells();
GridCell B2 = gridCells.get("B2");
B2.setValue("1-2");
B2.setCustom("@");
..........

Hope, this helps a bit.


#3

Hi Amjad_Sahi,

Thanks for your reply.

I have try the above codes and it works only when the value is set by code. If i input a value from UI, then the value will convert to number 43102.


#4

@andy2018,

I think you may try to add relevant code (for setting numbers formatting as text) to load event of the web page/form, so relevant cell(s) should be formatted when the page/form is initialized/loaded and when you update any value in the cell visually, it should be formatted accordingly.