Converting file from CSV to Excel format

Hi All,

I have been trying few Aspose sample program to convert CSV files to Excel. Below is the sample code which I have tried:

//Specify the LoadOptions
LoadOptions opt = new LoadOptions(LoadFormat.CSV);
//Set the memory preferences
opt.setMemorySetting(MemorySetting.MEMORY_PREFERENCE);
Workbook wb4 = new Workbook("e://Source.txt", opt);
wb4.save("SourceXLS3.xls",FileFormatType.EXCEL_97_TO_2003);
Workbook wb5 = new Workbook("e://Source.txt", opt);
wb5.save("SourceXLS4.xlsx",FileFormatType.XLSX);


I got few doubts about this code.

1. Is this the right way or the most efficient way of converting CSV file to Excel format?
2. For what conditions or file size, I should use MEMORY_PREFERENCE?
3. How the MEMORY_PREFERENCE internally works? How it effects the performance of conversion?
4. Is there anything else, which I should take care while implementing the code?
5. When I open the saved output file in excel, I get the date in format of ###### even though internally it the date is stored correctlIy. If I look at the Excel Formating Type, it shows the format as *14-03-2012. The excel describes the date formats begining with an asterik(*) respond to changes in the regional date and time settings that are specified for the operating system.

The question is that how can I set the date format while conversion so that I don't have to see dates in ##### format?

Thanks,
Aditya

Hi,


Thanks for your query and details.

1) I think you are doing OK for CSV to XLS/XLSX conversion. Furthermore, you may try to instantiate TxtLoadOptions and spcify your desired options on/off while loading your template CSV file for your requirements, see the document for your reference:

2) and 3)
When reading a big Microsoft Excel file, the process would surely consume more RAM. Aspose.Cells provides this feature (via options and API calls) to lower, reduce and optimize memory use. Also, it can help the process work more efficiently and run faster. See the document for your reference:
http://www.aspose.com/docs/display/cellsjava/Optimizing+Memory+Usage+while+Working+with+Big+Files+having+Large+Datasets

4) Well, if you are saving the same CSV file to different file formats e.g XLS and XLSX, you should not re-load the CSV file again, so you may simply try:
e.g
Sample code:
wb4.save(“SourceXLS3.xls”,FileFormatType.EXCEL_97_TO_2003);
wb4.save(“SourceXLS4.xlsx”,FileFormatType.XLSX);

5) Well, you would need to extend the columns’ width accordingly to cope with “######” issue. One way to cope with it is to use/call worksheet.autoFitColumns(); method before saving to Excel file formats.

And to specify the DateTime or other display numbers’ formattings, see the document for your reference:

Thank you.