In java, jsp, and javascript, how does one save a statistical table as an excel file?
---------------------------------------------------------------
& Lt script language = "JavaScript" & gt
Function AutomateExcel ()
{
Var I, j;
// Start Excel and get Application object.
Var oXL = new ActiveXObject ("Excel. Application ");
OXL. Visible = true;
// Get a new workbook.
Var oWB = oXL. Workbooks. Add ();
Var oSheet = oWB. ActiveSheet;
// Add table headers going cell by cell.
// Tblout table ID
For (I = 0; I & lt tblout. rows. length; I ++)
For (j = 0; j & lt tblout. rows (I). cells. length; j ++)
OSheet. Cells (I + 1, j + 1). Value = tblout. rows (I). cells (j). innerText
OXL. Visible = true;
OXL. UserControl = true;
}
& Lt/SCRIPT & gt
// You can search for the problem.
---------------------------------------------------------------
First, you need a button on the page: save
This button first queries the database, and then the action goes to the page for saving excell, that is, the code I gave you, Because I used this page to hide it, when you click save, a dialog box is displayed, asking whether to open or save the file. xxxxxxxxxxxxxx indicates the record of the database you called,
& Lt % @ page contentType = "text/html; charset = gb2312" % & gt
& Lt % @ page import = "java. lang. *" % & gt
& Lt %
Try {
Response. setContentType ("Application/msexcel ");
Response. setHeader ("Content-Disposition", "attachment?filename=trainlist.xls ");
StringBuffer cont = new StringBuffer ("");
% & Gt
& Lt HTML & gt
& Lt HEAD & gt
& Lt META http-equiv = "Content-Style-Type" content = "text/css" & gt
& Lt/HEAD & gt
& Lt BODY & gt
& Lt br & gt
& Lt %
Int status = khViewBean. getStatus ();
If (status = 0 ){
Int rscount = khViewBean. getRSCount ();
% & Gt
& Lt %
Cont. append ("& lt html & gt & lt head & gt & lt META content = 'text/html; charset = gb2312' http-equiv = Content-Type & gt & lt/head & gt & lt body & gt ");
Cont. append ("& lt h1 & gt SOP ?? μ? Why? Á1? & Lt/h1 & gt ");
Cont. append ("& lt table width = '000000' border = '1' & gt ");
Cont. append ("& lt tr & gt ");
Cont. append ("& lt td height = '19' & gt ??? To? & Lt/td & gt ");
Cont. append ("& lt td height = '19' & gt ??? T ?? & Lt/td & gt ");
Cont. append ("& lt td height = '19' & gt2 ??? & Lt/td & gt ");
Cont. append ("& lt td height = '19' & gt éúd § {± ?? & Lt/td & gt ");
Cont. append ("& lt/tr & gt ");
Cont. append ("& lt tr & gt ");
Cont. append ("& lt td & gt" + xxxxxxxxxxxxxxxxxxxxxxxx + "& lt/td & gt ");
Cont. append ("& lt td & gt" + xxxxxxxxxxxxxxxxxxxxxxxx + "& lt/td & gt ");
Cont. append ("& lt td & gt" + xxxxxxxxxxxxxxxxxxxxxxxx + "& lt/td & gt ");
Cont. append ("& lt td & gt" + xxxxxxxxxxxxxxxxxxxxxxxx + "& lt/td & gt ");
Cont. append ("& lt/tr & gt ");
Cont. append ("& lt tr & gt ");
Cont. append ("& lt td & gt" + xxxxxxxxxxxxxxxxxxxxxxxx + "& lt/td & gt ");
Cont. append ("& lt td & gt" + xxxxxxxxxxxxxxxxxxxxxxxx + "& lt/td & gt ");
Cont. append ("& lt td & gt" + xxxxxxxxxxxxxxxxxxxxxxxx + "& lt/td & gt ");
Cont. append ("& lt td & gt" + xxxxxxxxxxxxxxxxxxxxxxxx + "& lt/td & gt ");
}
Cont. append ("& lt/table & gt ");
Cont. append ("& lt/body & gt & lt/html & gt ");
Response. getWriter (). println (cont. toString ());
Response. getWriter (). close ();
% & Gt
& Lt %
}
Else if (status & gt 0 ){
% & Gt
& Lt hr color = "# 6699CC" & gt
& Lt span class = "text" & gt & lt font color = "blue" size = "16" & 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 0 ){
% & Gt
& Lt hr color = "# 6699CC" & gt
& Lt span class = "text" & gt & lt font color = "red" size = "16" & gt & lt center & gt & lt P & gt? ? Ó& lt/P & gt & lt/center & gt & lt/font & gt & lt/span & gt
& Lt %
}
% & Gt
& Lt hr color = "# 6699CC" & gt
& Lt %
}
Catch (Exception e ){
Out. println (e. toString ());
}
% & Gt
& Lt/BODY & gt
& Lt/HTML & gt