The use of POI technology
Frame-type SSH is using the Struts1
public void Outexcel (actionmapping mapping, Actionform form,
HttpServletRequest request, HttpServletResponse response) {
Your program needs to call something written here
try {
The first step is to create a webbook that corresponds to an Excel file
Hssfworkbook wb = new Hssfworkbook ();
In the second step, add a sheet in WebBook that corresponds to the sheet in the Excel file
Hssfsheet sheet = wb.createsheet ("name");
In the third step, add the No. 0 row of the table header to the sheet, noting that the old version of POI has a limit on the number of rows in Excel short
Hssfrow row = Sheet.createrow ((int) 0);
Fourth step, create a cell, and set the value header to center the header
Hssfcellstyle style = Wb.createcellstyle (); Style.setalignment (Hssfcellstyle.align_center);
Create a center format
Hssfcell cell = Row.createcell ((short) 0);
Cell.setcellvalue ("other");
Cell.setcellstyle (style);
Cell = Row.createcell ((short) 1);
Cell.setcellvalue ("other fetch");
Your program needs to call something written here
for (int i = 0; i < list1.size (); i++) {
for (int p = 0; p < list.size (); p++) {
if (List1.get (i). Equals (List.get (P). GETSSQX ())) {
TRACELXR sf=new TRACELXR ();
SF.SETSSQX (List.get (P). GETSSQX ());
SF.SETFG (List.get (P). GETFG ());
Newlist.add (SF);
}
}
}
for (int k1 = 0; k1 < newlist.size (); k1++) {
row = Sheet.createrow ((int) k1 + 1);
TRACELXR bgmultilevel = (TRACELXR) newlist.get (K1);
Row.createcell ((short) 0). Setcellvalue (BGMULTILEVEL.GETSSQX ());
Row.createcell ((short) 1). Setcellvalue (BGMULTILEVEL.GETFG ());
if (k1!=0) {
if (Newlist.get (k1-1). GETSSQX (). Equals (Newlist.get (K1). GETSSQX ())) {
Cellrangeaddress cra=new cellrangeaddress (K1, 1+k1, 0, 0);
Add merged cells in sheet
Sheet.addmergedregion (CRA);
}
}
}
Response.reset ();
Response.setcontenttype ("Application/vnd.ms-excel;charset=utf-8");
Response.setheader ("Content-disposition", "attachment;filename=" + New String (("Exportexcel". ToString () + ". x ls "). GetBytes ()," iso-8859-1 "));
OutputStream OS = Response.getoutputstream ();
Wb.write (OS); Os.close ();
}catch (IOException e) {
TODO auto-generated Catch block
E.printstacktrace ();
}
}
It's good to have a dynamic merge here. The method of invocation is written according to its own
Java dynamically export Excel merged cells