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) {}}}