`
JavaSam
  • 浏览: 951789 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

javascript导出excel(可以导出表格线)

 
阅读更多

<html>
    <head>
        <script language="javascript" type="text/javascript">
        </script>
        <script language="javascript" type="text/javascript">
            function MakeExcel(){
            var i,j;
                try {
                  var xls    = new ActiveXObject ( "Excel.Application" );
                 }
                catch(e) {
                     alert( "要打印该表,您必须安装Excel电子表格软件,同时浏览器须使用“ActiveX 控件”,您的浏览器须允许执行控件。 请点击【帮助】了解浏览器设置方法!");
                          return "";
                 }
           
                        xls.visible =true;  //设置excel为可见
           
                var xlBook = xls.Workbooks.Add;
                var xlsheet = xlBook.Worksheets(1);
                <!--合并-->
                  xlsheet.Range(xlsheet.Cells(1,1),xlsheet.Cells(1,7)).mergecells=true;
                  xlsheet.Range(xlsheet.Cells(1,1),xlsheet.Cells(1,7)).value="发卡记录";
                 //  xlsheet.Range(xlsheet.Cells(1,1),xlsheet.Cells(1,6)).Interior.ColorIndex=5;//设置底色为蓝色
                            //   xlsheet.Range(xlsheet.Cells(1,1),xlsheet.Cells(1,6)).Font.ColorIndex=4;//设置字体色        
               // xlsheet.Rows(1). Interior .ColorIndex = 5 ;//设置底色为蓝色  设置背景色 Rows(1).Font.ColorIndex=4 
           
                <!--设置行高-->
                xlsheet.Rows(1).RowHeight = 25;
                <!--设置字体 ws.Range(ws.Cells(i0+1,j0), ws.Cells(i0+1,j1)).Font.Size = 13 -->
                xlsheet.Rows(1).Font.Size=14;
                <!--设置字体 设置选定区的字体  xlsheet.Range(xlsheet.Cells(i0,j0), ws.Cells(i0,j0)).Font.Name = "黑体" -->
                xlsheet.Rows(1).Font.Name="黑体";
                <!--设置列宽 xlsheet.Columns(2)=14;-->
           
                xlsheet.Columns("A:D").ColumnWidth =18;
                 <!--设置显示字符而不是数字-->
                xlsheet.Columns(2).NumberFormatLocal="@";
                xlsheet.Columns(7).NumberFormatLocal="@";
           
           
                 //设置单元格内容自动换行 range.WrapText  =  true  ;
                 //设置单元格内容水平对齐方式 range.HorizontalAlignment  =  Excel.XlHAlign.xlHAlignCenter;//设置单元格内容竖直堆砌方式
                  //range.VerticalAlignment=Excel.XlVAlign.xlVAlignCenter
                //range.WrapText  =  true;  xlsheet.Rows(3).WrapText=true  自动换行
              
                //设置标题栏
           
                 xlsheet.Cells(2,1).Value="卡号";
                 xlsheet.Cells(2,2).Value="密码";
                 xlsheet.Cells(2,3).Value="计费方式";
                 xlsheet.Cells(2,4).Value="有效天数";
                 xlsheet.Cells(2,5).Value="金额";
                 xlsheet.Cells(2,6).Value="所属服务项目";
                   xlsheet.Cells(2,7).Value="发卡时间";
           
                 var oTable=document.all['fors:data'];
                 var rowNum=oTable.rows.length;
                 for(i=2;i<=rowNum;i++){
                 for (j=1;j<=7;j++){
            //html table类容写到excel
           
                   xlsheet.Cells(i+1,j).Value=oTable.rows(i-1).cells(j-1).innerHTML;
                        }
           
           
                }
                <!--   xlsheet.Range(xls.Cells(i+4,2),xls.Cells(rowNum,4)).Merge; -->
                // xlsheet.Range(xlsheet.Cells(i, 4), xlsheet.Cells(i-1, 6)).BorderAround , 4
                 // for(mn=1,mn<=6;mn++) .     xlsheet.Range(xlsheet.Cells(1, mn), xlsheet.Cells(i1, j)).Columns.AutoFit;
                  xlsheet.Columns.AutoFit;
                             xlsheet.Range( xlsheet.Cells(1,1),xlsheet.Cells(rowNum+1,7)).HorizontalAlignment =-4108;//居中
                               xlsheet.Range( xlsheet.Cells(1,1),xlsheet.Cells(1,7)).VerticalAlignment =-4108;
                             xlsheet.Range( xlsheet.Cells(2,1),xlsheet.Cells(rowNum+1,7)).Font.Size=10;
           
                  xlsheet.Range( xlsheet.Cells(2,1),xlsheet.Cells(rowNum+1,7)).Borders(3).Weight = 2; //设置左边距
                   xlsheet.Range( xlsheet.Cells(2,1),xlsheet.Cells(rowNum+1,7)).Borders(4).Weight = 2;//设置右边距
                         xlsheet.Range( xlsheet.Cells(2,1),xlsheet.Cells(rowNum+1,7)).Borders(1).Weight = 2;//设置顶边距
                   xlsheet.Range( xlsheet.Cells(2,1),xlsheet.Cells(rowNum+1,7)).Borders(2).Weight = 2;//设置底边距
           
            
           
                  
                    xls.UserControl = true;  //很重要,不能省略,不然会出问题 意思是excel交由用户控制
                   xls=null;
                   xlBook=null;
                   xlsheet=null;
           
            }
           
            
           
           
        </script>
        <link href="css/styles3.css" rel="stylesheet" type="text/css"/>
        <title>ziyuanweihu</title>
    </head>
    <body>
        <form id="fors" method="post" action="/WebModule/admins/card/showcard.faces" enctype="application/x-www-form-urlencoded">
            <table border="0" cellpadding="0" cellspacing="0" width="100%">
                <tbody>
                    <tr>
                        <td class="middleLeft">
                        </td>
                        <td class="btstyle">
                            <table id="fors:sort" border="0" cellpadding="0" cellspacing="0" style="valign:center" width="100%">
                                <tbody>
                                    <tr>
                                        <td class="btstyle">
                                            <input type="button" name="fors:_id7" value="&#29983;&#25104;excel&#25991;&#20214;" onclick="MakeExcel()"/><input type="submit" name="fors:_id8" value="&#36820;&#22238;" />
                                        </td>
                                    </tr>
                                </tbody>
                            </table>
                            <table id="fors:data" border="1" cellpadding="0" cellspacing="1" width="100%">
                                <thead>
                                    <tr>
                                        <th scope="col">
                                            <span id="fors:data:headerText1">&#21345;&#21495;</span>
                                        </th>
                                        <th scope="col">
                                            <span id="fors:data:headerText2">&#23494;&#30721;</span>
                                        </th>
                                        <th scope="col">
                                            <span id="fors:data:headerText3">&#35745;&#36153;&#26041;&#24335;</span>
                                        </th>
                                        <th scope="col">
                                            <span id="fors:data:headerText4">&#26377;&#25928;&#22825;&#25968;</span>
                                        </th>
                                        <th scope="col">
                                            &#37329;&#39069;
                                        </th>
                                        <th scope="col">
                                            <span id="fors:data:headerText6">&#25152;&#23646;&#26381;&#21153;&#39033;&#30446;</span>
                                        </th>
                                        <th scope="col">
                                            <span id="fors:data:headerText7">&#21457;&#21345;&#26102;&#38388;</span>
                                        </th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <tr>
                                        <td>
                                            h000010010
                                        </td>
                                        <td>
                                            543860
                                        </td>
                                        <td>
                                            &#35745;&#28857;
                                        </td>
                                        <td>
                                        </td>
                                        <td>
                                            2.0
                                        </td>
                                        <td>
                                            &#27979;&#35797;&#39033;&#30446;
                                        </td>
                                        <td>
                                            2006-06-23 10:14:40.843
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>
                                            h000010011
                                        </td>
                                        <td>
                                            683352
                                        </td>
                                        <td>
                                            &#35745;&#28857;
                                        </td>
                                        <td>
                                        </td>
                                        <td>
                                            2.0
                                        </td>
                                        <td>
                                            &#27979;&#35797;&#39033;&#30446;
                                        </td>
                                        <td>
                                            2006-06-23 10:14:40.843
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>
                                            h000010012
                                        </td>
                                        <td>
                                            433215
                                        </td>
                                        <td>
                                            &#35745;&#28857;
                                        </td>
                                        <td>
                                        </td>
                                        <td>
                                            2.0
                                        </td>
                                        <td>
                                            &#27979;&#35797;&#39033;&#30446;
                                        </td>
                                        <td>
                                            2006-06-23 10:14:40.843
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>
                                            h000010013
                                        </td>
                                        <td>
                                            393899
                                        </td>
                                        <td>
                                            &#35745;&#28857;
                                        </td>
                                        <td>
                                        </td>
                                        <td>
                                            2.0
                                        </td>
                                        <td>
                                            &#27979;&#35797;&#39033;&#30446;
                                        </td>
                                        <td>
                                            2006-06-23 10:14:40.843
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>
                                            h000010014
                                        </td>
                                        <td>
                                            031736
                                        </td>
                                        <td>
                                            &#35745;&#28857;
                                        </td>
                                        <td>
                                        </td>
                                        <td>
                                            2.0
                                        </td>
                                        <td>
                                            &#27979;&#35797;&#39033;&#30446;
                                        </td>
                                        <td>
                                            2006-06-23 10:14:40.843
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>
                                            h000010015
                                        </td>
                                        <td>
                                            188600
                                        </td>
                                        <td>
                                            &#35745;&#28857;
                                        </td>
                                        <td>
                                        </td>
                                        <td>
                                            2.0
                                        </td>
                                        <td>
                                            &#27979;&#35797;&#39033;&#30446;
                                        </td>
                                        <td>
                                            2006-06-23 10:14:40.843
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>
                                            h000010016
                                        </td>
                                        <td>
                                            363407
                                        </td>
                                        <td>
                                            &#35745;&#28857;
                                        </td>
                                        <td>
                                        </td>
                                        <td>
                                            2.0
                                        </td>
                                        <td>
                                            &#27979;&#35797;&#39033;&#30446;
                                        </td>
                                        <td>
                                            2006-06-23 10:14:40.843
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>
                                            h000010017
                                        </td>
                                        <td>
                                            175315
                                        </td>
                                        <td>
                                            &#35745;&#28857;
                                        </td>
                                        <td>
                                        </td>
                                        <td>
                                            2.0
                                        </td>
                                        <td>
                                            &#27979;&#35797;&#39033;&#30446;
                                        </td>
                                        <td>
                                            2006-06-23 10:14:40.843
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>
                                            h000010018
                                        </td>
                                        <td>
                                            354437
                                        </td>
                                        <td>
                                            &#35745;&#28857;
                                        </td>
                                        <td>
                                        </td>
                                        <td>
                                            2.0
                                        </td>
                                        <td>
                                            &#27979;&#35797;&#39033;&#30446;
                                        </td>
                                        <td>
                                            2006-06-23 10:14:40.843
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>
                                            h000010019
                                        </td>
                                        <td>
                                            234750
                                        </td>
                                        <td>
                                            &#35745;&#28857;
                                        </td>
                                        <td>
                                        </td>
                                        <td>
                                            2.0
                                        </td>
                                        <td>
                                            &#27979;&#35797;&#39033;&#30446;
                                        </td>
                                        <td>
                                            2006-06-23 10:14:40.843
                                        </td>
                                    </tr>
                                </tbody>
                            </table>
                        </td>
                        <td class="middleRight">
                        </td>
                    </tr>
                </tbody>
            </table>
   <input type="hidden" name="fors" value="fors" />
        </form>
    </body>
</html>

分享到:
评论

相关推荐

    layui数据表格导出Excel插件

    layui数据表格导出Excel插件是一款为layui框架设计的实用工具,它允许用户方便地将layui数据表格中的数据导出到Excel文件中。layui是一款轻量级的前端UI框架,以其简洁、优雅的代码风格和丰富的组件库深受开发者喜爱...

    纯JavaScript导出Excel

    "纯JavaScript导出Excel"的功能正是解决这个问题的一种方法,它允许开发者在不依赖任何后端服务或第三方库的情况下,直接在浏览器端将JSON格式的数据转换为可下载的Excel文件。这种技术对于那些对服务器交互有限制...

    JavaScript 实现 Excel数据导出 支持多个Sheet页导出

    在实际应用中,可以封装一个函数,接受JSON数据和Sheet页配置作为参数,然后执行上述步骤,以实现一个通用的Excel导出功能。这不仅可以提高代码复用性,还能方便地根据业务需求进行扩展。 总之,纯JavaScript实现...

    js 实现 用JavaScript导出图像到Excel

    js 实现 用JavaScript导出图像到Excel! 值得下载看看!资源免费,大家分享!!

    h5 列表导出为excel

    在IT领域,尤其是在Web开发中,常常需要将HTML5(H5)页面中的表格数据导出为Excel格式,以便用户可以方便地存储、编辑或分享数据。"h5 列表导出为excel"这个话题涉及到的技术点主要包括HTML5、JavaScript、CSS以及...

    ext实现导出excel的功能。

    在EXTJS这个强大的JavaScript框架中,实现导出Excel功能是一项常见的需求。EXTJS提供了一种高效的方法来将数据导出到Excel格式,使得用户能够方便地处理和分析数据。在这个场景下,我们可以从以下几个关键知识点入手...

    Ligerui Table导出excel 支持样式、冻结行列、图片等导出

    LigerUI Table不仅具备基本的表格功能,如排序、筛选、分页,还提供了丰富的扩展特性,如导出Excel功能。这个功能使得用户能够方便地将网页上的数据导出到Excel文件中,以便于进一步的数据分析或存储。 标题"...

    简单的导出excel表格列子

    总结来说,这个“简单的导出excel表格列子”提供了一种实用且高效的方法,通过纯JavaScript在Web页面上实现Excel导出功能,无需依赖任何插件,代码简洁易懂,对开发者来说具有很高的学习价值。通过阅读和实践压缩包...

    html页面表格导出excel(原生js浏览器全兼容)

    在网页开发中,有时我们...提供的`js浏览器导出Excel`资源应该包含了一个示例,你可以参考这个示例代码来理解并应用到自己的项目中。这种方法简单易用,适用于各种网页表格导出需求,极大地提高了前端开发的灵活性。

    使用js导出带样式的excel表格

    总的来说,使用JavaScript导出带样式的Excel表格涉及了对数据的组织、样式定义以及文件生成等多个环节。通过SheetJS库,我们可以轻松地实现这一功能,提供给用户高质量的导出体验。在实际项目中,还可以根据需求进行...

    jquery 导出excel方法

    总结,jQuery导出Excel的方法多样,可以选择适合项目需求的技术栈。TableExport插件是一个便捷的选择,而对于更复杂的需求,可以结合其他JavaScript库和服务器端技术来实现。在实际应用中,还需要关注兼容性、性能和...

    js导出Excel 、Word [超实用][自动保存样式]

    总结一下,JavaScript导出Excel和Word的关键步骤包括: 1. 获取Table数据和样式信息。 2. 将数据转化为适合Excel或Word的格式。 3. 使用库(如SheetJS、docx)生成相应格式的文件。 4. 创建下载链接或通过服务器完成...

    easyui datagrid 数据导出到Excel

    文件`Jquery_easyui_datagrid_js导出excel.doc`可能是文档说明或者包含插件使用的示例代码。通常,jQuery插件能简化Datagrid数据导出的操作。一种常见的方式是使用`html2canvas`和`jsPDF`库,它们可以将HTML内容转换...

    简单实用网页表格数据导出Excel电子表格文件jQuery插件

    本项目"简单实用网页表格数据导出Excel电子表格文件jQuery插件"正是为了解决这一问题。 首先,我们来探讨jQuery的核心概念。jQuery简化了JavaScript的DOM操作,提供了统一的API来选择元素、添加事件处理程序、执行...

    Ext Grid 导出Excel

    总结来说,"Ext Grid 导出Excel"这个话题涵盖了从JavaScript数据结构到Excel文件格式转换的过程,涉及到的主要技术有Ext JS的Grid和Store组件,以及第三方库SheetJS。这个过程对于那些需要提供数据导出功能的Web应用...

    tableExport_html表格导出excel等多种格式

    在IT行业中,数据的导入和导出是...总的来说,"tableExport_html表格导出excel等多种格式"是一个实用的前端工具,通过简单的集成,它可以极大地提升网页表格数据的交互性和实用性,使得数据的导出变得更加便捷和高效。

    js导出excel(xlsx格式)、CVS、PDF、打印

    Javascript导出excel为xlsx格式,兼容IE6+和主流浏览器,下载下来直接可以使用。 其他javascript导出excel插件可看作者文章:https://blog.csdn.net/qq_21693027/article/details/80459677

    vue导出excel表格Blob,Export2Excel

    在实际开发中,你可能还需要处理数据的格式化、错误处理、用户交互等细节问题,但以上内容已经涵盖了Vue.js中使用`Blob`和`Export2Excel`导出Excel表格的基础知识。通过这些技术,你可以为用户提供方便的数据导出...

    lodop导出ExcelDemo

    【lodop导出ExcelDemo】是一个基于LODOP技术实现的JavaScript示例,它展示了如何通过LODOP组件将网页中的数据导出为Excel文件。这个功能在许多Web应用程序中非常实用,允许用户方便地保存和处理数据。下面将详细阐述...

Global site tag (gtag.js) - Google Analytics