熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Java編程 >> Java核心技術 >> 正文

如何實現將統計表格保存成excel文件

2022-06-13   來源: Java核心技術 

  javajspjavascript中如何實現將統計表格保存成excel文件?

&lt SCRIPT LANGUAGE=JavaScript &gt
function AutomateExcel()
{
var ij;
// Start Excel and get Application object
var oXL = new ActiveXObject(ExcelApplication);

  oXLVisible = true;

  // Get a new workbook
var oWB = oXLWorkbooksAdd();
var oSheet = oWBActiveSheet;

  // Add table headers going cell by cell
// tblout表的ID
for(i=;i&lt tbloutrowslength;i++)
for(j=;j&lt tbloutrows(i)cellslength;j++)
oSheetCells(i+ j+)Value = tbloutrows(i)cells(j)innerText

  oXLVisible = true;
oXLUserControl = true;
}
&lt /SCRIPT &gt
//這個問題其實你搜一下就有了

  

  首先你的頁面上要有一個按鈕save
這個按鈕先做查詢數據庫然後action轉到保存excell的頁面即我給你的這些代碼由於我的是用這個頁面是隱藏的點擊save時有跳出界面問你是打開還是保存xxxxxxxxxxxxxx是你調用數據庫的記錄
&lt %@ page contentType=text/html;charset=gb % &gt
&lt %@ page import=javalang*% &gt
&lt %
try{
responsesetContentType(Application/msexcel);
responsesetHeader(ContentDisposition attachment;filename=trainlistxls);
StringBuffer cont=new StringBuffer();
% &gt
&lt HTML &gt
&lt HEAD &gt
&lt META httpequiv=ContentStyleType content=text/css &gt
&lt /HEAD &gt
&lt BODY &gt
&lt br &gt&lt br &gt&lt br &gt
&lt %
int status = khViewBeangetStatus();
if (status == ){
int rscount = khViewBeangetRSCount();
% &gt
&lt %
contappend(&lt html &gt&lt head &gt&lt META content=′text/html; charset=gb′ httpequiv=ContentType &gt&lt /head &gt&lt body &gt );
contappend(&lt h &gt SOP??μμé?ˉ?á?&lt /h &gt);
contappend(&lt table width=′%′ border=′′ &gt );
contappend(&lt tr &gt );
contappend(&lt td height=′′ &gt???to? &lt /td &gt );
contappend(&lt td height=′′ &gt???t?? &lt /td &gt );
contappend(&lt td height=′′ &gt??? &lt /td &gt );
contappend(&lt td height=′′ &gtéúD§ê±?? &lt /td &gt );
contappend(&lt /tr &gt );
contappend(&lt tr &gt );
contappend(&lt td &gt+xxxxxxxxxxxxxxxxxxxxxxxx + &lt /td &gt );
contappend(&lt td &gt+xxxxxxxxxxxxxxxxxxxxxxxx + &lt /td &gt );
contappend(&lt td &gt+xxxxxxxxxxxxxxxxxxxxxxxx + &lt /td &gt );
contappend(&lt td &gt+xxxxxxxxxxxxxxxxxxxxxxxx + &lt /td &gt );
contappend(&lt /tr &gt );
contappend(&lt tr &gt );
contappend(&lt td &gt+xxxxxxxxxxxxxxxxxxxxxxxx + &lt /td &gt );
contappend(&lt td &gt+xxxxxxxxxxxxxxxxxxxxxxxx + &lt /td &gt );
contappend(&lt td &gt+xxxxxxxxxxxxxxxxxxxxxxxx + &lt /td &gt );
contappend(&lt td &gt+xxxxxxxxxxxxxxxxxxxxxxxx + &lt /td &gt );
}
contappend(&lt /table &gt );
contappend(&lt /body &gt&lt /html &gt );
responsegetWriter()println(conttoString());
responsegetWriter()close();
% &gt
&lt %
}
else if (status  &gt ) {
% &gt
&lt hr color=#CC &gt
&lt span class=text &gt&lt font color=blue size= &gt&lt center &gt&lt P &gt?Têy?Y &lt /P &gt&lt /center &gt&lt /font &gt&lt /span &gt
&lt %
}
else if (status &lt  ) {
% &gt
&lt hr color=#CC &gt
&lt span class=text &gt&lt font color=red size= &gt&lt center &gt&lt P &gt?¢éú′í?ó &lt /P &gt&lt /center &gt&lt /font &gt&lt /span &gt
&lt %
}
% &gt
&lt hr color=#CC &gt
&lt %
}
catch (Exception e){
outprintln(etoString());
}
% &gt
&lt /BODY &gt
&lt /HTML &gt


From:http://tw.wingwit.com/Article/program/Java/hx/201311/27116.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.