Use JEXCELAPI to dynamically generate an Excel document

zhaozj2021-02-16  56

First, please go to http://www.andykhan.com/jexcelapi/index.html to download the Java Excel API, and more detailed introductions on the home page. The latest version is 2.4.3, and it can also go to: http://www.andykhan.com/jexcelapi/jexcelapi_2_4_3.tar.gz download to the latest version of the API, because the project is open source, so the downloaded file already Contains source code, the same, Javadoc in the file, you can refer to JavaDoc in the development.

After the download is complete, we need to add JXL.jar in the file to your development classpath. The following figure is the Excel screenshot now to produce: http://blog.9cbs.net/beming/gallery/Image/3437.aspx

code show as below:

File Excel = new file ("D: /aming.xls"); if (! Excel.exists ()) {Excel.createNewFile ();} Writableworkbook wwb = workbook.createworkbook (Excel); Writablesheet WS = Wwb.createsheet "TESTEXCEL", 0); label lable = null; // Support for Chinese Very good Lable = New Label (0, "My Chinese Heart"); ws.addcell (Lable); // You can define a template format of your cell WritableFont wf = new WritableFont (WritableFont.ARIAL, 10, WritableFont.NO_BOLD, false, UnderlineStyle.NO_UNDERLINE, Colour.BLACK); WritableCellFormat wcf = new WritableCellFormat (wf); wcf.setBackground (Colour.WHITE); lable = New Label (0, 1, "FDSL", WCF); ws.addcell (Lable); WF = New WritableFont (WritableFont.Times, 18, WritableFont.Bold, True); WF = New WritableCellFormat (WF); Lable = New Label (0, 2, "Aming", WCF); Ws.Addcell (Lable); // Cell type can also be defined as digital type Number NB = New Number (0, 3, 21.4321321); ws.addcell (NB ); // support formatting your digital string Numberformat nf = new numberFormat ("#. ###"); WCF = New WritablecellFormat (NF); NB = New Number (0, 4, 21.43254354354354, wcf) WS.Addcell (NB);

// Cell type can be boolean type Boolean BL = New Boolean (0,5, true); WS.AddCell (BL);

// Cell type can also be dates, time datetime dt = new datetime (0, 6, new date (); ws.addcell (dt);

/ / And can format your date format DateFormat DF = New DateFormat ("MM DD YYYY HH: MM: SS"); WCF = New WritablecellFormat (DF); DT = New DateTime (0, 7, New Date) ), ws.addcell (dt); // Start writing files wwb.write (); wwb.close (); is it easy and easy?

转载请注明原文地址:https://www.9cbs.com/read-17708.html

New Post(0)