A little knowledge about JXL

xiaoxiao2021-03-06  26

This is what I saw on Javaeye.

Excerpt, the author can't clear it.

When writing data in the XLS file, you need to pay attention to the first to create a new XLS file OutputStream OS = New FileoutputStream ("c: //excel2.xls");

Establish a work file JXL.WRITE.WRITABLEWORKBOOK WWB = Workbook.createworkBook (New File);

If this file already exists, then we can join a Sheet in this file to separate the previous data; jxl.write.writablesheet WS = wwb.createsheet ("Test Sheet 1", 0); in front of the Createsheet method The parameter is the Sheet name, the next is the Sheet number to operate.

Next, you can write data in this file.

Pay attention to the data when writing data

(1) Added font style jxl.write.writablefont wf = new jxl.write.writablefont (WritableFont.bold, true); WritableFont.bold, true); WritableFont () method parameter description: This method is a container, you can put it In the first few: Times is the font size, he writes 18 second: bold is the judge whether it is a slope, select True, the third: Arial fourth: underlinestyle.no_underline Underline Fifth: JXL.FORMAT.COLOUR.RED font color is red

Jxl.write.writablecellformat wcff = new jxl.write.writablecellformat (wf);

Jxl.write.Label labelc = new jxl.write.label (0, 0, "this is a label cell", ws.addcell (labelc); three parameters in the label () method are the representative The number of columns, the second is the number of lines, and the fourth representative to write is the fourth is optional. It is an option to enter the style inside this label and then write the content into the Sheet by writing the Sheet method AddCell ().

(2) Add Number object with formatting jxl.write.Numberformat nf = new jxl.write.Numberformat ("#. ##");

(3) Add Number object (3.1) to display the format of Number object data

JXL.WRITE.NUMBERFORMAT NF = New jxl.write.Numberformat ("#. ##"); jxl.write.writablecellformat wcfn = new jxl.write.writablecellFormat (NF);

Jxl.write.number labelnf = new jxl.write.Number (1, 1, 3.1415926, ws.addcell (labelnf); Number () method parameter description: The third representation of the input position is input two content

(4) Add Boolean object jxl.write.Boolean labelb = new jxl.write.Boolean (0, 2, false); ws.addcell (labelb);

(5) Add a DateTime object jxl.write.datetime labeldt = new jxl.write.datetime (0, 3, new java.util.date ()); ws.addcell (labeldt); parameter of the DateTime () method front two A third indicator input is the current time (6) that is input (6) adds the dateFormat object with formatting. This display current time is all information, including the annual hourly second jxl.write.dateFormat DF = New jxl.write. DateFormat ("DD MM YYYY HH: MM: SS"); jxl.write.writablecellformat wcfdf = new jxl.write.writablecellFormat (DF); jxl.write.datetime labeldtf = new jxl.write.datetime (1, 3, New Java.util.date (), wcfdf); ws.addcell (labeldtf);

(7) Add object with font color formatting

jxl.write.WritableFont wfc = new jxl.write.WritableFont (WritableFont.ARIAL, 10, WritableFont.NO_BOLD, false, UnderlineStyle.NO_UNDERLINE, jxl.format.Colour.RED); jxl.write.WritableCellFormat wcfFC = new jxl.write .Writablecellformat (wfc);

Import = "jxl.formaVat. * jxl.write.writablefont wfc = new jxl.write.writablefont (WritableFont.arial, 20, Writablefont.bold, false, underlinestyle.no_underline, jxl.format.colour.green);

(8) Set a cell style

jxl.write.WritableFont wfc = new jxl.write.WritableFont (WritableFont.ARIAL, 10, WritableFont.NO_BOLD, false, UnderlineStyle.NO_UNDERLINE, jxl.format.Colour.RED); jxl.write.WritableCellFormat wcfFC = new jxl.write .Writablecellformat (wfc);

Import = "jxl.formaVat. * jxl.write.writablefont wfc = new jxl.write.writablefont (WritableFont.arial, 20, Writablefont.bold, false, underlinestyle.no_underline, jxl.format.colour.green);

(8) Set a cell style

JXL.WRITE.WRITABECELLFORMAT WCFFC = New JXL.WRITE.WRITABECECELLFORMAT (WFC); wcffc.setback in (jxl.format.colour.red); // Setting the cell's color is red WCFFC = New JXL.WRITE.LABEL (6, 0, "I Love China", WCFFC);

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

New Post(0)