javajspjavascript中如何實現將統計表格保存成excel文件?
< SCRIPT LANGUAGE=JavaScript >
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< tbloutrowslength;i++)
for(j=;j< tbloutrows(i)cellslength;j++)
oSheetCells(i+ j+)Value = tbloutrows(i)cells(j)innerText
oXLVisible = true;
oXLUserControl = true;
}
< /SCRIPT >
//這個問題其實你搜一下就有了
首先你的頁面上要有一個按鈕save
這個按鈕先做查詢數據庫然後action轉到保存excell的頁面即我給你的這些代碼由於我的是用這個頁面是隱藏的點擊save時有跳出界面問你是打開還是保存xxxxxxxxxxxxxx是你調用數據庫的記錄
< %@ page contentType=text/html;charset=gb % >
< %@ page import=javalang*% >
< %
try{
responsesetContentType(Application/msexcel);
responsesetHeader(ContentDisposition attachment;filename=trainlistxls);
StringBuffer cont=new StringBuffer();
% >
< HTML >
< HEAD >
< META httpequiv=ContentStyleType content=text/css >
< /HEAD >
< BODY >
< br >< br >< br >
< %
int status = khViewBeangetStatus();
if (status == ){
int rscount = khViewBeangetRSCount();
% >
< %
contappend(< html >< head >< META content=′text/html; charset=gb′ httpequiv=ContentType >< /head >< body > );
contappend(< h > SOP??μμé?ˉ?á?< /h >);
contappend(< table width=′%′ border=′′ > );
contappend(< tr > );
contappend(< td height=′′ >???to? < /td > );
contappend(< td height=′′ >???t?? < /td > );
contappend(< td height=′′ >??? < /td > );
contappend(< td height=′′ >éúD§ê±?? < /td > );
contappend(< /tr > );
contappend(< tr > );
contappend(< td >+xxxxxxxxxxxxxxxxxxxxxxxx + < /td > );
contappend(< td >+xxxxxxxxxxxxxxxxxxxxxxxx + < /td > );
contappend(< td >+xxxxxxxxxxxxxxxxxxxxxxxx + < /td > );
contappend(< td >+xxxxxxxxxxxxxxxxxxxxxxxx + < /td > );
contappend(< /tr > );
contappend(< tr > );
contappend(< td >+xxxxxxxxxxxxxxxxxxxxxxxx + < /td > );
contappend(< td >+xxxxxxxxxxxxxxxxxxxxxxxx + < /td > );
contappend(< td >+xxxxxxxxxxxxxxxxxxxxxxxx + < /td > );
contappend(< td >+xxxxxxxxxxxxxxxxxxxxxxxx + < /td > );
}
contappend(< /table > );
contappend(< /body >< /html > );
responsegetWriter()println(conttoString());
responsegetWriter()close();
% >
< %
}
else if (status > ) {
% >
< hr color=#CC >
< span class=text >< font color=blue size= >< center >< P >?Têy?Y < /P >< /center >< /font >< /span >
< %
}
else if (status < ) {
% >
< hr color=#CC >
< span class=text >< font color=red size= >< center >< P >?¢éú′í?ó < /P >< /center >< /font >< /span >
< %
}
% >
< hr color=#CC >
< %
}
catch (Exception e){
outprintln(etoString());
}
% >
< /BODY >
< /HTML >
From:http://tw.wingwit.com/Article/program/Java/hx/201311/27116.html