java读取Excel

    技术2022-07-14  84

    参考自:

    https://blog.csdn.net/ceovip/article/details/82964487?ops_request_misc=%7B%22request%5Fid%22%3A%22159365852719724839247802%22%2C%22scm%22%3A%2220140713.130102334..%22%7D&request_id=159365852719724839247802&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~top_click~default-2-82964487.first_rank_ecpm_v3_pc_rank_v4&utm_term=java读取excel表格  

     

    亲测,OK!  

    import java.io.*;    

    import jxl.*; import jxl.read.biff.BiffException; //import jxl.read.biff.*; public class ReadExcel {         public static void main(String args[]) throws BiffException, IOException         {             String filepath = "D:\\交叉验证平台\\测试报告\\DRU出厂测试报告8.xls";             File xlsFile = new File(filepath);             // 获得工作簿对象             Workbook workbook = Workbook.getWorkbook(xlsFile);             // 获得所有工作表             Sheet[] sheets = workbook.getSheets();             // 遍历工作表             if (sheets != null)              {                 for (Sheet sheet : sheets)                  {                     // 获得行数                     int rows = sheet.getRows();                     // 获得列数                     int cols = sheet.getColumns();                     // 读取数据                     for (int row = 0; row < rows; row++)                   {                         for (int col = 0; col < cols; col++)                          {                                  Cell cell = sheet.getCell(col, row);                      System.out.print(cell.getContents() + " ");                             }                      System.out.println();                   }                 }             }           workbook.close();       } }

     

    如报错:Exception in thread "main" jxl.read.biff.BiffException:unable to recongnize olestream 降低Excel版本即可,具体参考:https://blog.csdn.net/zhaols11/article/details/22191283?ops_request_misc=&request_id=&biz_id=102&utm_term=java读取excel时报错:Exception in th&utm_medium=distribute.pc_search_result.none-task-blog-2~all~sobaiduweb~default-0-22191283

    Processed: 0.019, SQL: 9