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