Java Data Export feature export Excel file instance _java

Source: Internet
Author: User

The process of using a table (report) frequently in programming is mainly based on Excel tables. Here's how to write data to Excel tables in Java:

  1. Add Jar file

Java Import Export Excel file to introduce the Jxl.jar package, the most critical is that the API is pure Java, does not rely on the Windows system, even if running under Linux, it can also correctly handle Excel files. Download Address: http://www.andykhan.com/jexcelapi/

  2.JXL Understanding of Excel tables

See also: http://www.jb51.net/article/68631.htm

The following figure is the Excel file T.xls you are preparing to build. Coordinates (columns, rows): Roles (0,0), Ta (0,3), Functional description (3,0), UC22 (1,4).

   3.java code generates the T.xls file shown in the above picture according to the data in the program

Import Java.io.File;
Import jxl.*;
Import Jxl.write.Label;
Import Jxl.write.WritableSheet;

Import Jxl.write.WritableWorkbook; public class writer_excel{public static void Main (string[] args) {//header row String title[]={"role", "Number", "Feature Name", "feature description
    "}; Content String context[][]={{"UC11", "Set Course", "Create Course"}, {"UC12", "Set up a student list", "give the student list associated with the course"}, {"UC21"
    , "View student List", ""}, {"UC22", "View group Information", "Show the team list information for the teaching Assistant"}}; 
      The action executes try {//t.xls for the filename to be created Writableworkbook book= workbook.createworkbook (New file ("T.xls")); 
      
      Generates a worksheet named "first page", and parameter 0 indicates that this is the first page Writablesheet sheet=book.createsheet ("first page", 0); 
      Write content for (int i=0;i<4;i++)//title Sheet.addcell (New Label (i,0,title[i)); for (int i=0;i<4;i++)//context {for (int j=0;j<3;j++) {Sheet.addcell (new Label (j+1 
        , I+1,context[i][j]));
      } Sheet.addcell (New Label (0,1, "teacher")); Sheet.adDcell (New Label (0,3, "ta"));  /* Merge cells. Merging can be either horizontal or longitudinal *writablesheet.mergecells (int m,int n,int p,int q);
      Represents a rectangular region composed of (M,n) to (P,Q) cells combining */sheet.mergecells (0,1,0,2);
      
      Sheet.mergecells (0,3,0,4); 
      Write Data book.write (); 
    Close file Book.close ();
 The catch (Exception e) {}}}
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.