web123456

Java to read Excel files


Operation steps:

1. First, download the JExcelApi rar package online. The latest one is: jexcelapi_2_6_12.tar, then unzip it, copy the file to the WEB-INF\lib directory or directly import it into a Java project.
2. The corresponding operation code is as follows:
package ;

 import ;
 import ;

 import ;
 import ;
 import ;
 import ;

 public class JavaReadExcel {
 public static void main(String[] args) {    
 try {
 String fileName = "?:\\...\\"; // The path where the Excel file is located
 File file = new File(fileName); // Create a file object
 Workbook wb = (file); // Get Excel workspace object from file stream (WorkBook)
 Sheet sheet = (0); // Get the page from the workspace (Sheet)
            
 for (int i = 0; i < (); i++) { // Loop to print the contents in the Excel table
 for (int j = 0; j < (); j++) {
 Cell cell = (j, i);
 (());
                      }
                      ();
               }
         } catch (BiffException e) {
              ();
         } catch (IOException e) {
              ();
         }
        
     }
 }