package ; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.util.Iterator; import org.apache.poi.POITextExtractor; import org.apache.poi.extractor.ExtractorFactory; import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermodel.HSSFRow; import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.openxml4j.exceptions.InvalidFormatException; import org.apache.poi.openxml4j.exceptions.OpenXML4JException; import org.apache.poi.poifs.filesystem.POIFSFileSystem; import org.apache.poi.xssf.usermodel.XSSFRow; import org.apache.poi.xssf.usermodel.XSSFSheet; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.apache.xmlbeans.XmlException; public class Test { /** * 读取office 2003 xls * @param filePath */ @SuppressWarnings({ "unchecked", "deprecation" }) public void loadXls(String filePath){ try { InputStream input = new FileInputStream("F:\\eclipsework\\.metadata\\.plugins\\org.eclipse.wst.server.core\\tmp0\\wtpwebapps\\mapbar-fieldwork\\jsp\\customervisit\\excelupload\\2.xls"); POIFSFileSystem fs = new POIFSFileSystem(input); HSSFWorkbook wb = new HSSFWorkbook(fs); HSSFSheet sheet = wb.getSheetAt(0); // Iterate over each row in the sheet Iterator rows = sheet.rowIterator(); while (rows.hasNext()) { HSSFRow row = (HSSFRow) rows.next(); System.out.println("Row #" + row.getRowNum()); // Iterate over each cell in the row and print out the cell"s // content Iterator cells = row.cellIterator(); while (cells.hasNext()) { HSSFCell cell = (HSSFCell) cells.next(); System.out.println("Cell #" + cell.getCellNum()); switch (cell.getCellType()) { case HSSFCell.CELL_TYPE_NUMERIC: System.out.println(cell.getNumericCellValue()); break; case HSSFCell.CELL_TYPE_STRING: System.out.println(cell.getStringCellValue()); break; case HSSFCell.CELL_TYPE_BOOLEAN: System.out.println(cell.getBooleanCellValue()); break; case HSSFCell.CELL_TYPE_FORMULA: System.out.println(cell.getCellFormula()); break; default: System.out.println("unsuported sell type"); break; } } } } catch (IOException ex) { ex.printStackTrace(); } } /** * 读取xlsx文本 * @param filePath */ public void loadXlsxText(String filePath){ File inputFile = new File("D://test.xlsx"); try { POITextExtractor extractor = ExtractorFactory.createExtractor(inputFile); System.out.println(extractor.getText()); } catch (InvalidFormatException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (OpenXML4JException e) { e.printStackTrace(); } catch (XmlException e) { e.printStackTrace(); } } /** * 读取office 2007 xlsx * @param filePath */ public void loadXlsx(String filePath){ // 构造 XSSFWorkbook 对象,strPath 传入文件路径 XSSFWorkbook xwb = null; try { xwb = new XSSFWorkbook("F:\\eclipsework\\.metadata\\.plugins\\org.eclipse.wst.server.core\\tmp0\\wtpwebapps\\mapbar-fieldwork\\jsp\\customervisit\\excelupload\\2.xls"); } catch (IOException e) { System.out.println("读取文件出错"); e.printStackTrace(); } // 读取第一章表格内容 XSSFSheet sheet = xwb.getSheetAt(0); xwb.getSheetAt(1); // 定义 row、cell XSSFRow row; String cell; // 循环输出表格中的内容 for (int i = sheet.getFirstRowNum(); i < sheet.getPhysicalNumberOfRows(); i++) { row = sheet.getRow(i); for (int j = row.getFirstCellNum(); j < row.getPhysicalNumberOfCells(); j++) { // 通过 row.getCell(j).toString() 获取单元格内容, cell = row.getCell(j).toString(); System.out.print(cell + "/t"); } System.out.println(""); } } public static void main(String[] args) { Test readExcel =new Test(); //readExcel.loadXlsx(""); readExcel.loadXls(""); } }
相关推荐
QtXlsx第三方库操作Excel文件---对excel文件进行读取,修改,刷新,删除等操作
c# 利用npoi 第三方类库写 excel 文件,避免 微软办公软件的尴尬。。
要在Python中读取Excel数据,您可以使用第三方库如 openpyxl 或 pandas。以上是使用这两个库的示例:示例假设您已经有一个名为 example.xlsx 的 Excel 文件,其中包含了要读取的数据。您可以根据实际情况修改文件名...
不是采用第三方控件NPOI读取加密的Excel文件。 开始研究NPOI读取加密的Excel文件,没有研究出来,后来才改用Microsoft.Office.Interop.Excel读取加密的Excle文件。若有那位大牛研究出NPOI读取加密的Excel文件,希望...
java读取Excel的poi以及第三方jar包3.8
* 第三行 为 字段名字 * 第四行 为 前端字段类型 (我是后端我不用,所以不解析,) * 第五行 为 后端 字段类型,int string float * 从第6行开始 就为具体的数值, * json 格式为 每横行 一个jsonobject ,...
转载:delphi7如何读取excel文件 用ole可以解决 用delphi提供 servers选项 第三方的表格控件可以直接读取excel的数据
自己写的一个读取excel的例子
读取Excel为DataTable的三种方式:1、传统方式;2、使用第三方插件NPOI读取;3、使用使用OpenXml读取
xamarin/android 导出excel第三方dll文件,poi文件重新打包
实现mac/ios通过第三方开源库读取excel文件数据
1. Java通过第三方控件POI操作Excel,读取的数据存储在ArrayCollection中。POI3.7 下载地址 2. 通过Blazeds将ArrayList发送到Flex中的ArrayCollection中。(Blazeds构建过程不在本篇讨论范围,见flex4+blazeds+java...
主要介绍了Python中使用第三方库xlrd来读取Excel示例,本文讲解了安装xlrd、xlrd的API、使用xlrd读取Excel代码示例,需要的朋友可以参考下
.net 读取excel文件类 .
方便快速读写excel,里面写了两个接口,有待继续完善。
C#读取excel的第三方库,支持excel97-excel2003,excel2007,不需要安装miscrosoft excel
C#读取excel的第三方库,支持excel97-excel2003,excel2007,不需要安装miscrosoft excel 附带源码工程,可自由修改
实现文件上传并读取EXCEL表格中的数据
专门用于测试的资源,Python用pdfplumber第三方库读取pdf文件写入到Excel表中 定期会分布一些优质文章,希望大家多多关注,一键三连 博客地址:https://tianlingqun.blog.csdn.net/