Java read Excel method

xiaoxiao2021-03-06  53

In the nearest project, the user requested the original historical data into the new system. We use Java to develop by users, the data format provided by the user is an Excel file. So I thought of using Apache's Poi, because I used it, I feel that I can do a test. I feel there is no problem, but when I import another file, I have an error, the system captures a javacastexception. Cause this unusual reason Because java.util.treemap is compared when the type is compared, the source code is developed due to POI, so I follow the location of the code error, I found that it is an internal error in Poi, and this bug has submitted to Apache's bugzilla. . The reason for this anomaly is due to the fact that the Excel file provided by the customer is generated by the original system through the Excel file, which is caused by the error of the file header during reading. I would like to try myself, but time is too tight to change my idea, I decided to use another library, I found JXL in SourceForge. Try it, or good, although a warning occurs when reading that relatively special file, but does not affect the accuracy of the read data. Let me write down the method.

Import java.io.file; import java.util.date; import jxl. *; import jxl.read.beff. *; import java.io. *;

public class testjeapi {public testjeapi () {try {Workbook workbook = Workbook.getWorkbook (new File ( "C: /TEMP/ehc.XLS")); Sheet sheet = workbook.getSheet (0); int rows = sheet.getRows (); For (int i = 1; i

String cbxmdm = sheet.getcell (0, i) .GetContents ();

String cbxmmc = sheet.getcell (1, i) .GetContents ();

// String JFSL = Sheet.getcell (7, i) .GetContents (). ReplaceAll (",", ");

//System.out.println ("jfsl :" jfsl);

Numbercell n = (Numbercell) Sheet.Getcell (7, i); // Numbercell is used to read cells in digital format.

System.out.println ("N:" N.GetValue ());

Double d = new double (n.getValue ());

System.out.println ("D:" D);

// system.out.println ("Cell Format:" Sheet.getcell (7, i) .gettype ());

// String JFSL = Sheet.getcell (7, i) .GetContents ();

// String JFJE = Numbercell.getcell (8, i) .GetContents ();

// Double DFSL = New Double (Numbercell.getcell (9, i) .getContents ());

// String DFJE = Sheet.getcell (10, i) .GetContents (); // system.out.println (i "| CBXMDM:" "CBXMDM " | " " CBXMMC "| " JFSL : " JFSL " | " " JFJE: " JFJE " | DFSL: " DFSL " | DFJE: " DFJE);

}}} Catch (biffexception ex) {ex.printStackTrace ();} catch (ooException ex) {ex.printstacktrace ();}

} Public static void main (string [] args) {testjeapi testjeapi1 = new testjeapi ();

}

转载请注明原文地址:https://www.9cbs.com/read-114728.html

New Post(0)