The processing of form (report) is often used in programming in programming. Here are the method of reading the Excel table with Java:
1. Add jar file
Java introduces the export Excel file to introduce the JXL.JAR package. The most important thing is that this API is pure Java, which does not rely on the Windows system. Even if it runs under Linux, it can also handle the excel file correctly. Download address: http://www.andykhan.com/jexcelapi/
2.jxl's understanding of the excel table
(1) The position of each cell is considered to be given by a two -dimensional coordinate (i, j). Among them, I represent column, J represents line, and increases from top to bottom, increasing from left to right.
(2) The coordinates of the merger cells are the most left and the top cells. As shown in the figure below, T.XLS, a group list (0,0), Chen Yin (1,2), Chen Kaixian (1,6).
3. Java code to read t.xls
Import java.io.file; Import JXL.*; Public Class Read_excel {Public Static void Main (String [] ARGS) {int i; sheet sheet; Cell1 , cell2, cell3; try {//t.xls为要读取的excel文件名book= Workbook.getWorkbook(new File("t.xls")); //获得第一个工作表对象(ecxel中sheet的编号从0开始,0,1,2, 3, ....) Sheet = Book.getsheet (0); // Get the cell Cell1 = Sheet.getCell (0,0); System.out.println ("+Cell1.getContents ("+Cell1.getContents ); I = 1; While (TRUE) {// Get the cell cell1 = sheet.getcell (0, i); // (column, line) cell2 = sheet.getcell (1, i); cell3 = Sheet.getcell (2, i); if ("". Equals (cell1.getContents ()) == True) // "/t"+cell2.getContents ()+"/T "+Cell3.getContents ()); I ++;} Book.close ();} Catch (Exception E) {}}}}}}