Hi Aspose Team,
Is there any way to convert .xml file to .xlsx file (or other microsoft excel file formats) using the aspose.cells component?
Regards
Rama
Hi Rama,
Thanks for your posting and using Aspose.Cells.
Aspose.Cells can open and convert the xml file that are related to MS-Excel. These are called SpreadsheetML. Not all types of xml can be opened though.
For example, I have attached one such file for your reference. The following code opens the attached xml file and converts it to xlsx file which is also attached for you to view.
Java
String filePath = “F:\Shak-Data-RW\Downloads\SampleExcel.xml”;
//Load the source workbook
Workbook workbook = new Workbook(filePath);
//Save the workbook
workbook.save(filePath + “.out.xlsx”);
Thank you for your prompt response regarding my question, as well as the sample files you attached. As you mentioned in your post, there are only specific types of xml that can be converted. Does the xml that can be converted have to have follow specific schemas or contain namespaces exactly as the ones below I noticed from your sample files?
<?mso-application progid="Excel.Sheet"?>
<Workbook xmlns=“urn:schemas-microsoft-com:office:spreadsheet”
xmlns:o=“urn:schemas-microsoft-com:office:office”
xmlns:x=“urn:schemas-microsoft-com:office:excel”
xmlns:ss=“urn:schemas-microsoft-com:office:spreadsheet”
xmlns:html=“HTML 4.01 Specification”>
Also, if I were to feed in a similar xml such as the one I attached along with this post, would the conversion work?
Thanks,
Rama
Hi Rama,
Thank you for the directions to create the xml data. I tried to run the code that Shakeel had written earlier to do the conversion, however I run into the below error. I tried with two different version of the aspose.cells library jars (aspose-cells-8.0.0 and aspose-cells-7.3.2.4), which resulted in the same error. I am not sure if I’m missing something else.
java.lang.NoClassDefFoundError: com/ctc/wstx/stax/WstxInputFactory
at com.aspose.cells.b.a.h.k.b(Unknown Source)
at com.aspose.cells.b.a.h.k.a(Unknown Source)
at com.aspose.cells.b.a.h.k.a(Unknown Source)
at com.aspose.cells.b.a.h.k.(Unknown Source)
at com.aspose.cells.b.a.h.k.(Unknown Source)
at com.aspose.cells.a.c.z.a(Unknown Source)
at com.aspose.cells.sa.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 xmlToExcelDataConversion.XmlToExcel2.main(XmlToExcel2.java:14)
Caused by: java.lang.ClassNotFoundException: com.ctc.wstx.stax.WstxInputFactory
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
… 11 more
Hi Rama,
I wasn’t able to find that jar in the same folder as the aspose jar. I currently have the free trial version of aspose-cells-8.0.jar. However I do have another version and its corresponding bcprov-jdk15-xxx.jar file. I tried re-testing after importing that jar, and the same error still appears. Any other imports I may be missing?
Thanks,
Rama
Hi,