导入Excel文件数据

 /**

 * 导入Excel文件数据    

 * @param file 将要导入的Excel文件

 * @param fileCheckKeyWord 用于判断导入文件是否正确的关键字符串 

 * @param keyX 用于判断导入文件是否正确的关键字符串所在的x坐标位置

 * @param keyY 用于判断导入文件是否正确的关键字符串所在的y坐标位置

 * @param startRow 导入数据开始行数

 * @param startLine 导入数据开始列数     

 * @return List《Object[]》

 * @throws Exception */

public static ListexcelImport(File file, String fileCheckKeyWord, int keyX, int keyY, int startRow, int startLine) throws Exception

{  

   ListdataList = new ArrayList();

   InputStream inputStream = new FileInputStream(file);

   WorkbookSettings wbs = new WorkbookSettings();

   wbs.setSuppressWarnings(true);

   Workbook book = Workbook.getWorkbook(inputStream, wbs);

   Sheet sh = book.getSheet(0); //判断选择excel文件是否正确

   String typeContent = sh.getCell(keyX, keyY).getContents().trim(); 

   if(!typeContent.equals(fileCheckKeyWord)){ return dataList; } //行数 int rows = sh.getRows();

   if(rows >= 65536){//超出 excel 03最大行数 return dataList; } //列数

   int lines = sh.getColumns(); //判断导入的数据是否有误

   Object[] dataObjArr = null; 

   for(int i = startRow; i <= rows; i++){ dataObjArr = new Object[lines - startLine + 1];

           for(int j = startLine; j <= lines; j++){ String content = sh.getCell(j, i).getContents().trim(); 

              if(ComFun.strNull(content) && !content.trim().equals(""))

              { dataObjArr[j - startLine] = content; }

              else { dataObjArr[j - startLine] = ""; }

           }

       }       

       return dataList;

 }

猜你喜欢

转载自blog.csdn.net/xywnrf/article/details/81118595
今日推荐