How to read excel xml spreadsheet data in Classic ASP -
i thought straightforward xml load , loop, reason can't read out of excel xml spreadsheet.
the content of excel spreadsheet, appears standardised output, follows:
<?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" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:user="urn:my-scripts"> <documentproperties xmlns="urn:schemas-microsoft-com:office:office">... </documentproperties> <officedocumentsettings xmlns="urn:schemas-microsoft-com:office:office">... </officedocumentsettings> <excelworkbook xmlns="urn:schemas-microsoft-com:office:excel">... </excelworkbook> <styles>...</styles> <worksheet ss:name="sheet1" ss:protected="1"> <names> <namedrange ss:name="print_titles" ss:refersto="=sheet1!c2,sheet1!r7"/> </names> <table ss:expandedcolumncount="34" ss:expandedrowcount="32" x:fullcolumns="1" x:fullrows="1" ss:defaultrowheight="13.2"> <column ss:hidden="1" ss:width="175.2"/> <column ss:width="250.20000000000002"/> <column ss:width="60" ss:span="31"/> <row ss:autofitheight="0" ss:height="150" ss:styleid="s67">...</row> <row ss:height="15"> <cell ss:styleid="s69"> <data ss:type="string">w89231</data> </cell> <cell ss:styleid="s70"> <data ss:type="string">tom brown</data> <namedcell ss:name="print_titles"/> </cell> <cell ss:styleid="s69"> <data ss:type="string">1e+</data> </cell> <cell ss:styleid="s69"> <data ss:type="string">1m</data> </cell>
etc etc
having read bytagname isn't best method tried following singlenode code first:
strfilename = "1b.xml" set oxmldoc = server.createobject("msxml2.domdocument.6.0") oxmldoc.async = false oxmldoc.load (server.mappath(strfilename)) set nodelist = oxmldoc.documentelement.selectnodes("workbook/worksheet") each node in nodelist response.write node.selectsinglenode("row/cell/data/text()") next
but absolutely nothing happens.
so went tried , trusted bytagname , tried following:
strfilename = "1b.xml" set oxmldoc = server.createobject("msxml2.domdocument.6.0") oxmldoc.async = false oxmldoc.load (server.mappath(strfilename)) set orows = oxmldoc.documentelement.getelementsbytagname("row") response.write orows.length
the orows.length feedback zero
i can't seem dom though standard excel xml spreadsheet format.
i'd appreciate if please explain how can read through rows , extract necessary data values.
regards
tom
managed find out it's namespaces.
by adding below lines:
set oxmldoc = server.createobject("msxml2.domdocument.6.0") oxmldoc.setproperty "selectionlanguage", "xpath" oxmldoc.setproperty "selectionnamespaces", "xmlns:myns='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' xmlns:msxsl='urn:schemas-microsoft-com:xslt' xmlns:user='urn:my-scripts'"
i reference tags within xml follows:
set oxmlrows = oxmldoc.selectnodes("/myns:workbook/myns:worksheet/myns:table/myns:row")
and xml parsing begin!! :0)
regards
tom
Comments
Post a Comment