[英]Reading data and inputting it into a new Excel file using Java POI
我目前正在尝试在Java中读取Excel文件,对其进行修改,然后将其放入新的Excel文件中。 即时消息只是试图将读取的数据直接放入新文件中。 我的问题是如何从cell.getContents()获取内容到新文件中
如果(!f.exists()){
String FileName = "C:\\Users\\alexp\\Desktop\\New_Export.xls";
WritableWorkbook excel = Workbook.createWorkbook(new File(FileName));
WritableSheet sheet = excel.createSheet("Sheet1", 0);
for (int y = 0; y < page.getRows(); y++){
for (int x = 0; x < page.getColumns(); x++){
Cell cell = page.getCell(x ,y +1);
CellType type = cell.getType();
if(type == CellType.LABEL){
System.out.println(cell.getContents());
Label label1 = new Label();
sheet.addCell(label1);
if(type == CellType.NUMBER){
System.out.println(cell.getContents());
Number num1 = new Number ();
sheet.addCell(num1);
}
}
}
System.out.println(" ");
}
System.out.println("The File Has Successfully Been Created!");
excel.write();
excel.close();
}
else{
System.out.println("File is already created!");
}
您可以使用apache poi读取Excel工作表的每一行,如下所示:
HssfRow row = sheet.getRow(rowIndex);
HssfCell cell = row.getCell(columnIndex);
FormulaEvaluator fe = workbook.getCreationHelper().createFormulaEvalator();
CellValue cv = fe.evaluate(cell);
希望这对您有帮助,我已经从移动设备上键入了此代码,您可能会遇到一些语法错误,使它们可以正常工作。 祝你今天愉快:-)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.