用MIME格式描述多工作表Excel文件
上次说了使用MIME格式描述多内容的Excel文件,那么如果我希望描述一个有多工作表(sheet)的Excel文件,是否也同样能办到呢?因为很多时候我们需要把一系列的多个表格导入一个Excel文件中保存,对多工作表的支持是非常重要的功能,否则单Sheet的Excel文件如同鸡肋的说。
其实我们完全可以按照上次的说明,生成一个MIME格式描述的Excel文件先,然后加入对多sheet的描述就可以了。对多sheet支持的MIME描述是文件中一个单独的节,如下是一个描述了4个sheets的节:
------BOUNDARY_9527----
Content-Location: file:///C:/0E8D990C/MimeExcel.xml
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset="us-ascii"
![](/Images/OutliningIndicators/None.gif)
<html xmlns:o=3D"urn:schemas-microsoft-com:office:office"
xmlns:x=3D"urn:schemas-microsoft-com:office:excel"
xmlns=3D"http://www.w3.org/TR/REC-html40">
![](/Images/OutliningIndicators/None.gif)
<head>
<xml>
<x:ExcelWorkbook>
<x:ExcelWorksheets>
<x:ExcelWorksheet>
<x:Name>cnblogs</x:Name>
<x:WorksheetSource HRef=3D"cid:sheet001"/>
</x:ExcelWorksheet>
<x:ExcelWorksheet>
<x:Name>birdshome</x:Name>
<x:WorksheetSource HRef=3D"cid:sheet002"/>
</x:ExcelWorksheet>
<x:ExcelWorksheet>
<x:Name>mime</x:Name>
<x:WorksheetSource HRef=3D"MimeExcel/sheet003.xml"/>
</x:ExcelWorksheet>
<x:ExcelWorksheet>
<x:Name>excel</x:Name>
<x:WorksheetSource HRef=3D"MimeExcel/sheet004.xml"/>
</x:ExcelWorksheet>
</x:ExcelWorksheets>
</x:ExcelWorkbook>
</xml>
</head>
</html>
其实最关键的就是<x:WorksheetSource HRef=3D"cid:sheet002"/>节点,它的属性HRef表示一个Sheet的ID,这个ID和上次说的图片引用一样,可以使Content-Location描述,也可是Content-ID来描述,只要引用的时候注意配对就行了。
各个Sheet的描述就和"多内容"一文中说的格式一样。比如sheet001:
------BOUNDARY_9527----
Content-ID: sheet001
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset="us-ascii"
![](/Images/OutliningIndicators/None.gif)
<html xmlns:o=3D"urn:schemas-microsoft-com:office:office"
xmlns:x=3D"urn:schemas-microsoft-com:office:excel"
xmlns=3D"http://www.w3.org/TR/REC-html40">
![](/Images/OutliningIndicators/None.gif)
<head>
<xml>
<x:WorksheetOptions>
<x:ProtectContents>False</x:ProtectContents>
<x:ProtectObjects>False</x:ProtectObjects>
<x:ProtectScenarios>False</x:ProtectScenarios>
</x:WorksheetOptions>
</xml>
</head>
<body>
<table>
<tr>
<td>cnblogs</td>
<td>cnblogs</td>
<td>cnblogs</td>
<td>cnblogs</td>
</tr>
</table>
</body>
</html>
本文MIME Execl文件示例下载:mime_excel.rar。显示效果如下图:
![MIME.SHEETS.XLS.png](/images/cnblogs_com/birdshome/NormalArticle/2005/MIME.SHEETS.XLS.png)
其实我们完全可以按照上次的说明,生成一个MIME格式描述的Excel文件先,然后加入对多sheet的描述就可以了。对多sheet支持的MIME描述是文件中一个单独的节,如下是一个描述了4个sheets的节:
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
其实最关键的就是<x:WorksheetSource HRef=3D"cid:sheet002"/>节点,它的属性HRef表示一个Sheet的ID,这个ID和上次说的图片引用一样,可以使Content-Location描述,也可是Content-ID来描述,只要引用的时候注意配对就行了。
各个Sheet的描述就和"多内容"一文中说的格式一样。比如sheet001:
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
本文MIME Execl文件示例下载:mime_excel.rar。显示效果如下图:
![MIME.SHEETS.XLS.png](/images/cnblogs_com/birdshome/NormalArticle/2005/MIME.SHEETS.XLS.png)
posted on 2005-07-14 00:09 birdshome 阅读(6007) 评论(5) 编辑 收藏 举报