标签:http color java 使用 io 文件 for ar
这里使用apache的poi进行读取excel
1,新建javaproject 项目:TestExcel
2,导入包
包下载地址:http://poi.apache.org/download.html#POI-3.10-FINAL
百度网盘下载:http://pan.baidu.com/s/1i365mQT
导入根目录下、lib、ooxml-lib下的所有jar
4,操作读取excel
import java.io.File; import java.io.IOException; import java.util.Iterator; import org.apache.poi.openxml4j.exceptions.InvalidFormatException; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.ss.usermodel.WorkbookFactory; public class Test { // 得到一个File public static void main(String[] args) { File file = new File("F:/color.xlsx"); Workbook workbook = null; try { workbook = WorkbookFactory.create(file); } catch (InvalidFormatException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } Sheet sheet = workbook.getSheetAt(0); Iterator<Row> rows = sheet.rowIterator(); int count = 0; while (rows.hasNext()) { count++; Row row = rows.next(); // 如果不是String类型统一设置为String if (row.getCell(2).getCellType() == 0 || row.getCell(2).getCellType() == 2 || row.getCell(2).getCellType() == 3 || row.getCell(2).getCellType() == 4) { row.getCell(2).setCellType(1); } System.out.println(row.getCell(2).getStringCellValue()); } } }
源代码和测试文件:
http://pan.baidu.com/s/1c0nIBiK
Java中读取Excel功能实现_POI,布布扣,bubuko.com
标签:http color java 使用 io 文件 for ar
原文地址:http://blog.csdn.net/jerome_s/article/details/38330615