Hi.
I have a csv file “myfile.csv” that contains XML data.
If I rename it to “myfile.xls” and I open it with Excel, I can see it like an excel file.
Now I want to read the csv file with Aspose Cells.
I try this code to read it :
LoadOptions loadOptions = new LoadOptions(LoadFormat.CSV);
Workbook workbook = new Workbook(file.getAbsolutePath(), loadOptions);
Worksheet worksheet = workbook.getWorksheets().get(0);
Cells cells = worksheet.getCells();
System.out.println(cells.get(0, 0).getStringValue());
It return the xml content like this : <?xml version="1.0" encoding="utf-8"?>
I want to convert this in a xls file to read it like an Excel file.
So I try this :
workbook.save(“myfile.xls”, SaveFormat.EXCEL_97_TO_2003);
But when I read it, it contains xml.
What can I do to read the CSV file like an Excel file ?
Hi Yannick,
Hi.
I try to open the file with the option LoadFormat.Auto but I have this error :
java.lang.NullPointerException
at com.aspose.cells.a.c.h.b(Unknown Source)
at com.aspose.cells.akg.b(Unknown Source)
at com.aspose.cells.Workbook.isColorInPalette(Unknown Source)
at com.aspose.cells.apm.a(Unknown Source)
at com.aspose.cells.apm.d(Unknown Source)
at com.aspose.cells.apm.i(Unknown Source)
at com.aspose.cells.apm.h(Unknown Source)
at com.aspose.cells.apm.a(Unknown Source)
at com.aspose.cells.apm.a(Unknown Source)
at com.aspose.cells.Workbook.a(Unknown Source)
at com.aspose.cells.Workbook.a(Unknown Source)
at com.aspose.cells.Workbook.(Unknown Source)
at Test.main(Test.java:14)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
LoadOptions loadOptions = new LoadOptions(LoadFormat.AUTO);
Workbook workbook = new Workbook(file.getAbsolutePath(), loadOptions); // error here
Hi,
Thanks for your posting and using Aspose.Cells.
Please provide us your CSV file so that we replicate this issue at our end and in case of bug, log it in our database for a fix.
Hi.
Here is the file.
Hi,
Thanks for your posting and using Aspose.Cells.
Please provide us your source CSV file. The file you attached is the output XLS file. We need your source CSV file to test this issue at our end.
It’s the same file. The extension was change from csv to xls to open it with Excel.
Hi,
Sample code:
LoadOptions loadOptions = new LoadOptions(LoadFormat.SPREADSHEET_ML);
Workbook workbook = new Workbook(“export.xls”, loadOptions);
Worksheet worksheet = workbook.getWorksheets().get(0);
Cells cells = worksheet.getCells();
System.out.println(cells.get(0, 0).getStringValue());
Ok. Thanks for your help.
Hi,
Hi.
I download the new version and try it but I have an error.
I use this code :
public static void main(String[] args) {
LoadOptions loadOptions = new LoadOptions(LoadFormat.SPREADSHEET_ML);
Workbook workbook = null;
try {
workbook = new Workbook(“export.xls”, loadOptions);
Worksheet worksheet = workbook.getWorksheets().get(0);
Cells cells = worksheet.getCells();
System.out.println(cells.get(0, 0).getStringValue());
} catch (Exception e) {
e.printStackTrace();
}
}
And the error is :
java.lang.NullPointerException
at com.aspose.cells.a.c.zh.b(Unknown Source)
at com.aspose.cells.zals.b(Unknown Source)
at com.aspose.cells.Workbook.isColorInPalette(Unknown Source)
at com.aspose.cells.zarn.a(Unknown Source)
at com.aspose.cells.zarn.d(Unknown Source)
at com.aspose.cells.zarn.i(Unknown Source)
at com.aspose.cells.zarn.h(Unknown Source)
at com.aspose.cells.zarn.a(Unknown Source)
at com.aspose.cells.zarn.a(Unknown Source)
at com.aspose.cells.Workbook.a(Unknown Source)
at com.aspose.cells.Workbook.a(Unknown Source)
at com.aspose.cells.Workbook.(Unknown Source)
at Test.main(Test.java:12)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
Hi,
Hi,
Thanks for using Aspose.Cells for Java.
Please download and try this fix: Aspose.Cells for Java v8.4.0.8 and let us know your feedback.
Hi.
This time it works fine.
The new version resolve my issue.
Thanks for your help.
Hi Yannick,
The issues you have found earlier (filed as CELLSJAVA-41265) have been fixed in this update.
This message was posted using Notification2Forum from Downloads module by Aspose Notifier.