Message-ID: <2120474053.8059.1711630707291.JavaMail.web05$@web05> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_8058_1400136776.1711630707291" ------=_Part_8058_1400136776.1711630707291 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html
The parseXml method of this demo reads an XML file and parses i= t using XML DOM. The data is read into an array of type Object[][], a= nd then bound to the report with the BindData method.
=20 =20public class XmlImport { ///<summary> ///Build the report with ExcelTemplate ///</summary> public void GenerateReport() { //These are the names of the valu= es in WeatherData array string[] colNames =3D { "Dat= e", "Temp", "Humidity", "Wind" }; //Read the XML document into an o= bject array object[][] weatherData =3D ParseX= ml(); //Create an instance of SoftArtis= ans ExcelTemplate ExcelTemplate xlt =3D new ExcelTe= mplate(); //Open the template workbook = ; string templatePath =3D @"..= \..\ExcelTemplateFiles\XMLImportTemplate.xlsx"; xlt.Open(templatePath); //Bind the WeatherData array to t= he template // %%=3DWeather.Date, %%=3DWeathe= r.Temp // %%=3DWeather.Humidity, %%=3DWe= ather.Wind DataBindingProperties bindingProp= erties =3D xlt.CreateDataBindingProperties(); bindingProperties.MaxRows =3D Exc= elTemplate.ALL_ROWS; bindingProperties.Transpose =3D t= rue; xlt.BindData(weatherData, colName= s, "Weather", bindingProperties); //Process the template to populat= e it with the Data Source data xlt.Process(); //Save the report xlt.Save(@"..\..\ExcelOutput= Files\XmlWeatherReport_output.xlsx"); } ///<summary> Load the XML weather r= eport data into a 2-D ///Object array. ///</summary> /// <returns> Parsed XML data to be = used with ExcelTemplate /// </returns> private object[][] ParseXml() { //Create an array with an element= for each day of weather // reported in the XML document // There will be four elements in= the first dimension // to hold "Date", &quo= t;Temp", "Humidity", and "Wind" data // and one element in the second = dimension for every day // reported in the XML document XmlDocument doc =3D new XmlDocume= nt(); doc.Load(@"..\..\ExcelData\X= MLWeatherData.xml"); int NodeCount =3D doc.DocumentEle= ment.ChildNodes.Count; string[][] WeatherData =3D new st= ring[4][]; for (int i =3D 0; i < WeatherD= ata.Length; i++) WeatherData[i] =3D = new string[NodeCount]; //Loop through the days of weathe= r for (int i =3D 0; i < NodeCoun= t; i++) { XmlNode DayNode =3D= doc.DocumentElement.ChildNodes[i]; //Read the weather = values from the XML document into the array if (DayNode.Name = =3D=3D "today") Weath= erData[0][i] =3D DateTime.Now.ToString("d"); else Weath= erData[0][i] =3D DateTime.Now.AddDays(i).ToString("d"); WeatherData[1][i] =3D DayNode.SelectSingleNode("tempar= ature").InnerText; WeatherData[2][i] = =3D (Convert.ToDouble(DayNode.SelectSingleNode("humidity").InnerT= ext) / 100).ToString(); WeatherData[3][i] = =3D DayNode.SelectSingleNode("wind").InnerText; &nbs= p; } return WeatherData; } }=20