1. Using Open Source Tools Jxl.jar
2. Function: Parse general Excel. The XLS format test is feasible and xlsx is not tested. The Excel Test format is a simple layout file like table. The first behavior title, followed by the behavior content. Code
Content is parsed correctly and the first row (header) is automatically discarded.
3. Sample code (import the necessary libraries yourself)
1 Public Static voidReadexcel ()throwsbiffexception, ioexception{2 //Create a list to store the read content3List List =NewArrayList ();4Workbook RWB =NULL;5Cell cell =NULL;6 7 //Create an input stream8InputStream stream =NewFileInputStream ("D:\\testjxl.xls");9 Ten //get the Excel file object OneRWB =Workbook.getworkbook (stream); A - //gets the default first for the specified worksheet of a file -Sheet Sheet = Rwb.getsheet (0); the - //Number of Rows (table header directory not required, starting from 1) - for(inti=0; I<sheet.getrows (); i++){ - + //create an array to store the values for each column -string[] str =Newstring[sheet.getcolumns ()]; + A //Number of columns at for(intj=0; J<sheet.getcolumns (); J + +){ - - //get the value of row i, column J -Cell =Sheet.getcell (j,i); -STR[J] =cell.getcontents (); - in } - //Save the newly acquired column to list to List.add (str); + } - for(intI=0;i<list.size (); i++){ thestring[] str =(string[]) list.get (i); * for(intj=0;j<str.length;j++){ $ System.out.println (Str[j]);Panax Notoginseng } - } the}
Parsing the Java Code Toolbox Excel