List of usage examples for org.apache.poi.xssf.usermodel XSSFCell getStringCellValue
@Override
public String getStringCellValue()
For numeric cells we throw an exception.
From source file:edu.vt.vbi.patric.common.ExcelHelper.java
License:Apache License
/** * Returns the width the Column should be (XSSF version) * @param sheet - sheet of workbook/* www . jav a2 s . com*/ * @param col - the column to work with * @return length (in characters) of that column */ private int decideXColumnWidth(XSSFSheet sheet, int col) { int titleLength = sheet.getRow(0).getCell(col).getStringCellValue().length(); int longestString = titleLength; for (int i = 0; i < sheet.getLastRowNum(); i++) { XSSFRow row = sheet.getRow(i); XSSFCell cell = row.getCell(col); int temp = cell.getStringCellValue().length(); if (temp > titleLength * 2) { longestString = temp; } } if (longestString > titleLength * 4) { longestString = titleLength * 4; } return longestString; }
From source file:entities.HangNhap.java
public HangNhap(XSSFCell maHangHoa, XSSFCell tenHangHoa, XSSFCell giaMua, XSSFCell soLuong, XSSFCell nhomHangHoa) {/*from ww w . j av a 2s . c o m*/ this.mMaHangHoa = maHangHoa.getStringCellValue(); this.mTenHangHoa = tenHangHoa.getStringCellValue(); this.mGiaMua = (int) giaMua.getNumericCellValue(); this.mSoLuong = (int) soLuong.getNumericCellValue(); this.mNhomHangHoa = nhomHangHoa.getStringCellValue(); }
From source file:foodbankyfs.FbMainFx.java
private List<String[]> saveSpreadsheetData() { // Copy spreadsheet contents into memory try {//from w w w . jav a2 s . c o m // Initialize xls reading objects FileInputStream fileInputStream = new FileInputStream(spreadsheet); XSSFWorkbook workbook = new XSSFWorkbook(fileInputStream); XSSFSheet worksheet = workbook.getSheet(FbConstants.SHEET_NAME); FormulaEvaluator evaluator = workbook.getCreationHelper().createFormulaEvaluator(); List<String[]> tmpData = new ArrayList(); // Save XSSF objects for rewrite wrksheet = worksheet; wrkbook = workbook; // Iterate through all rows in the sheet for (int rowNum = FbConstants.DATA_ROW_START_INDEX; rowNum < worksheet.getLastRowNum(); rowNum++) { // Initialize array that will store cell contents String values[] = new String[FbConstants.NUMBER_OF_COLUMNS]; XSSFRow row = worksheet.getRow(rowNum); // Iterate through cells in each row and store values to an array for (int cellNum = 0; cellNum < FbConstants.NUMBER_OF_COLUMNS; cellNum++) { XSSFCell cell = row.getCell(cellNum, Row.CREATE_NULL_AS_BLANK); String value = ""; if (cell != null) { if (cell.getCellType() == XSSFCell.CELL_TYPE_FORMULA) { evaluator.evaluateInCell(cell); } // If cell type is numeric convert the number value to a string if (cell.getCellType() == XSSFCell.CELL_TYPE_NUMERIC) { double tmpVal = cell.getNumericCellValue(); value = String.format("%.0f", tmpVal); } if (cell.getCellType() == XSSFCell.CELL_TYPE_STRING) { value = cell.getStringCellValue().toLowerCase(); } } // If a cell row has an empty ID do not include it in data if (cellNum == 0 && value.equals("")) { break; } // Initialize value to 0 if cell is empty if (value.isEmpty()) { // If value is from email or notes field then put empty instead if (cellNum == FbConstants.EMAIL_FIELD || cellNum == FbConstants.NOTES_FIELD) { value = "empty"; } else { value = "0"; } } // Store value in array values[cellNum] = value; } // Store array of values in list tmpData.add(values); } return tmpData; } catch (IOException e) { System.err.println(e); } return null; }
From source file:fr.unice.i3s.rockflows.experiments.automatictest.ExcelUtils.java
/** * Checks if the value of a given {@link XSSFCell} is empty. * * @param cell/* w w w. jav a 2s .c om*/ * The {@link XSSFCell}. * @return {@code true} if the {@link XSSFCell} is empty. {@code false} * otherwise. */ public static boolean isCellEmpty(final XSSFCell cell) { if (cell == null || cell.getCellType() == Cell.CELL_TYPE_BLANK) { return true; } if (cell.getCellType() == Cell.CELL_TYPE_STRING && cell.getStringCellValue().isEmpty()) { return true; } return false; }
From source file:fr.unice.i3s.rockflows.experiments.automatictest.ExcelUtils.java
public static String getStringValue(final XSSFCell cell) { if (cell.getCellType() == Cell.CELL_TYPE_STRING) { return cell.getStringCellValue(); }/*from w w w. ja v a2s . c o m*/ return cell.getRawValue(); }
From source file:Import.ImportData.java
protected BigDecimal getBigDecimalCellValue(XSSFCell cell) throws NullPointerException { try {/*from w w w . ja va 2 s . c o m*/ switch (cell.getCellType()) { case XSSFCell.CELL_TYPE_NUMERIC: { return new BigDecimal(cell.getNumericCellValue()); } case XSSFCell.CELL_TYPE_STRING: { String stringDouble = cell.getStringCellValue(); return new BigDecimal(stringDouble); } default: throw new NullPointerException(); } } catch (NumberFormatException e) { throw new NullPointerException(); } }
From source file:Import.ImportData.java
protected Date getDateCellValue(XSSFCell cell) throws NullPointerException { switch (cell.getCellType()) { case XSSFCell.CELL_TYPE_NUMERIC: { return cell.getDateCellValue(); }/*from w w w.jav a 2 s. c o m*/ case XSSFCell.CELL_TYPE_STRING: { String stringDate = cell.getStringCellValue(); return stringToDate(stringDate); } default: throw new NullPointerException(); } }
From source file:Import.ImportData.java
protected Object getCellValue(XSSFCell cell) throws NullPointerException { switch (cell.getCellType()) { case XSSFCell.CELL_TYPE_NUMERIC: { return cell.getNumericCellValue(); }// ww w.j a va 2 s . c o m case XSSFCell.CELL_TYPE_STRING: { String value = cell.getStringCellValue(); if ("".equals(value)) throw new NullPointerException(); return value; } default: throw new NullPointerException(); } }
From source file:Import.ImportData.java
protected String getStringCellValue(XSSFCell cell) throws NullPointerException { switch (cell.getCellType()) { case XSSFCell.CELL_TYPE_NUMERIC: { DecimalFormat f = new DecimalFormat("##");//"##"); return f.format(cell.getNumericCellValue()); }//from w w w. jav a 2 s . c o m case XSSFCell.CELL_TYPE_STRING: { String value = cell.getStringCellValue(); if ("".equals(value)) throw new NullPointerException(); return value; } default: throw new NullPointerException(); } }
From source file:in.expertsoftware.colorcheck.Financial_Standard_WorkingSection_count.java
public ArrayList<String> working_Section(int SOFWDLocation, int EOFWDLocation, XSSFWorkbook workbook) { ArrayList<String> workingSection = new ArrayList<String>(); XSSFRow row;//from www . j a va 2s. com XSSFCell cell; XSSFSheet Sheet = workbook.getSheet("Financial_Standard"); String genrateFormula; for (int start = (SOFWDLocation - 1); start < EOFWDLocation; start++) { try { row = Sheet.getRow(start); cell = row.getCell(2); if (!(cell.getStringCellValue().equals("Common Financial Ratios Reviewed by Lenders"))) { switch (cell.getCellType()) { case Cell.CELL_TYPE_STRING: genrateFormula = "Financial_Standard!C" + (row.getRowNum() + 1); workingSection.add(genrateFormula); break; case Cell.CELL_TYPE_BLANK: break; default: System.out.println("Error"); break; } } } catch (Exception e) { System.out.println(e.getMessage()); e.printStackTrace(); } } return workingSection; }