I’m using Aspose.Cells to extract and process Excel documents. For the extraction I’m using the workbook.save() method to save the Excel to CSV. Then I read the CSV to do the required processing. What I noticed is that the export to CSV loses some formatting rules, especially for date formatted cells. I really need the exported CSV to contain the same formatted values as the original Excel document.
I’m using the following code to export an Excel document to CSV:
Workbook wb = new Workbook();
wb.open(in);
wb.setCalculateBeforeSave(true);
wb.setCalculationMode(CalculationMode.AUTOMATIC);
wb.save(out, ‘|’, “UTF8”);
I also noticed that the month names are adjusted to the regional settings currently active on the machine the code is running. This behaviour also differs from Excel. Within MS Excel the month names do not change when switching between regional settings.
I attached the original Excel document together with 2 CSV export files (one is the result of the save with the NL regional settings applied and one with the UK regional settings). As you can see in the export files the first date is incorrectly formatted (1/14/2011 instead of 14/01/2011). Another difference is that the month name is changed according to the currently used regional settings.
I really need some help how to get a CSV export with exactly the same formatting as when the file is opened in MS Excel.
Kind regards,.
Hi,
setting.setLocale(java.util.Locale.UK);
Hi,
Thank you for your answer. I downloaded the latest version and it is working better now. However there are still some issues with cells formatted in long date. Please check the attachment for a graphical representation. The image contains views of Excel, format cells boxes, the CSV output and my operation system’s regional settings. As you can see I configured my system to use the Dutch regional settings, and the long date format is set to “day in week; day in month; month; year”. Cell A5 contains a fixed date format and should not change depending the regional settings, but in the CSV output it is using the configured Dutch regional settings. This is unexpected behaviour. As you can see in the left Format Cells box the date format is not prefixed with an asterisk (*) and should not switch date orders. The date in cell A6 is using the configured regional settings but the format in the CSV differs from Excel (vrijdag 14 januari 2011 vs vrijdag, januari 14, 2011).
Please help me how to fix this.
Kind regards,.
Hi,
Hi,
I have tested the version you sent to me and it is working better now, but there still are some issues. I get an different output when processing the file date_time-formats.xls [see attachment] with the UK regional settings. The long date differs (cell A1), but you already mentioned that you need more time to investigate that. Could you please also check the differences of the other two cells (A2 and A3)? And could you tell me how to fix this?
Kind regards,.
Hi,
Thank you!