JXL set Excel font background color merge unit Grekon

Source: Internet
Author: User

Import Java.io.File; Import java.io.IOException; Import Java.net.URL; Import JXL. workbook; Import Jxl.format.UnderlineStyle; Import Jxl.write.Label; Import Jxl.write.WritableCellFormat; Import Jxl.write.WritableFont;
Import Jxl.write.WritableHyperlink;
Import Jxl.write.WritableImage;
Import Jxl.write.WritableSheet;
Import Jxl.write.WritableWorkbook;
Import jxl.write.WriteException;
Import jxl.write.biff.RowsExceededException;
public class Testexl {
public static void Main (String args[]) throws IOException,
Rowsexceededexception, WriteException {
Writableworkbook book = Workbook.createworkbook (New File ("F://aa.xls")); First step

Writablesheet sheet = book.createsheet ("sheet", 0); Create sheet
Sheet.setcolumnview (0, 30); To set the width of a column
Sheet.setcolumnview (1, 30); To set the width of a column
Sheet.setcolumnview (2, 30); To set the width of a column
Sheet.setrowview (6, 1000); Set the height of a row
Sheet.setrowview (4, 1000); Set the height of a row
Sheet.setrowview (5, 1000); Set the height of a row

Writablefont wf = new Writablefont (writablefont.arial, 15,
Writablefont.bold, False, Underlinestyle.no_underline,
Jxl.format.Colour.CORAL); Define formatting font underline italic bold color
Writablecellformat WCF = new Writablecellformat (WF); Cell definition
Wcf.setbackground (Jxl.format.Colour.BLACK); Set the background color of a cell
Wcf.setalignment (Jxl.format.Alignment.CENTRE); To set alignment

Sheet.addcell (New Label (0, 0, "Mailbox Asasasasa", WCF)); Normal cells with a defined format
Sheet.addcell (New Label (1, 0, "Action Asasasasa", WCF));
Sheet.addcell (New Label (2, 0, "Time Asasasasa", WCF));
Sheet.addcell (New Label (0, 1, ""));
Sheet.addcell (New Label (1, 1, "action"));
Sheet.addcell (New Label (2, 1, "time"));

Sheet.addcell (New Label (4, 0, "merged cell", WCF)); Merging cells
Sheet.addcell (New Label (4, 1, "Test 1"));
Sheet.addcell (New Label (5, 1, "Test 2"));
Sheet.addcell (New Label (6, 1, "Test 3"));
Sheet.mergecells (4, 0, 6, 0); Merging cells

Sheet.addcell (New Label (0, 3, "show picture JXL only support PNG format", WCF)); Show Picture title
Sheet.mergecells (0, 3, 3, 3); Merge Picture header cells
File File = new file ("F://1.png"); Get Pictures
Writableimage image = New Writableimage (0, 4, 3, 3, file); Set Picture Display location
4, 4 represents the height and width of the picture for 4 cells
Sheet.addimage (image); Load picture

Sheet.addcell (New Label (0, 8, "Excel Link Test", WCF)); Link title
Sheet.mergecells (0, 8, 2, 8);
Writablehyperlink link = new Writablehyperlink (0, 9, new URL (
"http://www.google.com"));
Link.setdescription ("link to use links to Google");
Sheet.mergecells (0, 9, 1, 9);
Sheet.addhyperlink (link);
Book.write ();
Book.close ();
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.