这篇文章主要介绍了如何使用jscript编写excel导出,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。function exportexcel(){ &nbs
这篇文章主要介绍了如何使用jscript编写excel导出,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。
function exportexcel()
{
var iSubjectNum,iElementNum;
var sText;
var iX=1;
var iY=2;
var xlsub;
// alert(‘export‘);
IniExcel();
xlApp.visible=false;
if (fso.FileExists(sExcelPath)==true ) {
xlsub=xlApp.Application.Workbooks.Open(sExcelPath);
//alert(xlsub);
//xlsub=xlApp.Application.Worksheets(ipage);
}
else{
xlApp.Workbooks.Add();
//xlsub=xlApp.Application.Worksheets(1);
//ipage=1;
}
var sheetcount=xlApp.Application.Worksheets.Count;
var addcount=ipage-sheetcount;
if (addcount!=0){
for(var m=0;m xlApp.Application.Worksheets.Add();
}
//Ñ°ÕÒÊÇ?ñÓÐÏàͬµÄSHEET
var bFlag=false;
var isheetpos=-1;
for (var n=1;n<=sheetcount;n++) {
if (xlApp.Application.Worksheets(n).Name==("Sheet"+ipage.toString())) {
bFlag=true;
isheetpos=n;
}
}
if (bFlag==false )
{ xlApp.Application.Worksheets.Add();
ipage=1;
}
else
{
ipage=isheetpos;
}
xlsub=xlApp.Application.Worksheets(ipage);
xlsub.Cells(1,1).Value =oHead.ReportName.toString();
sText=of_convert_char(1)+"1:"+of_convert_char(iColumnNum)+"1";
xlsub.Range(sText).Merge(true);
xlsub.Range(sText).HorizontalAlignment=3;
xlsub.Range(sText).Font.Size=20;
xlsub.Range(sText).Font.Bold=true;
iSubjectNum=oHead.oSubject.length;
iY=iY+1;
for(var i= 0; i<iSubjectNum;i++) {
if (oHead.oSubject[i].oElement==null){
xlsub.Cells(iY,iX).Value =oHead.oSubject[i].SubjectName.toString();
var temp=iY+3;
sText=of_convert_char(iX)+iY.toString()+":"+of_convert_char(iX)+temp.toString();
xlsub.Range(sText).Merge(false);
xlsub.Range(sText).HorizontalAlignment=3;
xlsub.Range(sText).Borders.LineStyle=1;
xlsub.Range(sText).Font.Size=10;
continue;
}
else
iElementNum= oHead.oSubject[i].oElement.length;
xlsub.Cells(iY,iX).Value =oHead.oSubject[i].SubjectName.toString();
sText=of_convert_char(iX)+iY+":"+of_convert_char(iX+iElementNum-1)+iY;
xlsub.Range(sText).Merge(true);
xlsub.Range(sText).HorizontalAlignment=3;
xlsub.Range(sText).Borders.LineStyle=1;
xlsub.Range(sText).Font.Size=10;
iY=iY+1;
for(var j=0;j<iElementNum;j++){
xlsub.Cells(iY,iX).Value =oHead.oSubject[i].oElement[j].ElementName.toString();
var temp=iY+2;
sText=of_convert_char(iX)+iY.toString()+":"+of_convert_char(iX)+temp.toString();
xlsub.Range(sText).Merge(false);
xlsub.Range(sText).HorizontalAlignment=3;
xlsub.Range(sText).Borders.LineStyle=1;
xlsub.Range(sText).Font.Size=10;
iX=iX+1;
}
iY=iY-1;
}
iY=iY+3;
for (var i=0;i<iRowNum;i++) {
iY++;
for (var j=0 ;j<iColumnNum;j++) {
xlsub.Cells(iY,j+1).Value=oBody[i][j].toString();
xlsub.Cells(iY,j+1).Borders.LineStyle=1;
xlsub.Cells(iY,j+1).Font.Size=10;
}
}
if (fso.FileExists(sExcelPath)==true ) {
var thiswork=xlApp.Application.ActiveWorkbook;
thiswork.Saved=true;
thiswork.Save();
thiswork.Close(true);
}
else
xlsub.SaveAs(sExcelPath);
window_onunload();
alert("Îļþ´æ?ÅÔÚ£º"+sExcelPath);
}
感谢你能够认真阅读完这篇文章,希望小编分享的“如何使用Jscript编写EXCEL导出”这篇文章对大家有帮助,同时也希望大家多多支持编程网,关注编程网精选频道,更多相关知识等着你来学习!
--结束END--
本文标题: 如何使用Jscript编写EXCEL导出
本文链接: https://www.lsjlt.com/news/233305.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0