其实我们完全可以按照上次的说明,生成一个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"
< 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" >
< 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 >
Content-Location: file:///C:/0E8D990C/MimeExcel.xml
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset="us-ascii"
< 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" >
< 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"
< 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" >
< 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 >
Content-ID: sheet001
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset="us-ascii"
< 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" >
< 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。显示效果如下图: