Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(Unicode C) Parse the XML of an Excel (XLS) SpreadsheetDemonstrate how to access various items from the XML of an XLS (Excel) Spreadsheet. Our sample data is shown below, and can be downloaded from http://www.chilkatsoft.com/data/ndc_nhric_labeler_codes_04_29_2015.xls
<?xml version="1.0" version="1.0" encoding="utf-8" ?> <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="http://www.w3.org/TR/REC-html40"> <DocumentProperties xmlns="urn:schemas-microsoft-com:office:office"> <Version>14.00</Version> </DocumentProperties> <OfficeDocumentSettings xmlns="urn:schemas-microsoft-com:office:office"> <AllowPNG /> </OfficeDocumentSettings> <ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel"> <WindowHeight>7800</WindowHeight> <WindowWidth>12000</WindowWidth> <WindowTopX>105</WindowTopX> <WindowTopY>105</WindowTopY> <ProtectStructure>False</ProtectStructure> <ProtectWindows>False</ProtectWindows> </ExcelWorkbook> <Styles> <Style ss:ID="Default" ss:Name="Normal"> <Alignment ss:Vertical="Top" /> <Borders /> <Font ss:FontName="Arial" /> <Interior /> <NumberFormat /> <Protection /> </Style> <Style ss:ID="s63"> <Alignment ss:Vertical="Bottom" ss:WrapText="1" /> <Font ss:FontName="Arial" x:Family="Swiss" ss:Bold="1" /> <Interior ss:Color="#C0C0C0" ss:Pattern="Solid" /> </Style> <Style ss:ID="s64"> <NumberFormat ss:Format="@" /> </Style> </Styles> <Worksheet ss:Name="NDCLabelerCode"> <Table ss:ExpandedColumnCount="2" ss:ExpandedRowCount="8186" x:FullColumns="1" x:FullRows="1"> <Column ss:Index="2" ss:Width="580.5" /> <Row ss:AutoFitHeight="0" ss:Height="38.25"> <Cell ss:StyleID="s63"> <Data ss:Type="String">NDC Labeler Code</Data> </Cell> <Cell ss:StyleID="s63"> <Data ss:Type="String">Firm Name</Data> </Cell> </Row> <Row> <Cell ss:StyleID="s64"> <Data ss:Type="String">0002</Data> </Cell> <Cell ss:StyleID="s64"> <Data ss:Type="String">Eli Lilly and Company</Data> </Cell> </Row> ...
#include <C_CkXmlW.h> void ChilkatSample(void) { HCkXmlW xlsDoc; BOOL success; HCkXmlW xWorksheet; HCkXmlW x; int numChildren; int i; const wchar_t *data0; const wchar_t *data1; xlsDoc = CkXmlW_Create(); success = CkXmlW_LoadXmlFile(xlsDoc,L"myFiles/ndc_nhric_labeler_codes_04_29_2015.xls"); if (success != TRUE) { wprintf(L"%s\n",CkXmlW_lastErrorText(xlsDoc)); CkXmlW_Dispose(xlsDoc); return; } // This example will access the following pieces of data: // NDC Labeler Code, Firm Name, 0002, Eli Lilly and Company, ... // First navigate to the Worksheet named "NDCLabelerCode" xWorksheet = CkXmlW_GetChildWithAttr(xlsDoc,L"Worksheet",L"ss:Name",L"NDCLabelerCode"); // Next, get the Table node: x = CkXmlW_GetChildWithTag(xWorksheet,L"Table"); // How many immediate child nodes? numChildren = CkXmlW_getNumChildren(x); // Loop over each Row and access the cell contents. for (i = 0; i <= (numChildren - 1); i++) { // Navigate without creating new XML objects success = CkXmlW_GetChild2(x,i); if (CkXmlW_TagEquals(x,L"Row")) { data0 = CkXmlW_chilkatPath(x,L"Cell[0]|Data|*"); wprintf(L"%s\n",data0); data1 = CkXmlW_chilkatPath(x,L"Cell[1]|Data|*"); wprintf(L"%s\n",data1); } // Navigate back up. success = CkXmlW_GetParent2(x); } CkXmlW_Dispose(x); CkXmlW_Dispose(xWorksheet); CkXmlW_Dispose(xlsDoc); } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.