使用Jscript编写EXCEL导出(转)

下面是一段关于采用Jscript语言对EXCEL的导出,下面的程序是对导出的关键一段,读者可以自己参考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 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 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
iY++;
for (var j=0 ;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);
}
[@more@]

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/9650775/viewspace-922766/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/9650775/viewspace-922766/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值