Excel 文件导出功能核心部分

${response.setHeader("Content-Type", "application/vnd.ms-excel; charset=G2312")}
${response.setHeader("Content-Disposition","attachment; filename=sample_export.xls")}
${response.setHeader("Cache-Control", "cache")}

一、标准单卡片页结构导出方式:

<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <!-- Excel 专用设置,不可删除! START -->
        <!--[if gte mso 9]>
        <xml>
            <x:ExcelWorkbook>
                <x:ExcelWorksheets><x:ExcelWorksheet>
                <x:Name>SHET_NAME_1</x:Name>
                <x:WorksheetOptions>
                    <x:DefaultRowHeight>285</x:DefaultRowHeight>
                    <x:Print>
                        <x:ValidPrinterInfo/>
                        <x:PaperSizeIndex>9</x:PaperSizeIndex>
                        <x:HorizontalResolution>600</x:HorizontalResolution>
                        <x:VerticalResolution>600</x:VerticalResolution>
                    </x:Print>
                    <x:Selected/>
                    <x:TopRowVisible>48</x:TopRowVisible>
                    <x:ProtectContents>False</x:ProtectContents>
                    <x:ProtectObjects>False</x:ProtectObjects>
                    <x:ProtectScenarios>False</x:ProtectScenarios>
                </x:WorksheetOptions>
                </x:ExcelWorksheet></x:ExcelWorksheets>
            </x:ExcelWorkbook>
            <x:ExcelName>
                <x:Name>Print_Titles</x:Name>
                <x:SheetIndex>1</x:SheetIndex>
                <x:Formula>=SHET_NAME_1!$1:$3</x:Formula>
            </x:ExcelName>
        </xml>
        <![endif]-->
        <!-- Excel 专用设置,不可删除! END -->
    </head>
    <body>
        以 Table 标签来定义 Excel 文件内的复杂表格结构即可。
    </body>
</html>

二、多卡片页结构核心原理如下:(未验证,仅是理论推断!)

1、主体结构中的Excel配置信息:

        <xml>
            <x:ExcelWorkbook>
                <x:ExcelWorksheets>
                    <x:ExcelWorksheet>
                        <x:Name>SHET_NAME_1</x:Name>
                        <x:WorksheetSource HRef="DEMO.files/sheet001.htm"/>
                    </x:ExcelWorksheet>
                    <x:ExcelWorksheet>
                        <x:Name>SHET_NAME_2</x:Name>
                        <x:WorksheetSource HRef="DEMO.files/sheet001.htm"/>
                    </x:ExcelWorksheet>
                </x:ExcelWorksheets>
            </x:ExcelWorkbook>
            <x:ExcelName>
                <x:Name>Print_Titles</x:Name>
                <x:SheetIndex>1</x:SheetIndex>
                <x:Formula>=SHET_NAME_1!$1:$3</x:Formula>
            </x:ExcelName>
            <x:ExcelName>
                <x:Name>Print_Titles</x:Name>
                <x:SheetIndex>1</x:SheetIndex>
                <x:Formula>=SHET_NAME_2!$1:$3</x:Formula>
            </x:ExcelName>
        </xml>

2、主体结构中的各独立卡片页内容:

        <frameset rows="*,39" border=0 width=0 frameborder=no framespacing=0>
            <frame src="DEMO.files/sheet001.htm" name="frSheet">
            <frame src="DEMO.files/tabstrip.htm" name="frTabs" marginwidth=0 marginheight=0>
            <noframes>
                <body>
                    <p>此页面使用了框架,而您的浏览器不支持框架。</p>
                </body>
            </noframes>
        </frameset>

3、上述参数<x:WorksheetSource HRef="SUB-VIEW-FILE">内容结构:

注:基本原理与上述一单文件中的明细描述部分结构一致!

<!--[if gte mso 9]>
<xml>
    <x:WorksheetOptions>
        <x:DefaultRowHeight>285</x:DefaultRowHeight>
        <x:Print>
            <x:ValidPrinterInfo/>
            <x:PaperSizeIndex>9</x:PaperSizeIndex>
            <x:HorizontalResolution>600</x:HorizontalResolution>
            <x:VerticalResolution>600</x:VerticalResolution>
        </x:Print>
        <x:ProtectContents>False</x:ProtectContents>
        <x:ProtectObjects>False</x:ProtectObjects>
        <x:ProtectScenarios>False</x:ProtectScenarios>
    </x:WorksheetOptions>
</xml>
<![endif]-->

以 Table 标签来定义 Excel 文件内的复杂表格结构即可。

版权归 LvCreator 所有,仅供参考。

2014-08-07 调查后更新...

你可能感兴趣的:(Excel,导出)