List of usage examples for org.apache.poi.ss.usermodel PrintSetup A4_PAPERSIZE
short A4_PAPERSIZE
To view the source code for org.apache.poi.ss.usermodel PrintSetup A4_PAPERSIZE.
Click Source Link
From source file:com.crm.webapp.util.ExcelCustomExporter.java
License:Apache License
@Override public void export(ActionEvent event, String tableId, FacesContext context, String filename, String tableTitle, boolean pageOnly, boolean selectionOnly, String encodingType, MethodExpression preProcessor, MethodExpression postProcessor, boolean subTable) throws IOException { wb = new XSSFWorkbook(); String safeName = WorkbookUtil.createSafeSheetName(filename); Sheet sheet = wb.createSheet(safeName); cellStyle = wb.createCellStyle();/*from w ww .j av a2s.com*/ facetStyle = wb.createCellStyle(); titleStyle = wb.createCellStyle(); createCustomFonts(); int maxColumns = 0; StringTokenizer st = new StringTokenizer(tableId, ","); while (st.hasMoreElements()) { String tableName = (String) st.nextElement(); UIComponent component = SearchExpressionFacade.resolveComponent(context, event.getComponent(), tableName); if (component == null) { throw new FacesException("Cannot find component \"" + tableName + "\" in view."); } if (!(component instanceof DataTable || component instanceof DataList)) { throw new FacesException("Unsupported datasource target:\"" + component.getClass().getName() + "\", exporter must target a PrimeFaces DataTable/DataList."); } DataList list = null; DataTable table = null; int cols = 0; if (preProcessor != null) { preProcessor.invoke(context.getELContext(), new Object[] { wb }); } if (tableTitle != null && !tableTitle.isEmpty() && !tableId.contains("" + ",")) { Row titleRow = sheet.createRow(sheet.getLastRowNum()); int cellIndex = titleRow.getLastCellNum() == -1 ? 0 : titleRow.getLastCellNum(); Cell cell = titleRow.createCell(cellIndex); cell.setCellValue(new XSSFRichTextString(tableTitle)); Font titleFont = wb.createFont(); titleFont.setBoldweight(Font.BOLDWEIGHT_BOLD); titleStyle.setFont(titleFont); cell.setCellStyle(titleStyle); sheet.createRow(sheet.getLastRowNum() + 3); } if (component instanceof DataList) { list = (DataList) component; if (list.getHeader() != null) { tableFacet(context, sheet, list, "header"); } if (pageOnly) { exportPageOnly(context, list, sheet); } else { exportAll(context, list, sheet); } cols = list.getRowCount(); } else { table = (DataTable) component; int columnsCount = getColumnsCount(table); if (table.getHeader() != null && !subTable) { tableFacet(context, sheet, table, columnsCount, "header"); } if (!subTable) { tableColumnGroup(sheet, table, "header"); } addColumnFacets(table, sheet, ColumnType.HEADER); if (pageOnly) { exportPageOnly(context, table, sheet); } else if (selectionOnly) { exportSelectionOnly(context, table, sheet); } else { exportAll(context, table, sheet, subTable); } if (table.hasFooterColumn() && !subTable) { addColumnFacets(table, sheet, ColumnType.FOOTER); } if (!subTable) { tableColumnGroup(sheet, table, "footer"); } table.setRowIndex(-1); if (postProcessor != null) { postProcessor.invoke(context.getELContext(), new Object[] { wb }); } cols = table.getColumnsCount(); if (maxColumns < cols) { maxColumns = cols; } } sheet.createRow(sheet.getLastRowNum() + Integer.parseInt(datasetPadding)); } if (!subTable) for (int i = 0; i < maxColumns; i++) { sheet.autoSizeColumn((short) i); } PrintSetup printSetup = sheet.getPrintSetup(); printSetup.setLandscape(true); printSetup.setPaperSize(PrintSetup.A4_PAPERSIZE); sheet.setPrintGridlines(true); writeExcelToResponse(context.getExternalContext(), wb, filename); }
From source file:io.vertigo.dynamo.plugins.export.xls.XLSExporter.java
License:Apache License
/** * Ralise l'export des donnes de contenu et de la ligne d'en-tte. * * @param parameters Paramtre de cet export * @param workbook Document excel// www . ja v a2 s . co m * @param sheet Feuille Excel * @param forceLandscape Indique si le parametrage force un affichage en paysage */ private void exportData(final ExportSheet parameters, final HSSFWorkbook workbook, final HSSFSheet sheet, final boolean forceLandscape) { initHssfStyle(workbook); // Column width final Map<Integer, Double> maxWidthPerColumn = new HashMap<>(); if (parameters.hasDtObject()) { exportObject(parameters, workbook, sheet, maxWidthPerColumn); } else { exportList(parameters, workbook, sheet, maxWidthPerColumn); } // On definit la largeur des colonnes: double totalWidth = 0; int cellIndex; for (final Map.Entry<Integer, Double> entry : maxWidthPerColumn.entrySet()) { cellIndex = entry.getKey(); final Double maxLength = entry.getValue(); final double usesMaxLength = Math.min(maxLength.doubleValue(), MAX_COLUMN_WIDTH); sheet.setColumnWidth(cellIndex, Double.valueOf(usesMaxLength * 256).intValue()); totalWidth += usesMaxLength; } /** * @todo ne serait-il pas plus simple d'utilisersheet.autoSizeColumn(i); de poi 3.0.1 ? */ // note: il ne semble pas simple de mettre title et author dans les // proprits du document final String title = parameters.getTitle(); if (title != null) { final HSSFHeader header = sheet.getHeader(); header.setLeft(title); } sheet.setHorizontallyCenter(true); sheet.getPrintSetup().setPaperSize(PrintSetup.A4_PAPERSIZE); if (forceLandscape || totalWidth > 85) { sheet.getPrintSetup().setLandscape(true); } // On dfinit le footer final HSSFFooter footer = sheet.getFooter(); footer.setRight("Page " + HeaderFooter.page() + " / " + HeaderFooter.numPages()); }
From source file:io.vertigo.quarto.plugins.export.xls.XLSExporter.java
License:Apache License
/** * Ralise l'export des donnes de contenu et de la ligne d'en-tte. * * @param parameters Paramtre de cet export * @param workbook Document excel/*from w ww. j ava2 s .c om*/ * @param sheet Feuille Excel * @param forceLandscape Indique si le parametrage force un affichage en paysage */ private void exportData(final ExportSheet parameters, final HSSFWorkbook workbook, final HSSFSheet sheet, final boolean forceLandscape) { // Column width final Map<Integer, Double> maxWidthPerColumn = new HashMap<>(); if (parameters.hasDtObject()) { exportObject(parameters, workbook, sheet, maxWidthPerColumn); } else { exportList(parameters, workbook, sheet, maxWidthPerColumn); } // On definit la largeur des colonnes: double totalWidth = 0; int cellIndex; for (final Map.Entry<Integer, Double> entry : maxWidthPerColumn.entrySet()) { cellIndex = entry.getKey(); final Double maxLength = entry.getValue(); final int usesMaxLength = Double.valueOf(Math.min(maxLength.doubleValue(), MAX_COLUMN_WIDTH)) .intValue(); sheet.setColumnWidth(cellIndex, usesMaxLength * 256); totalWidth += usesMaxLength; } /** * @todo ne serait-il pas plus simple d'utilisersheet.autoSizeColumn(i); de poi 3.0.1 ? */ // note: il ne semble pas simple de mettre title et author dans les proprits du document final String title = parameters.getTitle(); if (title != null) { final HSSFHeader header = sheet.getHeader(); header.setLeft(title); } sheet.setHorizontallyCenter(true); sheet.getPrintSetup().setPaperSize(PrintSetup.A4_PAPERSIZE); if (forceLandscape || totalWidth > 85) { sheet.getPrintSetup().setLandscape(true); } // On dfinit le footer final HSSFFooter footer = sheet.getFooter(); footer.setRight("Page " + HeaderFooter.page() + " / " + HeaderFooter.numPages()); }
From source file:jdbreport.model.io.xls.poi.Excel2003Writer.java
License:Apache License
private short convertPaperSize(PaperSize paperSize) { if (paperSize == PaperSize.Letter) { return PrintSetup.LETTER_PAPERSIZE; }/*from w w w. jav a 2 s .co m*/ if (paperSize == PaperSize.A4) { return PrintSetup.A4_PAPERSIZE; } if (paperSize == PaperSize.A5) { return PrintSetup.A5_PAPERSIZE; } return 0; }
From source file:net.algem.planning.day.DayScheduleCtrl.java
License:Open Source License
@Override public void actionPerformed(ActionEvent evt) { Object src = evt.getSource(); String cmd = evt.getActionCommand(); if (src instanceof DateDayBar) { Date d = ((DateDayBar) evt.getSource()).getDate(); load(d);//from ww w. j a v a2s . co m //((DayScheduleView) view).stateChanged(new ChangeEvent(cal)); desktop.postEvent(new SelectDateEvent(this, d)); } else if (src instanceof DateFrField) { Date d = ((DateFrField) evt.getSource()).getDate(); load(d); //((DayScheduleView) view).stateChanged(new ChangeEvent(cal)); desktop.postEvent(new SelectDateEvent(this, d)); } else if ("Click".equals(cmd)) { ScheduleView v = (ScheduleView) evt.getSource(); Schedule p = v.getSchedule(); ScheduleDetailEvent pde = new ScheduleDetailEvent(this, p); Point pos = v.getClickPosition(); pos.translate(60, 0); // deplacement vers la droite pde.setPosition(pos); pde.setRanges(v.getScheduleRanges()); desktop.postEvent(pde); } else if (BundleUtil.getLabel("Action.today.label").equals(cmd)) { Date d = new Date(); load(d); //((DayScheduleView) view).stateChanged(new ChangeEvent(cal)); desktop.postEvent(new SelectDateEvent(this, d)); } else if (src == miSaveUISettings) { storeUISettings(); Toast.showToast(desktop, getUIInfo()); } else if (src == miPrint) { view.print(); } else if (src == miQuit) { savePrefs = (evt.getModifiers() & Event.SHIFT_MASK) == Event.SHIFT_MASK; try { close(); } catch (GemCloseVetoException ex) { GemLogger.logException(ex); } } else if (src == miExportA3 || src == miExportA4) { List<DayPlan> planning = ((DayScheduleView) view).getCurrentPlanning(); String proposed = "planning"; DayPlan plan = planning == null || planning.isEmpty() ? null : planning.get(0); if (plan != null && plan.getSchedule() != null && plan.getSchedule().size() > 0) { proposed = "planning_" + plan.getSchedule().get(0).getDate().toString(); } File destFile = FileUtil.getSaveFile(view, "xls", BundleUtil.getLabel("Excel.file.label"), proposed); if (destFile != null) { try { short paperSize = src == miExportA3 ? PrintSetup.A3_PAPERSIZE : PrintSetup.A4_PAPERSIZE; boolean printMembers = ConfigUtil.getConf(ConfigKey.SCHEDULE_RANGE_NAMES.getKey()).toLowerCase() .charAt(0) == 't'; new PlanningExportService(new PlanningService(DataCache.getDataConnection()), new StandardScheduleColorizer(new ColorPrefs()), paperSize, printMembers) .exportPlanning(planning, destFile); new DesktopOpenHandler().open(destFile.getAbsolutePath()); } catch (IOException | DesktopHandlerException e) { GemLogger.log(e.getMessage()); } } } else if (src == miEstab) { EstabActivationCtrl estabCtrl = new EstabActivationCtrl(desktop, true); estabCtrl.initUI(); if (estabCtrl.hasChanged()) { Toast.showToast(desktop, MessageUtil.getMessage("establishment.activation.info"), 4000); } } }
From source file:org.eclipse.scada.ae.ui.views.export.excel.impl.ExportEventsImpl.java
License:Open Source License
private HSSFSheet createSheet(final List<Event> events, final HSSFWorkbook workbook, final List<Field> columns) { final HSSFSheet sheet = workbook.createSheet(Messages.ExportImpl_ExcelSheet_Name); final HSSFHeader header = sheet.getHeader(); header.setLeft(Messages.ExportImpl_ExcelSheet_Header); header.setRight(HeaderFooter.date() + " " + HeaderFooter.time());//$NON-NLS-1$ final HSSFFooter footer = sheet.getFooter(); footer.setLeft(String.format(Messages.ExportImpl_ExcelSheet_Footer_1, events.size())); footer.setRight(Messages.ExportImpl_ExcelSheet_Footer_2 + HeaderFooter.page() + Messages.ExportImpl_ExcelSheet_Footer_3 + HeaderFooter.numPages()); makeHeader(columns, sheet);//www . ja va 2s . com final HSSFPrintSetup printSetup = sheet.getPrintSetup(); printSetup.setLandscape(true); printSetup.setFitWidth((short) 1); printSetup.setFitHeight((short) 0); printSetup.setPaperSize(PrintSetup.A4_PAPERSIZE); sheet.setAutoFilter(new CellRangeAddress(0, 0, 0, columns.size() - 1)); sheet.createFreezePane(0, 1); sheet.setFitToPage(true); sheet.setAutobreaks(true); printSetup.setFooterMargin(0.25); sheet.setMargin(Sheet.LeftMargin, 0.25); sheet.setMargin(Sheet.RightMargin, 0.25); sheet.setMargin(Sheet.TopMargin, 0.25); sheet.setMargin(Sheet.BottomMargin, 0.5); return sheet; }
From source file:org.primefaces.component.export.ExcelExporter.java
License:Open Source License
protected void applyOptions(Workbook wb, DataTable table, Sheet sheet, ExporterOptions options) { facetStyle = wb.createCellStyle();//from w w w .j a va 2s . c o m facetStyle.setAlignment((short) CellStyle.ALIGN_CENTER); facetStyle.setVerticalAlignment((short) CellStyle.VERTICAL_CENTER); facetStyle.setWrapText(true); applyFacetOptions(wb, options, facetStyle); cellStyle = wb.createCellStyle(); cellStyle.setAlignment((short) CellStyle.ALIGN_LEFT); applyCellOptions(wb, options, cellStyle); PrintSetup printSetup = sheet.getPrintSetup(); printSetup.setLandscape(true); printSetup.setPaperSize(PrintSetup.A4_PAPERSIZE); sheet.setPrintGridlines(true); }
From source file:org.primefaces.extensions.component.exporter.ExcelExporter.java
License:Apache License
@Override public void export(ActionEvent event, String tableId, FacesContext context, String filename, String tableTitle, boolean pageOnly, boolean selectionOnly, String encodingType, MethodExpression preProcessor, MethodExpression postProcessor, boolean subTable) throws IOException { wb = new XSSFWorkbook(); String safeName = WorkbookUtil.createSafeSheetName(filename); Sheet sheet = wb.createSheet(safeName); cellStyle = wb.createCellStyle();//w w w . ja va2 s. c o m facetStyle = wb.createCellStyle(); titleStyle = wb.createCellStyle(); facetStyleLeftAlign = wb.createCellStyle(); facetStyleCenterAlign = wb.createCellStyle(); facetStyleRightAlign = wb.createCellStyle(); cellStyleLeftAlign = wb.createCellStyle(); cellStyleCenterAlign = wb.createCellStyle(); cellStyleRightAlign = wb.createCellStyle(); createCustomFonts(); int maxColumns = 0; StringTokenizer st = new StringTokenizer(tableId, ","); while (st.hasMoreElements()) { String tableName = (String) st.nextElement(); UIComponent component = SearchExpressionFacade.resolveComponent(context, event.getComponent(), tableName); if (component == null) { throw new FacesException("Cannot find component \"" + tableName + "\" in view."); } if (!(component instanceof DataTable || component instanceof DataList)) { throw new FacesException("Unsupported datasource target:\"" + component.getClass().getName() + "\", exporter must target a PrimeFaces DataTable/DataList."); } DataList list = null; DataTable table = null; int cols = 0; if (preProcessor != null) { preProcessor.invoke(context.getELContext(), new Object[] { wb }); } if (tableTitle != null && !tableTitle.isEmpty() && !tableId.contains("" + ",")) { Row titleRow = sheet.createRow(sheet.getLastRowNum()); int cellIndex = titleRow.getLastCellNum() == -1 ? 0 : titleRow.getLastCellNum(); Cell cell = titleRow.createCell(cellIndex); cell.setCellValue(new XSSFRichTextString(tableTitle)); Font titleFont = wb.createFont(); titleFont.setBoldweight(Font.BOLDWEIGHT_BOLD); titleStyle.setFont(titleFont); cell.setCellStyle(titleStyle); sheet.createRow(sheet.getLastRowNum() + 3); } if (component instanceof DataList) { list = (DataList) component; if (list.getHeader() != null) { tableFacet(context, sheet, list, "header"); } if (pageOnly) { exportPageOnly(context, list, sheet); } else { exportAll(context, list, sheet); } cols = list.getRowCount(); } else { table = (DataTable) component; int columnsCount = getColumnsCount(table); if (table.getHeader() != null && !subTable) { tableFacet(context, sheet, table, columnsCount, "header"); } if (!subTable) { tableColumnGroup(sheet, table, "header"); } addColumnFacets(table, sheet, ColumnType.HEADER); if (pageOnly) { exportPageOnly(context, table, sheet); } else if (selectionOnly) { exportSelectionOnly(context, table, sheet); } else { exportAll(context, table, sheet, subTable); } if (table.hasFooterColumn() && !subTable) { addColumnFacets(table, sheet, ColumnType.FOOTER); } if (!subTable) { tableColumnGroup(sheet, table, "footer"); } table.setRowIndex(-1); if (postProcessor != null) { postProcessor.invoke(context.getELContext(), new Object[] { wb }); } cols = table.getColumnsCount(); if (maxColumns < cols) { maxColumns = cols; } } sheet.createRow(sheet.getLastRowNum() + Integer.parseInt(datasetPadding)); } if (!subTable) for (int i = 0; i < maxColumns; i++) { sheet.autoSizeColumn((short) i); } PrintSetup printSetup = sheet.getPrintSetup(); printSetup.setLandscape(true); printSetup.setPaperSize(PrintSetup.A4_PAPERSIZE); sheet.setPrintGridlines(true); writeExcelToResponse(context.getExternalContext(), wb, filename); }
From source file:org.primefaces.extensions.showcase.util.ExcelCustomExporter.java
License:Apache License
@Override public void export(ActionEvent event, String tableId, FacesContext context, String filename, String tableTitle, boolean pageOnly, boolean selectionOnly, String encodingType, MethodExpression preProcessor, MethodExpression postProcessor, boolean subTable) throws IOException { wb = new XSSFWorkbook(); String safeName = WorkbookUtil.createSafeSheetName(filename); Sheet sheet = wb.createSheet(safeName); cellStyle = wb.createCellStyle();//from ww w. j a va 2 s.com facetStyle = wb.createCellStyle(); titleStyle = wb.createCellStyle(); createCustomFonts(); int maxColumns = 0; StringTokenizer st = new StringTokenizer(tableId, ","); while (st.hasMoreElements()) { String tableName = (String) st.nextElement(); UIComponent component = SearchExpressionFacade.resolveComponent(context, event.getComponent(), tableName); if (component == null) { throw new FacesException("Cannot find component \"" + tableName + "\" in view."); } if (!(component instanceof DataTable || component instanceof DataList)) { throw new FacesException("Unsupported datasource target:\"" + component.getClass().getName() + "\", exporter must target a PrimeFaces DataTable/DataList."); } DataList list = null; DataTable table = null; int cols = 0; if (preProcessor != null) { preProcessor.invoke(context.getELContext(), new Object[] { wb }); } if (tableTitle != null && !tableTitle.isEmpty() && !tableId.contains("" + ",")) { Row titleRow = sheet.createRow(sheet.getLastRowNum()); int cellIndex = titleRow.getLastCellNum() == -1 ? 0 : titleRow.getLastCellNum(); Cell cell = titleRow.createCell(cellIndex); cell.setCellValue(new XSSFRichTextString(tableTitle)); Font titleFont = wb.createFont(); titleFont.setBold(true); titleStyle.setFont(titleFont); cell.setCellStyle(titleStyle); sheet.createRow(sheet.getLastRowNum() + 3); } if (component instanceof DataList) { list = (DataList) component; if (list.getHeader() != null) { tableFacet(context, sheet, list, "header"); } if (pageOnly) { exportPageOnly(context, list, sheet); } else { exportAll(context, list, sheet); } cols = list.getRowCount(); } else { table = (DataTable) component; int columnsCount = getColumnsCount(table); if (table.getHeader() != null && !subTable) { tableFacet(context, sheet, table, columnsCount, "header"); } if (!subTable) { tableColumnGroup(sheet, table, "header"); } addColumnFacets(table, sheet, ColumnType.HEADER); if (pageOnly) { exportPageOnly(context, table, sheet); } else if (selectionOnly) { exportSelectionOnly(context, table, sheet); } else { exportAll(context, table, sheet, subTable); } if (table.hasFooterColumn() && !subTable) { addColumnFacets(table, sheet, ColumnType.FOOTER); } if (!subTable) { tableColumnGroup(sheet, table, "footer"); } table.setRowIndex(-1); if (postProcessor != null) { postProcessor.invoke(context.getELContext(), new Object[] { wb }); } cols = table.getColumnsCount(); if (maxColumns < cols) { maxColumns = cols; } } sheet.createRow(sheet.getLastRowNum() + Integer.parseInt(datasetPadding)); } if (!subTable) { for (int i = 0; i < maxColumns; i++) { sheet.autoSizeColumn((short) i); } } PrintSetup printSetup = sheet.getPrintSetup(); printSetup.setLandscape(true); printSetup.setPaperSize(PrintSetup.A4_PAPERSIZE); sheet.setPrintGridlines(true); writeExcelToResponse(context.getExternalContext(), wb, filename); }
From source file:org.projectforge.core.ConfigXml.java
License:Open Source License
/** * Supported values "LETTER", default is "DINA4". * @return PrintSetup short value. Default is * @see PrintSetup#A4_PAPERSIZE./* w w w . jav a 2 s . c o m*/ */ public short getDefaultPaperSize() { if (excelDefaultPaperSizeValue != -42) { return excelDefaultPaperSizeValue; } if ("LETTER".equals(excelDefaultPaperSize) == true) { excelDefaultPaperSizeValue = PrintSetup.LETTER_PAPERSIZE; } else { excelDefaultPaperSizeValue = PrintSetup.A4_PAPERSIZE; } return excelDefaultPaperSizeValue; }