List of usage examples for org.apache.poi.hssf.record CellValueRecordInterface getXFIndex
short getXFIndex();
From source file:XLS2CSVmra.java
License:Apache License
/** * Formats a number or date cell, be that a real number, or the * answer to a formula//from w w w. j a v a2 s.co m */ private String formatNumberDateCell(CellValueRecordInterface cell, double value) { // Get the built in format, if there is one ExtendedFormatRecord xfr = (ExtendedFormatRecord) xfRecords.get(cell.getXFIndex()); if (xfr == null) { System.err.println("Cell " + cell.getRow() + "," + cell.getColumn() + " uses XF with index " + cell.getXFIndex() + ", but we don't have that"); return Double.toString(value); } else { int formatIndex = xfr.getFormatIndex(); String format; if (formatIndex >= HSSFDataFormat.getNumberOfBuiltinBuiltinFormats()) { FormatRecord tfr = (FormatRecord) customFormatRecords.get(new Integer(formatIndex)); format = tfr.getFormatString(); } else { format = HSSFDataFormat.getBuiltinFormat(xfr.getFormatIndex()); } // Is it a date? if (HSSFDateUtil.isADateFormat(formatIndex, format) && HSSFDateUtil.isValidExcelDate(value)) { // Java wants M not m for month format = format.replace('m', 'M'); // Change \- into -, if it's there format = format.replaceAll("\\\\-", "-"); // Format as a date Date d = HSSFDateUtil.getJavaDate(value, false); DateFormat df = new SimpleDateFormat(format); return df.format(d); } else { if (format.toUpperCase().equals("GENERAL")) { // Some sort of wierd default return Double.toString(value); } // Format as a number DecimalFormat df = new DecimalFormat(format); return df.format(value); } } }
From source file:com.adanac.excel.reader.hssf.ExcelFormatTrackingHSSFListener.java
License:Apache License
/** * Returns the index of the format string, used by your cell, or -1 if none * found//from www .j av a 2 s . c o m */ public int getFormatIndex(CellValueRecordInterface cell) { ExtendedFormatRecord xfr = _xfRecords.get(cell.getXFIndex()); if (xfr == null) { logger.log(POILogger.ERROR, "Cell " + cell.getRow() + "," + cell.getColumn() + " uses XF with index " + cell.getXFIndex() + ", but we don't have that"); return -1; } return xfr.getFormatIndex(); }