Convert XML to MS Excel(.xls) through Java API

Hi Team ,

I want to convert an xml to xls, below is the example. xml tags will be Header’s in excel & we will store the xml tag values in a property file and aspose api should pick from the corresponding xml tags & need to create a excel.

<soap:Envelope xmlns:soap=“http://schemas.xmlsoap.org/soap/envelope/”>

soap:Body

Kranthi

Morthala

</soap:Body>

</soap:Envelope>

Please share the code for the same ?

Thanks,

Kranthi

Hi,


Well, I am afraid, we do not support to directly import or read general/ common XML files to Excel sheet. Aspose.Cells does support SpreadsheetML file format though which is MS Excel oriented XML representation of Excel data/ contents. I think if you could read your XML file to fill an array or DataTable etc. by yourself (using your own codes), you may then try to use Aspose.Cells API (e.g Cells.importArray() etc.) to import data into Ms Excel workbook.

Thank you.

Hi,


I have an approach like converting xml to spreadsheetML & from spreadsheetML to excel.

What is your suggestion on this approach ?


Hi,

Yes, if you could convert XML data to spreadsheetML file, you may use Aspose.Cells to load/read that file via Aspose.Cells’ Workbook object.

e.g

Sample code:

Workbook book = new Workbook(“e:\test2\myspreadsheetml.xml”, new LoadOptions(LoadFormat.SPREADSHEET_ML));

book.Save(“e:\test2\out1.xlsx”, SaveFormat.XLSX);

Thank you.

Hi Team,


We have another approach i.e, convert the xml data into Array Data.

Can you please share the Java implementation to insert the Array Data into MS excel.

Thanks,
Kranthi

Hi,


Please see the document on different Data Importing options that Aspose.Cells for Java supports to import arrays, lists, resultset objects etc. via its APIs for your needs for your reference:
https://docs.aspose.com/display/cellsnet/Import+Data+into+Worksheet

Thank you.

Hi Team,


When we implement the below code, the data is inserted into Sheet 2, actually we want to insert into Sheet 1.

Workbook workbook = new Workbook();
int sheetIndex = workbook.getWorksheets().add();
Worksheet worksheet= workbook.getWorksheets().get(sheetIndex);
Cells cells = worksheet.getCells();
ArrayList list=new ArrayList();
list.add(employee.getDepartment());
list.add(employee.getName());
list.add(employee.getProject());
cells.importArrayList(list,0,0,true);
workbook.save(“Unmarshalling.xls”);

Please find the attached excel for reference.

Also please provide the java code for inserting 2D, 3D array data into excel

Thanks,
Kranthi

I have fixed the above issue, please ignore it.


please share the java code for inserting multi dimentional(2D,3D) array data into excel i.e, into multiple columns in excel.

Hi,


1) Good to know that you have figured it out by yourself and rightly so, if you need to get the first worksheet (default sheet), you may use the following sample line of code:
e.g
Sample code:
Worksheet worksheet= workbook.getWorksheets().get(0);

2) Please see the following sample code on how to import multi-dimensional array into Excel sheet via Aspose.Cells APIs, please refer to it:
e.g
Sample code:

Workbook workbook = new Workbook();
Cells cells = workbook.getWorksheets().get(“Sheet1”).getCells();
String[][] strArray = {
{“A”, “1A”,“2A” },
{“B”, “2B”, “3B”}
};
cells.importArray(strArray, 0, 0);

workbook.save(“outarrays1.xlsx”);


Hope, this helps a bit.

Thank you.


how u fix that issue…can u send me the code for that

Hi Mahalakshmi,


Please see and follow up your other thread for your reference:
<a href="https://forum.aspose.com/t/33260

Thank you.