Source: https://blog.csdn.net/seesun2012
This is an execl文件导入数据库
operation that uses JXL parsing execl to import a database process 出现了科学计数法
that does not match the data you want to import, and the following are examples and solutions:
example after successful import :
1, mobile phone number: 15388886666
Scientific counting method:1.54E+10
2, Number: 123456789000000
Scientific counting method:1.23E+14
3. ID Card: 432222198808083789
scientific Counting method:4.32E+17
Solution Ideas :
1. Judge whether it is a numeric type (number) or a numerical formula (Number_formula);
2, get the parsed value to determine whether it contains (E, E, + and other symbols);
3. Using Java to bring the mathematical class, the scientific calculation formula into the desired type.
Specific code :
Parsing execlpublic static list<string[]> readexcel (File filePath) {list<string[]> List = new arraylist& Lt String[]> (); Date formatted SimpleDateFormat SDF = new SimpleDateFormat ("Yyyy-mm-dd"); try {//Read the file as IO stream inputstream in = new FileInputStream (FilePath); Get workbook Workbook book = Workbook.getworkbook (in); get worksheet Sheet Sheet = book.getsheet (0); Get total number of columns int columns = Sheet.getcolumns (); Get the total number of rows int rows = Sheet.getrows (); for (int k = 2; k < rows; k++) {//row string[] row = new String[columns]; for (int i = 0; i < columns; i++) {//Column cell cell = Sheet.getcell (i, k); Get the cell specific type value in the way if (cell.gettype () = = Celltype.label) {Labelcell Labelcell = (Labelcell) cell; Row[i] = labelcell.geTstring (); }else if (cell.gettype () = = Celltype.date) {//Excel type is time type processing; Datecell DC = (Datecell) cell; Row[i] = Sdf.format (Dc.getdate ()); }else if (cell.gettype () = = Celltype.number | | cell.gettype () = = Celltype.number_formula) {//Excel type is numeric type processing; Numbercell NC = (Numbercell) cell; Determine if it is a scientific notation (including symbols E, E, +, etc.) if (("" +nc.getvalue ()). IndexOf ("E")!=-1 | | ("" +nc.getvalue ()). IndexOf ("E")!=-1 | | ("" +nc.getvalue ()). IndexOf ("+")!=-1) {BigDecimal bd = new BigDecimal ("" +nc.getvalue ()); Row[i] = bd.tostring (); }else{Row[i] = "" + Nc.getvalue (); }} else {//Common way to get the cell value, return string row[i] = Cell.getconten TS (); } } Add to List.add (row) in the list collection; }//Close the Working thin book.close (); } catch (Exception e) {e.printstacktrace (); } return list; }
Java JXL Import Excel file, imported digital, ID number, mobile phone number into a scientific notation, solution