javascript操作excel生成报表示例_.docx

上传人:啊飒飒 文档编号:11660224 上传时间:2021-08-28 格式:DOCX 页数:14 大小:14.19KB
返回 下载 相关 举报
javascript操作excel生成报表示例_.docx_第1页
第1页 / 共14页
javascript操作excel生成报表示例_.docx_第2页
第2页 / 共14页
javascript操作excel生成报表示例_.docx_第3页
第3页 / 共14页
javascript操作excel生成报表示例_.docx_第4页
第4页 / 共14页
javascript操作excel生成报表示例_.docx_第5页
第5页 / 共14页
亲,该文档总共14页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述

《javascript操作excel生成报表示例_.docx》由会员分享,可在线阅读,更多相关《javascript操作excel生成报表示例_.docx(14页珍藏版)》请在三一文库上搜索。

1、javascript操作excel生成报表示例_ 代码如下: html head 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; /设置e

2、xcel为可见 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;/设置底色为蓝色

3、/ 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

4、=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

5、.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(

6、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.allfors: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.r

7、ows(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.

8、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).Bord

9、ers(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.Use

10、rControl = true; /很重要,不能省略,不然会出问题 意思是excel交由用户掌握 xls=null; xlBook=null; xlsheet=null; /script link href=css/styles3.css rel=stylesheet type=text/css/ titleziyuanweihu/title /head body form id=fors method=post action=/WebModule/admins/card/showcard.faces enctype=application/x-form-urlencoded table id

11、=fors:top border=0 cellpadding=0 cellspacing=0 width=100% tbody tr td class=leftimg src=images/jiao1.gif alt= /td td class=topMiddle/td td class=rightimg src=images/jiao2.gif alt= /td /tr /tbody /table table border=0 cellpadding=0 cellspacing=0 width=100% tbody tr td class=middleLeft/td td class=bts

12、tyletable id=fors:sort border=0 cellpadding=0 cellspacing=0 style=valign:center width=100% tbody tr td class=btstyleinput type=button name=fors:_id7 value=生成excel文件 onclick=MakeExcel() /input type=submit name=fors:_id8 value=返回 /td /tr /tbody /table table id=fors:data border=1 cellpadding=0 cellspac

13、ing=1 width=100% thead tr th scope=colspan id=fors:data:headerText1卡号/span/th th scope=colspan id=fors:data:headerText2密码/span/th th scope=colspan id=fors:data:headerText3计费方式/span/th th scope=colspan id=fors:data:headerText4有效天数/span/th th scope=col金额/th th scope=colspan id=fors:data:headerText6所属服

14、务项目/span/th th scope=colspan id=fors:data:headerText7发卡时间/span/th /tr /thead tbody tr tdh000010010/td td543860/td td计点/td td/td td2.0/td td测试项目/td td2021-06-23 10:14:40.843/td /tr tr tdh000010011/td td683352/td td计点/td td/td td2.0/td td测试项目/td td2021-06-23 10:14:40.843/td /tr tr tdh000010012/td td43

15、3215/td td计点/td td/td td2.0/td td测试项目/td td2021-06-23 10:14:40.843/td /tr tr tdh000010013/td td393899/td td计点/td td/td td2.0/td td测试项目/td td2021-06-23 10:14:40.843/td /tr tr tdh000010014/td td031736/td td计点/td td/td td2.0/td td测试项目/td td2021-06-23 10:14:40.843/td /tr tr tdh000010015/td td188600/td t

16、d计点/td td/td td2.0/td td测试项目/td td2021-06-23 10:14:40.843/td /tr tr tdh000010016/td td363407/td td计点/td td/td td2.0/td td测试项目/td td2021-06-23 10:14:40.843/td /tr tr tdh000010017/td td175315/td td计点/td td/td td2.0/td td测试项目/td td2021-06-23 10:14:40.843/td /tr tr tdh000010018/td td354437/td td计点/td td

17、/td td2.0/td td测试项目/td td2021-06-23 10:14:40.843/td /tr tr tdh000010019/td td234750/td td计点/td td/td td2.0/td td测试项目/td td2021-06-23 10:14:40.843/td /tr /tbody /table /td td class=middleRight/td /tr /tbody /table table id=fors:bottom border=0 cellpadding=0 cellspacing=0 width=100% tbody tr td class=left img src=images/jiao3.gif alt=/ /td td class=bottomMiddle /td td class=right img src=images/jiao4.gif alt=/ /td /tr /tbody /table input type=hidden name=fors value=fors /form /body /html 更多信息请查看IT技术专栏 .

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 科普知识


经营许可证编号:宁ICP备18001539号-1