Excel 2007 Open XML文件结构(2)
在以上文件中,根据<sheet>元素中r:id属性的值可得到工作表数据的XML文件。例如,在workbook.xml文件中名为工作表1的工作表的r:id属性为rld1,在以上文件中根据ID找到以下代码:
<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationsh- ips/worksheet" Target="worksheets/sheet1.xml" />
<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationsh- ips/worksheet" Target="worksheets/sheet1.xml" />由此可知工作表数据保存在worksheets文件夹下,文件名为sheet1.xml。
(6)打开"xl\worksheets\sheet1.xml"文件,其内容如下(为节省篇幅,以下代码中省略了重复的4~6行的数据):
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?> - <worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/ main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"><dimension ref="A1:B6" /> '工作表数据范围- <sheetViews>- <sheetView tabSelected="1" workbookViewId="0"><selection activeCell="D12" sqref="D12" /> </sheetView></sheetViews><sheetFormatPr defaultRowHeight="13.5" /> - <cols><col min="1" max="1" width="13" bestFit="1" customWidth="1" /> </cols>- <sheetData> '工作表数据- <row r="1" spans="1:2"> '第1行数据<c r="A1" s="5" /> <c r="B1" s="5" /> </row>- <row r="2" spans="1:2" ht="14.25"> '第2行数据- <c r="A2" s="1" t="s"> '单元格A2的值,字符型<v>0</v> '字符串的位置索引</c>- <c r="B2" s="1" t="s"> '单元格B2的值,字符型<v>1</v> </c></row>- <row r="3" spans="1:2"> ' 第3行数据- <c r="A3" s="2" t="s"><v>2</v> </c>- <c r="B3" s="3"> '单元格B3的值<v>3500</v> '值为35000</c></row>(此处省略工作表第4~6行的数据)</sheetData>- <mergeCells count="1"><mergeCell ref="A1:B1" /> '合并单元格</mergeCells><phoneticPr fontId="1" type="noConversion" /> <pageMargins left="0.7" right="0.7" top="0.75" bottom="0.75" header="0.3" footer="0.3" /> </worksheet>
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?> - <worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/ main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"><dimension ref="A1:B6" /> '工作表数据范围- <sheetViews>- <sheetView tabSelected="1" workbookViewId="0"><selection activeCell="D12" sqref="D12" /> </sheetView></sheetViews><sheetFormatPr defaultRowHeight="13.5" /> - <cols><col min="1" max="1" width="13" bestFit="1" customWidth="1" /> </cols>- <sheetData> '工作表数据- <row r="1" spans="1:2"> '第1行数据<c r="A1" s="5" /> <c r="B1" s="5" /> </row>- <row r="2" spans="1:2" ht="14.25"> '第2行数据- <c r="A2" s="1" t="s"> '单元格A2的值,字符型<v>0</v> '字符串的位置索引</c>- <c r="B2" s="1" t="s"> '单元格B2的值,字符型<v>1</v> </c></row>- <row r="3" spans="1:2"> ' 第3行数据- <c r="A3" s="2" t="s"><v>2</v> </c>- <c r="B3" s="3"> '单元格B3的值<v>3500</v> '值为35000</c></row>(此处省略工作表第4~6行的数据)</sheetData>- <mergeCells count="1"><mergeCell ref="A1:B1" /> '合并单元格</mergeCells><phoneticPr fontId="1" type="noConversion" /> <pageMargins left="0.7" right="0.7" top="0.75" bottom="0.75" header="0.3" footer="0.3" /> </worksheet>以上XML代码中,元素<c>表示该行中的一个单元格,对于单元格中的值,如果<c>元素有"t"属性的话,<c>元素的子元素<v>的值就是各工作表共享的字符串的索引。否则,<v>元素的值就是该单元格的值。
(7)在工作簿中,各工作表使用的字符串统一存放在"xl/sharedStrings.xml"文件中,该文件的内容如下:
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?> - <sst xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" count="6" uniqueCount="5">- <si><t>商品名称</t> <phoneticPr fontId="2" type="noConversion" /> </si>- <si><t>单价</t> <phoneticPr fontId="2" type="noConversion" /> </si>- <si><t>三星手机</t> <phoneticPr fontId="2" type="noConversion" /> </si>- <si><t>诺基亚手机</t> <phoneticPr fontId="2" type="noConversion" /> </si>- <si><t>摩托罗拉手机</t> <phoneticPr fontId="2" type="noConversion" /> </si></sst>
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?> - <sst xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" count="6" uniqueCount="5">- <si><t>商品名称</t> <phoneticPr fontId="2" type="noConversion" /> </si>- <si><t>单价</t> <phoneticPr fontId="2" type="noConversion" /> </si>- <si><t>三星手机</t> <phoneticPr fontId="2" type="noConversion" /> </si>- <si><t>诺基亚手机</t> <phoneticPr fontId="2" type="noConversion" /> </si>- <si><t>摩托罗拉手机</t> <phoneticPr fontId="2" type="noConversion" /> </si></sst>每组字符串使用元素<si>表示,其排列顺序就是其序号,表示工作表数据的XML文件用该序号来引用字符串。
转载于:https://www.cnblogs.com/blue-skies/archive/2010/07/09/1774546.html