IE嵌入excel文档(转)

IE嵌入excel文档

需要在IE中嵌入excel文档(xls), 可用于解决在IE中一次性显示大量表格数据(10万个单元格以上)造成的性能问题, 经测试可以有2种方式, 如有可能的话, 还可以借用第3方服务, 如Google Docs或Microsoft SkyDrive Microsoft Excel Web App

1. 通过iframe方式嵌入
    主要是利用IE可以直接调用关联程序打开对应格式的文档, 如调用pdf阅读器在IE中直接打开pdf.
    excel也是一样, 可以直接通过IE打开本地或远程的excel文件, 通过拖拽(或从IE菜单中选择文件-打开)excel文件到IE可以打开本地文件.
    但一般通过网络会采用iframe的方式来嵌入文件, 让IE自动通过关联软件打开文件
    例如:
<iframe width="100%" height="100%" src="http://218.75.61.130/media_file/2005_10_29/20051029213808.xls" />



    参考
    ------
    请问如何在网页中嵌入Excel
    2003版的默认是在iframe里面打开的, 除非客户更改了设置
    2007版的要修改注册表(BrowserFlag)

    Internet Explorer 中编辑 OLE 嵌入文档
    HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Excel.Sheet.8
    修改 BrowserFlags 为 0

2. 通过ActiveX控件(OWC)方式嵌入
    主要是利用微软的OWC组件(Microsoft Office Web Components)来打开excel
    客户端必须安装该组件才能使用, 可以打开的格式为xml(SpreadsheetML), html(表格), csv
    不支持直接打开xls, 因此必须转成符合他要求的上述格式





OWCEmbedExcel.html
--------------------------------
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8" />
        <script>
            /**
             * 通过OWC来打开SpreadsheetML格式的excel文档(IE浏览器必须的)
             * 该方式可用于解决在IE中一次性显示大量表格数据(10万个单元格以上)造成的性能问题
             *
             * 如果打开页面报错, 请先安装owc11.exe(OWC组件包)
             *
             * @see Microsoft Office Web 组件 Visual Basic 参考(owc vba手册)
             * @see Excel与OWC做报表总结
             */
            function readSpreadsheetML() {
                var spreadsheet = document.getElementById("spreadsheet");
                // XMLURL必须指向SpreadsheetML格式的XML文档
                // SpreadsheetML is the XML schema for Microsoft Office Excel 2003
                // 可以通过将excel文档另存为"XML 电子表格式 2003(*.xml)"的方式来获得这个xml文档
                // 还支持csv和html格式(包含表格)对应属性为CSVURL, HTMLURL
                spreadsheet.XMLURL = 'SpreadsheetML.xml';

                setExcelDisplayMode(spreadsheet);
                setProtectMode(spreadsheet);

                // 选择单元格冻结表格
                spreadsheet.Cells(2, 2).Select();
                spreadsheet.ActiveWindow.FreezePanes = true;
            }

            function setExcelDisplayMode(spreadsheet) {
                spreadsheet.DisplayToolbar = false;
                spreadsheet.DisplayOfficeLogo = false;
                spreadsheet.DisplayWorkbookTabs = false;
            }

            function setProtectMode(spreadsheet) {
                var protection = spreadsheet.ActiveSheet.Protection;
                protection.AllowFormattingRows = true;
                protection.AllowFormattingColumns = true;
                protection.AllowDeletingRows = false;
                protection.AllowInsertingRows = false;
                protection.AllowInsertingColumns = false;
                protection.AllowSorting = false;
                protection.Enabled = true;
                spreadsheet.ActiveWindow.EnableResize = false;
            }
        </script>
    </head>
    <body>
        <input type="button" value="Read SpreadsheetML"
            onclick="readSpreadsheetML()" />
        <!-- Microsoft Office Web Components(OWC) -->
        <object id="spreadsheet" style=" 100%; height: 550px;"
            classid="CLSID:0002E559-0000-0000-C000-000000000046" />
    </body>
</html>


SpreadsheetML.xml
----------------------------
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?mso-application progid="Excel.Sheet"?>
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
        xmlns:html="http://www.w3.org/TR/REC-html40"
        xmlns:o="urn:schemas-microsoft-com:office:office"
        xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
        xmlns:x="urn:schemas-microsoft-com:office:excel">
    <ss:Worksheet ss:Name="Sheet1">
        <ss:Table>
            <ss:Row>
                <ss:Cell><Data ss:Type="String">Hello Excel!</Data></ss:Cell>
            </ss:Row>
        </ss:Table>
    </ss:Worksheet>
</Workbook>

原文地址:https://www.cnblogs.com/sungcong/p/2916611.html