Aspose cells java data formats

Hi, All the data (i.e. date, number, Boolean and string) from source database comes in the form of strings. Now my requirement is to convert them into respective data types and apply data formats on them. The data formats usually for date and numbers. Please let me know better way to achieve this.

@koteswaragunda
Please refer to the following documents on how to format cell data.

@koteswaragunda,

Please note, you have to convert/change the existing string data in the cells (after you have imported from the data source) to the relevant data type yourselves first. Number formatting won’t be applied unless you have converted the data in the cells to the proper data type. One way can be you re-insert the existing string/data using the overload Cell.putValue(string stringValue, bool isConverted) into those worksheet cells. See the sample code for your reference.
e.g.,
Sample code:

Workbook book = new Workbook("f:\\files\\Sample Excel.xlsx");
Worksheet sheet = book.getWorksheets().get(0);
Range range = sheet.getCells().createRange("A2", "A10");//create your desired range of cells
Iterator rangeIterator = range.iterator();
while(rangeIterator.hasNext())
{
            Cell cell = (Cell)rangeIterator.next();
            cell.putValue(cell.getStringValue(), true);
            //your code goes here.
}

Hope, this helps a bit.

Hi @John.He & @amjad.sahi

Thanks for your responses. it helped but some difficulty facing for number format, negative format and currency. Not getting idea how to apply all 3 formats like number format, -ve number format and currency at once. Please suggest.

@koteswaragunda
Would you please provide some examples in one template file to demonstrate the formattings you want to set for different type of cells? That will make us know your requirement better and so we can provide the proper solution for you.