Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Serve Office Documents Using MIME Types and J#.NET : Page 3

The conversion of the native office document format to XML allows developers to create documents on the fly and serve them from a Web service.


advertisement
Opening the default.xml file from the download using Internet Explorer, you will see a document much like that in Figure 2.

  /assets/articlefigs/3557.gif
Figure 2: The XML Breakdown of an Excel workbook.

This XML file is broken down into several sections. The 'Workbook' node contains the following nodes:

  • DocumentProperties
  • OfficeDocumentSettings
  • ExcelWorkbook
  • Styles
  • Worksheet
Expand the 'Worksheet' node to see the following nodes:
  • Table
  • WorksheetOptions
Expand the 'Table' node to see the following nodes:
  • Column
  • Row
If you are familiar with Excel, you'll be in familiar territory. Columns and rows are the heart of the data storage structures within Excel.



Expanding the first 'Row' node presents a series of cells, containing the headings for the columns of data.

As expected, expanding the second Row shows the 'Revenue' line from the mockup. The first cell contains the label, the second contains the formula for calculating the average % change, the third is empty, and so on.

Rebuilding the Excel Workbook from Our Data Source
Take a look at the Web service code to find out how to manipulate the XML with the raw data. In Listing 1, you see how to loop through the three rows of data and then loop through columns 2, 4, 6, and 8 to place the data into the appropriate cells. Previously, the values for Revenue, Costs, and Taxes had been loaded into string arrays containing the appropriate values. Their values are placed into the cells by using the set_InnerText() method on an XML node in J#.

This code works on a node in the XML document, pulled out of the main document using an XPath to determine its location.

The XPath is simply the address of the nodes in the workbook containing the worksheet data as indicated below:

//ss:Workbook/ss:Worksheet[@ss:Name='Sheet1']/ss:Table/ss:Row"



Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date