1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
|
// Set the output format and header information response. setcontenttype ("application/X-msdownload; charset = GBK"); string filename =NewString ("supplier 2.16.xls ". getbytes ("GBK"), "iso_8859_1"); response. setheader ("content-disposition", "attachment; filename =" + filename); // virtual data string materialname = ""; // material name string size = "200 × 300"; // specification string unit = ""; // unit string qty = "2 "; // Number of string bands = "do not know the brand"; // material brand string Company = "a factory in Chengdu"; // manufacturer name string memo = "reliable quality "; // remarks string price = "20.30"; // price string repdate = "2007-04-11"; // list of quote time <string []> List =NewArraylist <string []> ();For(IntI = 10; I> 0; I --) {string [] Output = {materialname, size, unit, qty + I, band, company, memo, price, repdate }; list. add (output);} // output stream bytearrayoutputstream baos =NewBytearrayoutputstream (); // construct the work zone writableworkbook workbook = workbook. createworkbook (baos); // construct sheet writablesheet sheet = workbook. createsheet ("quote list", 0); // construct the bold title Font writablefont blodfont =NewWritablefont (writablefont. tahoma, 10, writablefont. Bold,False); Writablecellformat blodformat =NewWritablecellformat (blodfont); label Label =Null;Try{// Label =NewLabel (0, 0, "material name", blodformat); sheet. addcell (Label); label =NewLabel (1, 0, "type", blodformat); sheet. addcell (Label); label =NewLabel (2, 0, "unit", blodformat); sheet. addcell (Label); label =NewLabel (3, 0, "quantity", blodformat); sheet. addcell (Label); label =NewLabel (4, 0, "material brand", blodformat); sheet. addcell (Label); label =NewLabel (5, 0, "manufacturer name", blodformat); sheet. addcell (Label); label =NewLabel (6, 0, "Remarks", blodformat); sheet. addcell (Label); label =NewLabel (7, 0, "price", blodformat); sheet. addcell (Label); label =NewLabel (8, 0, "", blodformat); sheet. addcell (Label); // output business dataFor(IntI = 1; I <= List. Size (); I ++) {string [] Output = list. Get (I-1); label =NewLabel (0, I, output [0]); sheet. addcell (Label); label =NewLabel (1, I, output [1]); sheet. addcell (Label); label =NewLabel (2, I, output [2]); sheet. addcell (Label); label =NewLabel (3, I, output [3]); sheet. addcell (Label); label =NewLabel (4, I, output [4]); sheet. addcell (Label); label =NewLabel (5, I, output [5]); sheet. addcell (Label); label =NewLabel (6, I, output [6]); sheet. addcell (Label); label =NewLabel (7, I, output [7]); sheet. addcell (Label); label =NewLabel (8, I, repdate); sheet. addcell (Label);} // write to the file workbook. write (); workbook. close (); // return the file stream outputstream OS = response to the browser. getoutputstream (); OS. write (baos. tobytearray (); OS. flush (); OS. close (); baos. close ();}Catch(Rowsexceededexception e) {e. printstacktrace ();}Catch(Writeexception e) {e. printstacktrace ();}} |