标签:pac val generate illegal ring xls get ack class
import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFRow; import org.apache.poi.hssf.usermodel.HSSFCell; import java.io.*; public class FormulaToString { /** * @param args */ public void fileInput() throws IOException { HSSFWorkbook hw = new HSSFWorkbook(new FileInputStream( "d:/My Documents/Desktop/poi.xls")); HSSFSheet hsheet = hw.getSheet("poi test"); HSSFRow hrow = hsheet.getRow(0); HSSFCell hcell = hrow.getCell(0); String cellValue = this.getCellValue(hcell); System.out.println(cellValue); } public String getCellValue(HSSFCell cell) { String value = null; if (cell != null) { switch (cell.getCellType()) { case HSSFCell.CELL_TYPE_FORMULA: // cell.getCellFormula(); try { value = String.valueOf(cell.getNumericCellValue()); } catch (IllegalStateException e) { value = String.valueOf(cell.getRichStringCellValue()); } break; case HSSFCell.CELL_TYPE_NUMERIC: value = String.valueOf(cell.getNumericCellValue()); break; case HSSFCell.CELL_TYPE_STRING: value = String.valueOf(cell.getRichStringCellValue()); break; } } return value; } public static void main(String[] args) { try { // TODO Auto-generated method stub FormulaToString fts = new FormulaToString(); fts.fileInput(); } catch (IOException e) { e.printStackTrace(); } } }
标签:pac val generate illegal ring xls get ack class
原文地址:https://www.cnblogs.com/linxixinxiang/p/11271946.html