Java Create, manipulate tables

Source: Internet
Author: User

Java Operation simple table test code

@Test public void Test1 () throws Rowsexceededexception, WriteException, IOException, interruptedexception {File        File=new file ("e:\\1.xlsx");//file name cannot appear in time format OutputStream os =new fileoutputstream (file);        Create a workbook Writableworkbook workbook = workbook.createworkbook (OS);        Create a new page Writablesheet sheet = workbook.createsheet ("First sheet", 0);        Create the content to be displayed, create a cell, the first parameter is the column coordinates, the second parameter is the row coordinate, the third parameter is the content label Xuexiao = new label (0,0, "school");        Sheet.addcell (Xuexiao);        Label Zhuanye = new label (1, 0, "professional");        Sheet.addcell (Zhuanye);        Label Jingzhengli = new label (2,0, "professional competitiveness");                Sheet.addcell (Jingzhengli);        Label Qinghua = new label (0,1, "Tsinghua University");        Sheet.addcell (Qinghua);        Label Jisuanji = new Label (1, 1, "Computer Professional");        Sheet.addcell (Jisuanji);        Label Gao = new label (2,1, "high");                Sheet.addcell (GAO);        Label Beida = new label (0,2, "Peking University");        Sheet.addcell (Beida); Label Falv = new Label (1, 2, "legal profession");        Sheet.addcell (FALV);        Label Zhong = new label (2,2, "medium");                Sheet.addcell (Zhong);        Label Ligong = new label (0,3, "Beijing Institute");        Sheet.addcell (Ligong);        Label Hangkong = new Label (1, 3, "aviation Professional");        Sheet.addcell (Hangkong);        Label di = new label (2,3, "low");                Sheet.addcell (DI);        Writes the created content to the output stream and closes the output stream workbook.write ();        Workbook.close ();    Os.close ();     }

Using the test code to generate a tabular file requires the use of a jar package Jxl.jar

1. First create a table file object

        File file=new file ("e:\\1.xlsx"); // file name cannot appear in time format        OutputStream OS =new fileoutputstream (file);

2. Create a workbook, create a new page

        // Create a workbook        Writableworkbook workbook = workbook.createworkbook (OS);         // Create a new page        Writablesheet sheet = workbook.createsheet ("First sheet", 0);

3. Generate a cell and join the workbook (where the label parameter has three columns, rows, contents)

        New Label (0,0, "school");        Sheet.addcell (Xuexiao);

Can actually be simplified to

Sheet.addcell (new lable (0,0, "school"));

4. Closing Resources last

        // writes the created content to the output stream and closes the output stream         workbook.write ();        Workbook.close ();        Os.close ();

Java Create, manipulate tables

Related Article

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.