Cell formatting in a string

      Hi -

      Is it possible to get the cell format of a cell as a String?Im trying to obtain the date format for a particular cell. i.e. did the user format the cell as yyyy-mm-dd or m/dd/yyyy? I only see this "Style.Number" property - but I don't see a way to obtain the format string. Id like to be able to access the format string as was entered by the user (or selected by the user) in Excel

      Another related question, If the user uses a custom format in Excel for date display, does Aspose correctly detect this as a DateTime cell?

      i.e. so that Cell.getType() == CellValueType.DATETIME returns true.

Thanks,

This message was posted using Email2Forum by Tilal Ahmad Sana.

Hi,


To get a custom string, you may try to use Style.getCustom() method that returns style/formatting string.
e.g
Sample code:

//Setting the display format of the value to number 6 to show value as currency
Style style = cell.getStyle();
String customString = style.getCustom();

Note: For built-in number formats, you can use Style.getCultureCustom() to get its corresponding formatting string for your needs.

2) I think you may try to evaluate in switch case:
e.g
Sample code:

switch(cell.getType())
{
case CellValueType.IS_BOOL:
boolean b = ((Boolean)cell.getValue()).booleanValue();
break;
case CellValueType.IS_DATE_TIME:
Calendar calendar = (Calendar)cell.getValue();
break;
case CellValueType.IS_NUMERIC:
double d = ((Double)cell.getValue()).doubleValue();
break;
case CellValueType.IS_STRING:
String s = (String)cell.getValue();
break;
case CellValueType.IS_NULL:
// no value
break;
}


Let us know if I can be of any further help.

Thank you.