public void writeSetup() { workbook = new XSSFWorkbook(); creationHelper = workbook.getCreationHelper(); createStyles(); }
protected AbstractCellRangeDataSource(XSSFSheet sheet, CellRangeAddress cellRangeAddress) { this.sheet = sheet; // Make copy since CellRangeAddress is mutable. this.cellRangeAddress = cellRangeAddress.copy(); this.numOfCells = this.cellRangeAddress.getNumberOfCells(); this.evaluator = sheet.getWorkbook().getCreationHelper().createFormulaEvaluator(); }
@Override public Workbook write() { workbook = new XSSFWorkbook(); creationHelper = workbook.getCreationHelper(); createStyles(); writeConfiguration(); writeDays(); writeRooms(); writePersons(); writeMeetings(); writeRoomsView(); writePersonsView(); writePrintedFormView(); writeScoreView(justificationList -> justificationList.stream() .filter(o -> o instanceof MeetingAssignment).map(o -> ((MeetingAssignment) o).toString()) .collect(joining(", "))); return workbook; }
@Override public void applyStyleAndValue(int dbColNum, ResultSet resultSet, Cell cell) throws SQLException { if (links < MAX_HYPERLINKS) { Hyperlink hyperlink = workbook.getCreationHelper().createHyperlink(linkType); String path = resultSet.getString(dbColNum); String address = urlBase+path; hyperlink.setAddress(address); cell.setHyperlink(hyperlink); cell.setCellStyle(style); String fName = Paths.get(path).getFileName().toString(); cell.setCellValue(fName); links++; } else { //silently stop adding hyperlinks } } }
import org.apache.poi.xssf.usermodel.*; //import needed XSSFWorkbook wb = new XSSFWorkbook (); // Create workbook XSSFSheet sheet = wb.createSheet(); // Create spreadsheet in workbook XSSFRow row = sheet.createRow(rowIndex); // Create the row in the spreadsheet //1. Create the date cell style XSSFCreationHelper createHelper = wb.getCreationHelper(); XSSFCellStyle cellStyle = wb.createCellStyle(); cellStyle.setDataFormat( createHelper.createDataFormat().getFormat("MMMM dd, yyyy")); //2. Apply the Date cell style to a cell //This example sets the first cell in the row using the date cell style cell = row.createCell(0); cell.setCellValue(new Date()); cell.setCellStyle(cellStyle);
@Override public void reset(XSSFWorkbook workbook) { style = workbook.createCellStyle(); style.setDataFormat(workbook.getCreationHelper() .createDataFormat().getFormat(formatString)); }
/** * Returns an object that handles instantiating concrete * classes of the various instances one needs for HSSF and XSSF. */ public CreationHelper getCreationHelper() { return _wb.getCreationHelper(); }
public void writeSetup() { workbook = new XSSFWorkbook(); creationHelper = workbook.getCreationHelper(); createStyles(); }
XSSFWorkbook wb = new XSSFWorkbook(); XSSFSheet sheet = wb.createSheet("test"); Row row = sheet.createRow(0); Cell inCell = row.createCell(0); inCell.setCellValue("01.0234500"); Cell outCell = row.createCell(1); FormulaEvaluator fev = wb.getCreationHelper().createFormulaEvaluator(); String value = inCell.getStringCellValue(); outCell.setCellFormula("VALUE(" + value + ")"); fev.evaluateInCell(outCell);
protected AbstractCellRangeDataSource(XSSFSheet sheet, CellRangeAddress cellRangeAddress) { this.sheet = sheet; // Make copy since CellRangeAddress is mutable. this.cellRangeAddress = cellRangeAddress.copy(); this.numOfCells = this.cellRangeAddress.getNumberOfCells(); this.evaluator = sheet.getWorkbook().getCreationHelper().createFormulaEvaluator(); }
public void setStyle(String name, String format) { getStyle(name).setDataFormat(workbook.getCreationHelper().createDataFormat().getFormat(format)); }
@Override public void setWritableCell(TableModel tableModel, XSSFCell cell, Object value, int row, int col) { XSSFWorkbook wb = cell.getSheet().getWorkbook(); cell.setCellStyle(cellStyle); cell.setCellValue(wb.getCreationHelper().createRichTextString(value.toString())); cell.setCellType(XSSFCell.CELL_TYPE_STRING); } }
//creating the cell Row row = my_sheet.createRow(0); Cell cell = row.createCell(0); //creating helper class XSSFWorkbook workbook = new XSSFWorkbook(); XSSFCreationHelper helper= workbook.getCreationHelper(); //creating the hyperlink link = helper.createHyperlink(HSSFHyperlink.LINK_DOCUMENT); link.setAddress("'target_worksheet_name'!A1"); //optional hyperlink style XSSFCellStyle hlinkstyle = workbook.createCellStyle(); XSSFFont hlinkfont = workbook.createFont(); hlinkfont.setUnderline(XSSFFont.U_SINGLE); hlinkfont.setColor(HSSFColor.BLUE.index); hlinkstyle.setFont(hlinkfont); //applying the hyperlink to the cell cell.setHyperlink(link);
@Override public void transform(XSSFCellStyle cellStyle) { XSSFDataFormat format = sheet.getWorkbook().getCreationHelper().createDataFormat(); cellStyle.setAlignment(alignment.excelAlignment(timestamp, cellStyle)); cellStyle.setDataFormat(format.getFormat(formatProvider.getExcelDateTimeFormat(locale.getCountry()))); } }
@Override public void transform(XSSFCellStyle cellStyle) { XSSFDataFormat format = sheet.getWorkbook().getCreationHelper().createDataFormat(); cellStyle.setAlignment(alignment.excelAlignment(date, cellStyle)); cellStyle.setDataFormat(format.getFormat(formatProvider.getExcelDateFormat(locale.getCountry()))); } }
@Override public void setWritableCell(TableModel tableModel, XSSFCell cell, Object value, int row, int col) { String string = getString((LocalTime) value); XSSFWorkbook wb = cell.getSheet().getWorkbook(); cell.setCellStyle(cellStyle); cell.setCellType(XSSFCell.CELL_TYPE_STRING); if (string != null) { cell.setCellValue(wb.getCreationHelper().createRichTextString(string)); } }
@Override public void setWritableCell(TableModel tableModel, XSSFCell cell, Object value, int row, int col) { XSSFWorkbook wb = cell.getSheet().getWorkbook(); cell.setCellStyle(cellStyle); cell.setCellValue(wb.getCreationHelper().createRichTextString(getString(tableModel, value, row, col))); cell.setCellType(XSSFCell.CELL_TYPE_STRING); }
@Override public void transform(XSSFCellStyle cellStyle) { XSSFDataFormat format = sheet.getWorkbook().getCreationHelper().createDataFormat(); cellStyle.setAlignment(alignment.excelAlignment(money, cellStyle)); cellStyle.setDataFormat(format.getFormat(getExcelCurrencyFormat(money.getCurrencyCd()))); } }
public static void hyperlinkScreenshot(XSSFCell cell, String FileAddress){ XSSFWorkbook wb=cell.getRow().getSheet().getWorkbook(); CreationHelper createHelper = wb.getCreationHelper(); CellStyle hlink_style = wb.createCellStyle(); Font hlink_font = wb.createFont(); hlink_font.setUnderline(Font.U_SINGLE); hlink_font.setColor(IndexedColors.BLUE.getIndex()); hlink_style.setFont(hlink_font); Hyperlink hp = createHelper.createHyperlink(Hyperlink.LINK_FILE); FileAddress=FileAddress.replace("\\", "/"); hp.setAddress(FileAddress); cell.setHyperlink(hp); cell.setCellStyle(hlink_style); }
/** * Creates a cell and aligns it a certain way. * * @param wb the workbook * @param row the row to create the cell in * @param column the column number to create the cell in * @param halign the horizontal alignment for the cell. */ private static void createCell(XSSFWorkbook wb, XSSFRow row, int column, HorizontalAlignment halign, VerticalAlignment valign) { CreationHelper ch = wb.getCreationHelper(); XSSFCell cell = row.createCell(column); cell.setCellValue(ch.createRichTextString("Align It")); CellStyle cellStyle = wb.createCellStyle(); cellStyle.setAlignment(halign); cellStyle.setVerticalAlignment(valign); cell.setCellStyle(cellStyle); }