

User Guide EasyXLS Basics Import files Import XML data in .NET, Java and other programming languages Tweet Import XML data in .NET, Java and other programming languages Concept EasyXLS™ library allows you to import data from XML file or from XML string.



The methods that import XML data accept any XML schema, but for the best result, a schema similar with EasyXLS.xsd should be used. It is preferable that the schema contain data in a table format simulating the rows and columns, such as the mentioned schema or such as an HTML table and CDATA tag. The schema should also mention EasyXLS word. The tags like table, row and data can be named differently, but the table alike format is important. Concept in action The below example is a common code about how to import an XML string that contains data in a table format. Source code sample C#.NET VB.NET C++.NET J#.NET Java PHP ASP C++ VB6 VBS Coldfusion // Create an instance of the class that exports Excel files, having one sheet ExcelDocument workbook = new ExcelDocument(1); // Build XML string String xml = "<?xml version='1.0'?><Table><![CDATA[Generated by EasyXLS]]>" + "<Row><Data>Value 1</Data><Data>Value 2</Data></Row>" + "<Row><Data>Value 3</Data><Data>Value 4</Data></Row>" + "</Table>"; // Import data from an XML string into worksheet starting with A1 cell ExcelWorksheet xlsWorksheet = (ExcelWorksheet) workbook.easy_getSheetAt(0); xlsWorksheet.easy_insertXMLFromString(xml, "A1"); // Optionally, export Excel file workbook.easy_WriteXLSXFile("C:\\Samples\\Excel.xlsx"); ' Create an instance of the class that exports Excel files, having one sheet Dim workbook As New ExcelDocument(1) ' Build XML string Dim Xml = "<?xml version='1.0'?><Table><![CDATA[Generated by EasyXLS]]>" & vbCrLf & _ "<Row><Data>Value 1</Data><Data>Value 2</Data></Row>" & vbCrLf & _ "<Row><Data>Value 3</Data><Data>Value 4</Data></Row>" & vbCrLf & _ "</Table>" ' Import data from an XML string into worksheet starting with A1 cell Dim xlsWorksheet As ExcelWorksheet = workbook.easy_getSheetAt(0) xlsWorksheet.easy_insertXMLFromString(Xml, "A1") ' Optionally, export Excel file workbook.easy_WriteXLSXFile("C:\Samples\Excel.xlsx") // Create an instance of the class that exports Excel files, having one sheet ExcelDocument ^workbook = gcnew ExcelDocument(1); // Build XML string String ^xml = "<?xml version='1.0'?><Table><![CDATA[Generated by EasyXLS]]>" "<Row><Data>Value 1</Data><Data>Value 2</Data></Row>" "<Row><Data>Value 3</Data><Data>Value 4</Data></Row>" "</Table>"; // Import data from an XML string into worksheet starting with A1 cell ExcelWorksheet ^xlsWorksheet = safe_cast<ExcelWorksheet^>(workbook->easy_getSheetAt(0)); xlsWorksheet->easy_insertXMLFromString(xml, "A1"); // Optionally, export Excel file workbook->easy_WriteXLSXFile("C:\\Samples\\Excel.xlsx"); // Create an instance of the class that exports Excel files, having one sheet ExcelDocument workbook = new ExcelDocument(1); // Build XML string String xml = "<?xml version='1.0'?><Table><![CDATA[Generated by EasyXLS]]>" + "<Row><Data>Value 1</Data><Data>Value 2</Data></Row>" + "<Row><Data>Value 3</Data><Data>Value 4</Data></Row>" + "</Table>"; // Import data from an XML string into worksheet starting with A1 cell ExcelWorksheet xlsWorksheet = (ExcelWorksheet) workbook.easy_getSheetAt(0); xlsWorksheet.easy_insertXMLFromString(xml, "A1"); // Optionally, export Excel file workbook.easy_WriteXLSXFile("C:\\Samples\\Excel.xlsx"); // Create an instance of the class that exports Excel files, having one sheet ExcelDocument workbook = new ExcelDocument(1); // Build XML string String xml = "<?xml version='1.0'?><Table><![CDATA[Generated by EasyXLS]]>" + "<Row><Data>Value 1</Data><Data>Value 2</Data></Row>" + "<Row><Data>Value 3</Data><Data>Value 4</Data></Row>" + "</Table>"; // Import data from an XML string into worksheet starting with A1 cell ExcelWorksheet xlsWorksheet = (ExcelWorksheet) workbook.easy_getSheetAt(0); xlsWorksheet.easy_insertXMLFromString(xml, "A1"); // Optionally, export Excel file workbook.easy_WriteXLSXFile("C:\\Samples\\Excel.xlsx"); // Create an instance of the class that exports Excel files $workbook = new COM("EasyXLS.ExcelDocument"); // Create one sheet $workbook->easy_addWorksheet_2("My tab"); // Build XML string $xml = "<?xml version='1.0'?><Table><![CDATA[Generated by EasyXLS]]>" . "<Row><Data>Value 1</Data><Data>Value 2</Data></Row>" . "<Row><Data>Value 3</Data><Data>Value 4</Data></Row>" . "</Table>"; // Import data from an XML string into worksheet starting with A1 cell $xlsWorksheet = $workbook->easy_getSheetAt(0); $xlsWorksheet->easy_insertXMLFromString_3($xml, "A1"); // Optionally, export Excel file $workbook->easy_WriteXLSXFile("C:\Samples\Excel.xlsx");

' Create an instance of the class that exports Excel files set workbook = Server.CreateObject("EasyXLS.ExcelDocument") ' Create one sheet workbook.easy_addWorksheet_2("My tab") ' Build XML string Dim xml: xml = "<?xml version='1.0'?><Table><![CDATA[Generated by EasyXLS]]>" & _ vbNewline & "<Row><Data>Value 1</Data><Data>Value 2</Data></Row>" & _ vbNewline & "<Row><Data>Value 3</Data><Data>Value 4</Data></Row>" & _ vbNewline & "</Table>" ' Import data from an XML string into worksheet starting with A1 cell set xlsWorksheet = workbook.easy_getSheetAt(0) xlsWorksheet.easy_insertXMLFromString_3 xml, "A1" ' Optionally, export Excel file workbook.easy_WriteXLSXFile("C:\Samples\Excel.xlsx")

// Create an instance of the class that exports Excel files EasyXLS::IExcelDocumentPtr workbook; hr = CoCreateInstance(__uuidof(EasyXLS::ExcelDocument), NULL, CLSCTX_ALL, __uuidof(EasyXLS::IExcelDocument), (void**) &workbook) ; // Create one sheet workbook->easy_addWorksheet_2("My tab"); // Build XML string char* xml = (char*)malloc(536*sizeof(char)); strcpy(xml, "<?xml version='1.0'?><Table><![CDATA[Generated by EasyXLS]]>"); strcat(xml, "<Row><Data>Value 1</Data><Data>Value 2</Data></Row>"); strcat(xml, "<Row><Data>Value 3</Data><Data>Value 4</Data></Row>"); strcat(xml, "</Table>"); // Import data from an XML string into worksheet starting with A1 cell EasyXLS::IExcelWorksheetPtr xlsWorksheet = (EasyXLS::IExcelWorksheetPtr)workbook->easy_getSheetAt(0); xlsWorksheet->easy_insertXMLFromString_3(xml, "A1"); // Optionally, export Excel file workbook->easy_WriteXLSXFile("C:\\Samples\\Excel.xlsx");

' Create an instance of the class that exports Excel files Set workbook = CreateObject("EasyXLS.ExcelDocument") ' Create one sheet workbook.easy_addWorksheet_2 ("My tab") ' Build XML string Dim xml As String xml = "<?xml version='1.0'?><Table><![CDATA[Generated by EasyXLS]]>" & vbCrLf _ & "<Row><Data>Value 1</Data><Data>Value 2</Data></Row>" & vbCrLf _ & "<Row><Data>Value 3</Data><Data>Value 4</Data></Row>" & vbCrLf _ & "</Table>" ' Import data from an XML string into worksheet starting with A1 cell Set xlsWorksheet = workbook.easy_getSheetAt(0) xlsWorksheet.easy_insertXMLFromString_3 xml, "A1" ' Optionally, export Excel file workbook.easy_WriteXLSXFile ("C:\Samples\Excel.xlsx")

' Create an instance of the class that exports Excel files set workbook = CreateObject("EasyXLS.ExcelDocument") ' Create one sheet workbook.easy_addWorksheet_2 ("My tab") ' Build XML string Dim xml xml = "<?xml version='1.0'?><Table><![CDATA[Generated by EasyXLS]]>" & _ "<Row><Data>Value 1</Data><Data>Value 2</Data></Row>" & _ "<Row><Data>Value 3</Data><Data>Value 4</Data></Row>" & _ "</Table>" ' Import data from an XML string into worksheet starting with A1 cell set xlsWorksheet = workbook.easy_getSheetAt(0) xlsWorksheet.easy_insertXMLFromString_3 xml, "A1" ' Optionally, export Excel file workbook.easy_WriteXLSXFile("C:\Samples\Excel.xlsx")

<!-- Create an instance of the class that exports Excel files --> <cfobject type="java" class="EasyXLS.ExcelDocument" name="workbook" action="CREATE"> <!-- Create one sheet --> <cfset ret = workbook.easy_addWorksheet("My tab")> <!-- Build XML string --> <cfset xml = "<?xml version='1.0'?><Table><![CDATA[Generated by EasyXLS]]>" & "<Row><Data>Value 1</Data><Data>Value 2</Data></Row>" & "<Row><Data>Value 3</Data><Data>Value 4</Data></Row>" & "</Table>"> <!-- Import data from an XML string into worksheet starting with A1 cell --> <cfset xlsWorksheet = workbook.easy_getSheetAt(0)> <cfset xlsWorksheet.easy_insertXMLFromString(xml, "A1")> <!-- Optionally, export Excel file --> <cfset ret = workbook.easy_WriteXLSXFile("C:\Samples\Excel.xlsx")>

Import data from XML string EasyXLS library allows importing data from XML strings using ExcelWorksheet.easy_insertXMLFromString method. The above code sample shows how to achieve this goal. Import data from XML file EasyXLS library allows importing data from XML file using ExcelWorksheet.easy_insertXMLFromFile method similarly, as presented in the above code sample. Import XML Spreadsheet file EasyXLS allows you to import XML Spreadsheet Excel file. See also: Getting started with EasyXLS Excel library To download the trial version of EasyXLS Excel Library, press the below button:





If you already own a license key, you may login and download EasyXLS from your account.



See also:

Related methods:

Available for: Professional, Excel Reader, Excel Writer



EasyXLS Excel libraries: .NET Excel Library full .NET version to import, export or convert Excel files .NET Excel Writer .NET version to create and export Excel files .NET Excel Reader .NET version to read and import Excel files Java Excel Library full Java version to import, export or convert Excel files Java Excel Writer Java version to create and export Excel files Java Excel Reader Java version to read and import Excel files File formats: MS Excel 97 - 2003

MS Excel 2007 - 2010

MS Excel 2013

MS Excel 2016

MS Excel 2019