Take the quality assurance letter as an example
JSP file:
To add an export button:
<a class= "Btn_short" name= "button" id= "button" href= "javascript:void (0)" title= "Export" onclick= " QUERYWLZXZLBHLISTUTILS.JLDC () "> Export </a>
Export JS:
<script type= "Text/javascript" >;
Querywlzxzlbhlistutils = {};
QUERYWLZXZLBHLISTUTILS.JLDC = function () {
$ ("Query_wlzxzlbh_list_form"). Action = "wlzxzlbh/jlexport.do";
EXT.MILAN.PAGEJS.PAGE_WLZXZLBH.JLDC (' Query_wlzxzlbh_list_form ');
};
</script>
Pagejs file:
EXT.MILAN.PAGEJS.PAGE_WLZXZLBH.JLDC = function (formId) {
Milan.ajaxutility.downloadFile ({form: $ (formId)});
};
Action Layer File:
Public String Jlexport () {
Wlzxzlbhquery query = NewQuery (wlzxzlbhquery.class,default_sort_columns);
try{
Reportstream = wlzxzlbhmanager.jlexport (query);
if (reportstream! = null) {
String fileName = "Quality assurance letter. xls";
This.filename = new String (Filename.getbytes (), "iso8859-1");
return "SJDC";
}else{
map<string, object> resinfo = null;
Resinfo = Resinfo.getresinfo ("", False, False, 2, "without any export results", "");
Outxmljson (Resinfo);
}
} catch (Exception e) {
E.printstacktrace ();
}
return null;
}
Manager Layer Files:
Public InputStream jlexport (wlzxzlbhquery query) {
list<wlzxzlbh> list = wlzxzlbhdao.jlexport (query);
if (list = null && list.size () >0) {
Bytearrayoutputstream Ops = Genjlxls (list);
InputStream ips = new Bytearrayinputstream (Ops.tobytearray ());
return IPs;
}
return null;
}
Private Bytearrayoutputstream Genjlxls (list<wlzxzlbh> List) {
Writableworkbook WWB;
Bytearrayoutputstream Ops = new Bytearrayoutputstream ();
try {
WWB = Workbook.createworkbook (OPS);
Format the text of a cell
Writablefont wf = new Writablefont (Writablefont.arial,12,writablefont.no_bold,false,underlinestyle.no_underline, Colour.black);
Writablecellformat WCF = new Writablecellformat (WF);
Wcf.setverticalalignment (Verticalalignment.centre);
Wcf.setalignment (Alignment.centre);
Populating the contents of the data
Label label;
Writablesheet sheet=wwb.createsheet ("Quality table letter", 0);
Sheet.setcolumnview (0,10);
Sheet.setcolumnview (1,30);
Sheet.setcolumnview (2,30);
Sheet.setcolumnview (3,30);
Sheet.setcolumnview (4,30);
Sheet.setcolumnview (5,30);
Sheet.setcolumnview (6,30);
Sheet.setcolumnview (7,30);
Sheet.setcolumnview (8,30);
Sheet.setcolumnview (9,30);
Sheet.setcolumnview (10,30);
Sheet.setcolumnview (11,30);
Sheet.setcolumnview (12,30);
Create a table header
Sheet.mergecells (0,0,0,0);
Label = new label (0,0, "ordinal", WCF);
Sheet.addcell (label);
Label = new label (1, 0, "Vendor name", WCF);
Sheet.addcell (label);
Label = new label (2,0, "handler", WCF);
Sheet.addcell (label);
Label = new label (3,0, "date of the letter of Guarantee", WCF);
Sheet.addcell (label);
Label = new label (4,0, "date of receipt of the letter of Guarantee", WCF);
Sheet.addcell (label);
Label = new label (5,0, "function number", WCF);
Sheet.addcell (label);
Label = new label (6,0, "Letter of Guarantee Issue date", WCF);
Sheet.addcell (label);
Label = new label (7,0, "Letter of Guarantee Effective Date", WCF);
Sheet.addcell (label);
Label = new label (8,0, "Letter of guarantee Expiration date", WCF);
Sheet.addcell (label);
Label = new label (9,0, "Letter of Guarantee Amount", WCF);
Sheet.addcell (label);
Label = new label (10,0, "Letter of Guarantee return time", WCF);
Sheet.addcell (label);
Label = new label (11,0, "Letter of Guarantee return reason", WCF);
Sheet.addcell (label);
Label = new label (12,0, "state", WCF);
Sheet.addcell (label);
int i=0;
for (wlzxzlbh zlbh:list) {
Label = new label (0,i+1, (i+1) + "", WCF); Serial number
Sheet.addcell (label);
Label = new label (1,I+1,ZLBH.GETGYSMC (), WCF);
Sheet.addcell (label);
Label = new label (2,I+1,ZLBH.GETJBRXM (), WCF);
Sheet.addcell (label);
Label = new label (3,i+1,zlbh.getykbhrqstring (), WCF);
Sheet.addcell (label);
Label = new label (4,i+1,zlbh.getsdbhrqstring (), WCF);
Sheet.addcell (label);
Label = new label (5,I+1,ZLBH.GETHH (), WCF);
Sheet.addcell (label);
Label = new label (6,i+1,zlbh.getbhqfrqstring (), WCF);
Sheet.addcell (label);
Label = new label (7,i+1,zlbh.getbhsxrqstring (), WCF);
Sheet.addcell (label);
Label = new label (8,i+1,zlbh.getbhzfrqstring (), WCF);
Sheet.addcell (label);
Amount is a number and needs to be converted to a string output
Label = new label (9,i+1,zlbh.getbhje () + "", WCF);
Sheet.addcell (label);
Label = new label (10,i+1,zlbh.getbhthsjstring (), WCF);
Sheet.addcell (label);
Label = new label (11,I+1,ZLBH.GETTHYY (), WCF);
Sheet.addcell (label);
Convert the state of a number format to text
String ZT = "";
if (zlbh.getzt () = = 0) {
ZT = "not processed";
}else if (zlbh.getzt () = = 1) {
ZT = "Done";
}else {
ZT = "returned";
}
Label = new label (12,I+1,ZT,WCF);
Sheet.addcell (label);
i++;
}
Wwb.write ();
Wwb.close ();
} catch (IOException e) {
E.printstacktrace ();
} catch (Rowsexceededexception e) {
E.printstacktrace ();
} catch (WriteException e) {
E.printstacktrace ();
}
return OPS;
}
DAO Layer Files:
Public list<wlzxzlbh> jlexport (wlzxzlbhquery query) {
String sql = "Select t from wlzxzlbh t where 1=1"
+ "/~ and T.GYSMC = ' [GYSMC] ' ~/"
+ "/~ and T.jbrxm = ' [Jbrxm] ' ~/"
+ "/~ and T.YKBHRQ = ' [YKBHRQ] ' ~/"
+ "/~ and T.SDBHRQ = ' [SDBHRQ] ' ~/"
+ "/~ and t.hh = ' [hh] ' ~/"
+ "/~ and T.bhqfrq = ' [Bhqfrq] ' ~/"
+ "/~ and T.bhsxrq = ' [Bhsxrq] ' ~/"
+ "/~ and T.bhzfrq = ' [Bhzfrq] ' ~/"
+ "/~ and T.bhje = ' [Bhje] ' ~/"
+ "/~ and T.BHTHSJ = ' [BHTHSJ] ' ~/"
+ "/~ and t.thyy = ' [Thyy] ' ~/"
+ "/~ order BY [Sortcolumns] ~/";
Search All
Return Findhqlall (Sql,query);
}
XML configuration file:
Export conversion to stream output
<action name= "wlzxzlbh/*" method= "{1}" class= "Com.tech15.wlzx.action.WlzxZlbhAction" >
<result name= "SJDC" type= "Stream" >
<param name= "ContentType" >application/vnd.ms-excel</param>
<param name= "contentdisposition" >attachment;filename= "${filename}" </param>
<param name= "BufferSize" >4096</param>
<param name= "InputName" >reportStream</param>
</result>
<result name= "*" type= "direct" > Quality assurance Letter </result>
</action>
Wind power Platform Export function