/** * Get the contents of the format string, by looking up * the DataFormat against the supplied low level workbook * @see org.apache.poi.hssf.usermodel.HSSFDataFormat */ public String getDataFormatString(org.apache.poi.hssf.model.InternalWorkbook workbook) { HSSFDataFormat format = new HSSFDataFormat( workbook ); return format.getFormat(getDataFormat()); }
/** * Get the contents of the format string, by looking up * the DataFormat against the supplied workbook * @see org.apache.poi.hssf.usermodel.HSSFDataFormat * * @return the format string or "General" if not found */ public String getDataFormatString(org.apache.poi.ss.usermodel.Workbook workbook) { HSSFDataFormat format = new HSSFDataFormat( ((HSSFWorkbook)workbook).getWorkbook() ); int idx = getDataFormat(); return idx == -1 ? "General" : format.getFormat(getDataFormat()); } /**
HSSFDataFormat cf = workbook.createDataFormat(); currencyCellStyle = workbook.createCellStyle(); currencyCellStyle.setDataFormat(cf.getFormat("#,##0.00\\ _€"));
HSSFCellStyle cellStyle = wb.createCellStyle(); HSSFDataFormat hssfDataFormat = wb.createDataFormat(); String cellVal = "2500"; cellStyle.setDataFormat(hssfDataFormat.getFormat("#,##0.000")); newCell.setCellStyle(cellStyle); newCell.setCellValue(new Double(cellVal)); newCell.setCellType(Cell.CELL_TYPE_NUMERIC);
HSSFCellStyle cs = hssfworkbook.createCellStyle(); HSSFDataFormat df = hssfworkbook.createDataFormat(); cs.setDataFormat(df.getFormat("#,##0.0")); //or cs.setDataFormat((short)7); cell.setCellValue(2655.32); cell.setCellStyle(cs);
public void setStyleFormat(int dataType, HSSFCellStyle styleRow, Workbook wb) { HSSFDataFormat df = (HSSFDataFormat) wb.createDataFormat(); switch (dataType) { case Types.DATE: case Types.TIME: case Types.TIMESTAMP: styleRow.setDataFormat(df.getFormat("m/d/yy")); break; case Types.INTEGER: case Types.NUMERIC: case Types.DECIMAL: styleRow.setDataFormat(df.getFormat("0")); break; default: styleRow.setDataFormat(df.getFormat("@")); break; } }
/** * Get the contents of the format string, by looking up * the DataFormat against the supplied low level workbook * @see org.apache.poi.hssf.usermodel.HSSFDataFormat */ public String getDataFormatString(org.apache.poi.hssf.model.InternalWorkbook workbook) { HSSFDataFormat format = new HSSFDataFormat( workbook ); return format.getFormat(getDataFormat()); }
/** * Get the contents of the format string, by looking up * the DataFormat against the supplied low level workbook * @see org.apache.poi.hssf.usermodel.HSSFDataFormat */ public String getDataFormatString(org.apache.poi.hssf.model.InternalWorkbook workbook) { HSSFDataFormat format = new HSSFDataFormat( workbook ); return format.getFormat(getDataFormat()); }
/** * Get the contents of the format string, by looking up * the DataFormat against the supplied low level workbook * @see org.apache.poi.hssf.usermodel.HSSFDataFormat */ public String getDataFormatString(org.apache.poi.hssf.model.InternalWorkbook workbook) { HSSFDataFormat format = new HSSFDataFormat( workbook ); return format.getFormat(getDataFormat()); }
protected static HSSFCellStyle createDateCellStyle(HSSFWorkbook workbook) { HSSFDataFormat format = workbook.createDataFormat(); short dateFormatCode = format.getFormat(DATE_FORMAT_AS_NUMBER_DBUNIT); HSSFCellStyle dateCellStyle = workbook.createCellStyle(); dateCellStyle.setDataFormat(dateFormatCode); return dateCellStyle; }
/** * Get the contents of the format string, by looking up * the DataFormat against the supplied workbook * @see org.apache.poi.hssf.usermodel.HSSFDataFormat * * @return the format string or "General" if not found */ public String getDataFormatString(org.apache.poi.ss.usermodel.Workbook workbook) { HSSFDataFormat format = new HSSFDataFormat( ((HSSFWorkbook)workbook).getWorkbook() ); int idx = getDataFormat(); return idx == -1 ? "General" : format.getFormat(getDataFormat()); } /**
/** * Get the contents of the format string, by looking up * the DataFormat against the supplied workbook * @see org.apache.poi.hssf.usermodel.HSSFDataFormat * * @return the format string or "General" if not found */ public String getDataFormatString(org.apache.poi.ss.usermodel.Workbook workbook) { HSSFDataFormat format = new HSSFDataFormat( ((HSSFWorkbook)workbook).getWorkbook() ); int idx = getDataFormat(); return idx == -1 ? "General" : format.getFormat(getDataFormat()); } /**
/** * Get the contents of the format string, by looking up * the DataFormat against the supplied workbook * @see org.apache.poi.hssf.usermodel.HSSFDataFormat * * @return the format string or "General" if not found */ public String getDataFormatString(org.apache.poi.ss.usermodel.Workbook workbook) { HSSFDataFormat format = new HSSFDataFormat( ((HSSFWorkbook)workbook).getWorkbook() ); int idx = getDataFormat(); return idx == -1 ? "General" : format.getFormat(getDataFormat()); } /**
FileOutputStream out = new FileOutputStream("dateFormat.xls"); HSSFWorkbook hssfworkbook = new HSSFWorkbook(); HSSFSheet sheet = hssfworkbook.createSheet("new sheet"); HSSFCellStyle cs = hssfworkbook.createCellStyle(); HSSFDataFormat df = hssfworkbook.createDataFormat(); cs.setDataFormat(df.getFormat("#,##0.0")); for(int i=0 ;i <100 ; i++ ) { double value = new Random(i).nextGaussian(); HSSFRow row = sheet.createRow((short) i); HSSFCell cell = row.createCell((short) 0); cell.setCellValue(value); if(value>=0 && value<=1) cell.setCellStyle(cs); } hssfworkbook.write(out); out.close();
try{ FileOutputStream out = new FileOutputStream ("dateFormat.xls"); HSSFWorkbook hssfworkbook = new HSSFWorkbook(); HSSFSheet sheet = hssfworkbook.createSheet ("new sheet"); HSSFCellStyle cs = hssfworkbook.createCellStyle(); HSSFDataFormat df = hssfworkbook. createDataFormat(); cs.setDataFormat(df.getFormat("#,##0.0")); HSSFRow row = sheet.createRow((short)0); HSSFCell cell = row.createCell((short)0); cell.setCellValue(11111.1); cell.setCellStyle(cs); hssfworkbook.write(out); out.close(); }catch(Exception e){} }
StylesContainer(HSSFWorkbook workbook, FontsContainer fontsContainer) { regularStyle = workbook.createCellStyle(); regularStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); headerStyle = workbook.createCellStyle(); headerStyle.setFont(fontsContainer.boldFont); headerStyle.setFillPattern(XSSFCellStyle.SOLID_FOREGROUND); headerStyle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); headerStyle.setBorderBottom(XSSFCellStyle.BORDER_MEDIUM); headerStyle.setWrapText(true); timeStyle = workbook.createCellStyle(); timeStyle.setDataFormat(workbook.createDataFormat().getFormat("[HH]:MM:SS")); timeBoldStyle = workbook.createCellStyle(); timeBoldStyle.setDataFormat(workbook.createDataFormat().getFormat("[HH]:MM:SS")); timeBoldStyle.setFont(fontsContainer.boldFont); negativeTimeStyle = workbook.createCellStyle(); negativeTimeStyle.setDataFormat(workbook.createDataFormat().getFormat("-[HH]:MM:SS")); numberStyle = workbook.createCellStyle(); numberStyle.setDataFormat(workbook.createDataFormat().getFormat("0.00###")); numberBoldStyle = workbook.createCellStyle(); numberBoldStyle.setDataFormat(workbook.createDataFormat().getFormat("0.00###")); numberBoldStyle.setFont(fontsContainer.boldFont); dateTimeStyle = workbook.createCellStyle(); dateTimeStyle.setDataFormat(workbook.createDataFormat().getFormat("yyyy-mm-dd hh:mm")); }
private void writeHeaderRow(E bean, HSSFSheet sheet) { HSSFRow headerRow = sheet.createRow(0); for (int i = 0; i < beanProperties.size(); i++) { PropFormat prop = beanProperties.get(i); // write column header String componentName = prop.getName(); headerRow.createCell(i).setCellValue(new HSSFRichTextString(componentName)); // apply pattern if (prop.getPattern() != null) { HSSFDataFormat dataFormat = workbook.createDataFormat(); CellStyle columnStyle = workbook.createCellStyle(); columnStyle.setDataFormat(dataFormat.getFormat(prop.getPattern())); sheet.setDefaultColumnStyle(i, columnStyle); } } }
FileOutputStream out = new FileOutputStream("dateFormat.xls"); HSSFWorkbook hssfworkbook = new HSSFWorkbook(); HSSFSheet sheet = hssfworkbook.createSheet("new sheet"); HSSFCellStyle cs = hssfworkbook.createCellStyle(); HSSFDataFormat df = hssfworkbook.createDataFormat(); HSSFFormulaEvaluator evaluator = new HSSFFormulaEvaluator(hssfworkbook); cs.setDataFormat(df.getFormat("h:mm:ss")); HSSFRow row = sheet.createRow((short)0); HSSFCell cell = row.createCell((short)0); cell.setCellFormula("TIME(0,3,24)");//this method only sets the formula string and does not calculate the formula value cell.setCellType(Cell.CELL_TYPE_FORMULA);//Set the cells type (numeric, formula or string) evaluator.evaluateFormulaCell(cell);// it evaluates the formula, and saves the result of the formula cell.setCellStyle(cs); HSSFRow row2 = sheet.createRow((short)1); HSSFCell cell2 = row2.createCell((short)0); cell2.setCellFormula("TIME(0,9,54)"); cell2.setCellType(Cell.CELL_TYPE_FORMULA); evaluator.evaluateFormulaCell(cell2); cell2.setCellStyle(cs);
public void handle(NumberTextValue textValue) { if (textValue.getPattern() != null) { baseStyle.setDataFormat( dataFormat.getFormat( getConvertedPattern(textValue.getPattern()) ) ); } HSSFCellStyle cellStyle = initCreateCell(gridCell, colIndex, rowIndex, baseStyle); if (textValue.getValue() == null) { cell.setCellType(HSSFCell.CELL_TYPE_BLANK); } else { cell.setCellValue(textValue.getValue().doubleValue()); } endCreateCell(cellStyle); }
public void handle(DateTextValue textValue) { baseStyle.setDataFormat( dataFormat.getFormat( getConvertedPattern(textValue.getPattern()) ) ); HSSFCellStyle cellStyle = initCreateCell(gridCell, colIndex, rowIndex, baseStyle); if (textValue.getValue() == null) { cell.setCellType(HSSFCell.CELL_TYPE_BLANK); } else { cell.setCellValue(textValue.getValue()); } endCreateCell(cellStyle); }