Excel 2007 Open XML文件结构(2)
Excel 2007 Open XML文件結構(2)
在以上文件中,根據<sheet>元素中r:id屬性的值可得到工作表數據的XML文件。例如,在workbook.xml文件中名為工作表1的工作表的r:id屬性為rld1,在以上文件中根據ID找到以下代碼:
<Relationship Id="rId1"
Type="http://schemas.openxmlformats.org/o
fficeDocument/2006/relationsh- ips/worksheet"
Target="worksheets/sheet1.xml" />
| ? <Relationship Id="rId1" Type="http://schemas.openxmlformats.org/o fficeDocument/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
總結
以上是生活随笔為你收集整理的Excel 2007 Open XML文件结构(2)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 设计模式学习笔记-代理模式
- 下一篇: .NET学习杂记