A simple example of jxl Excel Creation

Source: Internet
Author: User
Tags dateformat

You can download jxl. jar in Baidu or in the csdn resource Download Area.

The following address can also be downloaded without points:

Http://download.csdn.net/detail/laizhenhai88/4155005

 

 

Import Java. io. file; import jxl. workbook; import jxl. format. colour; import jxl. format. underlinestyle; import jxl. write. dateformat; import jxl. write. label; import jxl. write. number; import jxl. write. datetime; import jxl. write. boolean; import jxl. write. numberformat; import jxl. write. writablecellformat; import jxl. write. writablefont; import jxl. write. writablesheet; import jxl. write. writableworkbook; public class excelutil {public static void main (string [] ARGs) {// generate a readable Excel file object file xlsfile = new file ("D: \ myfile.xls "); writableworkbook workbook = NULL; writablesheet sheet = NULL; try {workbook = workbook. createworkbook (xlsfile); // Add the first worksheet sheet = workbook. createsheet ("sheetname", 0); // you can add a label (column, row, content) to the table header. addcell (new label (0, 0, ""); sheet. addcell (new label (1, 0, "oracle"); sheet. addcell (new label (0, 1, "integer"); sheet. addcell (new number (1, 1, 30); sheet. addcell (new label (0, 2, "decimal"); sheet. addcell (new number (1, 2, 30.12345); sheet. addcell (new label (0, 3, "font"); writablefont WF = new writablefont (writablefont. times, 12, writablefont. bold, true, underlinestyle. single, colour. red); writablecellformat cf = new writablecellformat (WF); sheet. addcell (new label (1, 3, "bold red", CF); sheet. addcell (new label (0, 4, "decimal format"); numberformat NF = new numberformat ("#. # "); writablecellformat CF2 = new writablecellformat (NF); sheet. addcell (new number (1, 4, 30.12345, CF2); sheet. addcell (new label (0, 5, "Boolean"); sheet. addcell (new Boolean (1, 5, false); sheet. addcell (new label (0, 6, "Time Format"); dateformat df = new dateformat ("yyyy-mm-dd hh: mm: SS "); writablecellformat cf3 = new writablecellformat (DF); sheet. addcell (New datetime (1, 6, new Java. util. date (), cf3); sheet. mergecells (,); sheet. addcell (new label (0, 7, "merge cells"); workbook. write (); workbook. close ();} catch (exception e) {e. printstacktrace ();}}}

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.