We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Date format should be same after converting to number

Hi Team,



I am using ASPOSE 8 jar with Java.



If I tried to convert text value to number, my date column format get changed.



Input : 7/10/2014

Output : 2014-07-10T00:00:00



Expected output after convert to number function calling :

Output : 7/10/2014



public static void main(String[] args) throws Exception{



String clonePath = “D:\ASPOSE\CSV_EXCEL2_import.xlsx”;

Workbook wb = new Workbook(clonePath);

String anchorNamedCell = “Anchor1”;





Worksheet worksheet = wb.getWorksheets().getRangeByName(anchorNamedCell).getWorksheet();

System.out.println(worksheet.getName());

Range headerRangeAnchr = wb.getWorksheets().getRangeByName(anchorNamedCell);



Range measureRange = worksheet.getCells().createRange(“D21:E30”);



convertToNumber(worksheet, measureRange);

wb.save(“D:\ASPOSE\CSV_EXCEL_output.xlsx”);

System.out.println(“DONE !!!”);

}

public static void convertToNumber(Worksheet worksheet,Range rangeCells) throws Exception {

try {

Cells cells = worksheet.getCells();

for (int i=0; i
for (int j=0; j<rangeCells.getColumnCount(); j++) {

Cell cell = cells.get(rangeCells.getFirstRow()+i, rangeCells.getFirstColumn()+j);

String value = cell.getValue()==null?"":cell.getValue().toString();

if(value.length() == 0){

worksheet.getCells().clearContents(cell.getRow(), cell.getColumn(), cell.getRow(), cell.getColumn());

}else{

cell.putValue(value, true);

}

}

}

Please update me on this.

Thanks in advance.

Hi,

Thanks for your posting and using Aspose.Cells.

For this your situation, you should use Cell.getStringValue() instead of Cell.getValue().toString() in your code:


String value = cell.getValue()==null?"":cell.getStringValue();// cell.getValue().toString();