Example usage for org.apache.poi.ss.usermodel Sheet BottomMargin

List of usage examples for org.apache.poi.ss.usermodel Sheet BottomMargin

Introduction

In this page you can find the example usage for org.apache.poi.ss.usermodel Sheet BottomMargin.

Prototype

short BottomMargin

To view the source code for org.apache.poi.ss.usermodel Sheet BottomMargin.

Click Source Link

Usage

From source file:com.actelion.research.spiritapp.report.AbstractReport.java

License:Open Source License

/**
 * Creates a new sheet, ensuring that the name is safe and unique
 * @param workbook/*from  w w w . j  av  a2s.c  om*/
 * @param sheetName
 * @return
 */
public Sheet createSheet(Workbook workbook, String sheetName) {
    Set<String> names = new HashSet<String>();
    for (int i = 0; i < workbook.getNumberOfSheets(); i++) {
        names.add(workbook.getSheetName(i));
    }

    String safe = WorkbookUtil.createSafeSheetName(sheetName);

    String name;
    for (int i = 0;; i++) {
        name = safe + (i == 0 ? "" : " (" + i + ")");
        if (!names.contains(name))
            break;
    }
    Sheet sheet = wb.createSheet(name);
    sheet.setAutobreaks(true);
    sheet.setMargin(Sheet.LeftMargin, 1);
    sheet.setMargin(Sheet.RightMargin, 1);
    sheet.setMargin(Sheet.BottomMargin, .5);
    sheet.setMargin(Sheet.TopMargin, .5);

    sheet.setFitToPage(true);
    sheet.getPrintSetup().setLandscape(true);
    sheet.getPrintSetup().setFitWidth((short) 1);
    sheet.getPrintSetup().setFitHeight((short) 99);

    //      Footer footer = sheet.getFooter();
    //       footer.setRight( "Page " + HeaderFooter.page() + " of " + HeaderFooter.numPages() );

    return sheet;
}

From source file:fr.amapj.service.engine.generator.excel.ExcelGeneratorTool.java

License:Open Source License

/**
 * Les paramtres sont en mm/*from  w  w w  .  j  a v a 2 s. co m*/
 */
public void setMargin(int left, int right, int top, int bottom) {
    // c est la valeur de 1 mm en inches
    double c = 0.039370;
    sheet.setMargin(Sheet.LeftMargin, c * left);
    sheet.setMargin(Sheet.RightMargin, c * right);
    sheet.setMargin(Sheet.TopMargin, c * top);
    sheet.setMargin(Sheet.BottomMargin, c * bottom);
}

From source file:jdbreport.model.io.xls.poi.Excel2003Writer.java

License:Apache License

private void saveSheet(Workbook wb, ReportModel model, ReportBook reportBook, String reportTitle)
        throws SaveReportException {

    CreationHelper createHelper = wb.getCreationHelper();

    Sheet sheet = wb.createSheet(reportTitle);
    sheet.setDisplayGridlines(reportBook.isShowGrid());
    sheet.setPrintGridlines(false);/*from  w ww .j a  v  a 2s  .c  om*/
    sheet.setFitToPage(model.isStretchPage());
    sheet.setDisplayRowColHeadings(model.isShowHeader() || model.isShowRowHeader());
    ReportPage rp = model.getReportPage();
    sheet.setMargin(Sheet.TopMargin, rp.getTopMargin(Units.INCH));
    sheet.setMargin(Sheet.BottomMargin, rp.getBottomMargin(Units.INCH));
    sheet.setMargin(Sheet.LeftMargin, rp.getLeftMargin(Units.INCH));
    sheet.setMargin(Sheet.RightMargin, rp.getRightMargin(Units.INCH));
    sheet.getPrintSetup().setLandscape(rp.getOrientation() == ReportPage.LANDSCAPE);
    short paperSize = convertPaperSize(rp.getPaperSize());
    if (paperSize > 0) {
        sheet.getPrintSetup().setPaperSize(paperSize);
    }

    TableColumnModel cm = model.getColumnModel();

    for (int c = 0; c < model.getColumnCount(); c++) {
        if (model.isColumnBreak(c)) {
            sheet.setColumnBreak(c);
        }

        //char width in points
        float char_width = 5.5f;
        sheet.setColumnWidth(c,
                (int) ((((ReportColumn) cm.getColumn(c)).getNativeWidth() - 2) / char_width * 256));
    }

    fillStyles(wb, reportBook);

    createRows(model, sheet);

    drawing = sheet.createDrawingPatriarch();
    for (int row = 0; row < model.getRowCount(); row++) {
        saveRow(wb, sheet, reportBook, model, row, createHelper);
    }
    drawing = null;
}

From source file:net.algem.planning.export.PlanningExportService.java

License:Open Source License

/**
 * Export to Excel destination file.//from w ww. j  av a2s. c  om
 *
 * @param dayPlan list of day schedules
 * @param destFile destination file
 * @throws IOException
 */
public void exportPlanning(List<DayPlan> dayPlan, File destFile) throws IOException {
    GemLogger.info("Exporting planning to " + destFile);

    Hour defStartTime = new Hour(ConfigUtil.getConf(ConfigKey.START_TIME.getKey()));
    int offset = defStartTime.getHour();
    int totalh = 24 - offset; // total time length in hours

    HSSFWorkbook workbook = new HSSFWorkbook();
    Sheet sheet = workbook.createSheet("Planning");
    if (dayPlan.size() > 0) {
        DateFormat df = new SimpleDateFormat("EEEE dd MMM yyyy");
        Header header = sheet.getHeader();
        String hd = df.format(dayPlan.get(0).getSchedule().get(0).getDate().getDate());
        header.setCenter(HSSFHeader.fontSize((short) 12) + HSSFHeader.startBold() + hd + HSSFHeader.endBold());
    }

    PrintSetup printSetup = sheet.getPrintSetup();
    printSetup.setLandscape(true);
    printSetup.setPaperSize(paperSize);
    sheet.setFitToPage(true);
    sheet.setHorizontallyCenter(false);// was true before 2.15.8
    sheet.setMargin(Sheet.TopMargin, 0.75); // 1.905
    sheet.setMargin(Sheet.BottomMargin, 0.4); // 0.4 inch = 1.016 cm
    sheet.setMargin(Sheet.LeftMargin, 0.4);
    sheet.setMargin(Sheet.RightMargin, 0.4);

    Map<String, CellStyle> styles = createStyles(workbook);

    Row headerRow = sheet.createRow(0);
    for (int i = 0; i < dayPlan.size(); i++) {
        Cell roomCell = headerRow.createCell(i + 1);
        // Set the width (in units of 1/256th of a character width)
        //sheet.setColumnWidth(i + 1, totalh * 256);// max number of characters must not depend of time length
        sheet.setColumnWidth(i + 1, 24 * 256); // cours.titre character varying(32)
        roomCell.setCellValue(dayPlan.get(i).getLabel());
        roomCell.setCellStyle(styles.get("header"));
    }
    int offsetMn = offset * 60;// offset in minutes
    List<Row> rows = new ArrayList<>();
    System.out.println(" offset = " + offset + " totalh = " + totalh);
    for (int t = 0, rowNumber = 1; t < totalh * 60; t += 5, rowNumber++) { // 1 row = 5mn
        Hour hour = new Hour(offsetMn + t);
        Row row = sheet.createRow(rowNumber);
        //row.setHeightInPoints(25);
        row.setHeightInPoints(PrintSetup.A3_PAPERSIZE == paperSize ? 12 : 6);
        // TIME SUBDIVISIONS
        if (t % 15 == 0) {
            Cell cell = row.createCell(0);
            if (t % 30 == 0) {
                cell.setCellValue(hour.toString());//show time
                if (t % 60 == 0) {
                    cell.setCellStyle(styles.get("hour"));
                } else {
                    cell.setCellStyle(styles.get("hour-half"));
                }
            } else {
                cell.setCellStyle(styles.get("hour-quarter"));
            }
        } else { // BETWEEN SUBDIVISION
            Cell cell = row.createCell(0);
            if ("23:55".equals(hour.toString())) { // last slice
                cell.setCellStyle(styles.get("hour-last"));
            } else {
                cell.setCellStyle(styles.get("hour"));
            }
            if (rowNumber % 3 == 0) { // merge every 3 rows
                sheet.addMergedRegion(new CellRangeAddress(rowNumber - 2, rowNumber, 0, 0));
            }
        }
        rows.add(row);
    }

    Map<java.awt.Color, CellStyle> coursStyleCache = new HashMap<>();

    for (int i = 0; i < dayPlan.size(); i++) {
        DayPlan plan = dayPlan.get(i);
        int col = i + 1;
        for (ScheduleObject event : plan.getSchedule()) {
            // if event starts before default starting time
            if (event.getStart().toMinutes() < offsetMn) {
                event.setStart(new Hour(offset * 60));
            }
            int startRowPos = (event.getStart().toMinutes() - offsetMn) / 5 + 1;
            int endRowPos = (event.getEnd().toMinutes() - offsetMn) / 5;

            Cell courseCell = rows.get(startRowPos - 1).createCell(col);
            courseCell.setCellValue(getLabel(event, workbook));// title text

            CellStyle style = getCourseStyle(workbook, event, coursStyleCache);
            courseCell.setCellStyle(style);
            if (startRowPos != endRowPos) {
                sheet.addMergedRegion(new CellRangeAddress(startRowPos, endRowPos, col, col));
                for (int row = startRowPos; row < endRowPos; row++) {
                    rows.get(row).createCell(col).setCellStyle(style);
                }
            }
        }

    }

    try (FileOutputStream out = new FileOutputStream(destFile)) {
        workbook.write(out);
    }

}

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);/*from   w  w w  .ja  v a 2  s .  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.talend.dataprep.schema.xls.streaming.StreamingSheetTest.java

License:Open Source License

@Test(expected = UnsupportedOperationException.class)
public void getMargin() throws Exception {
    streamingSheet.getMargin(Sheet.BottomMargin);
}

From source file:org.talend.dataprep.schema.xls.streaming.StreamingSheetTest.java

License:Open Source License

@Test(expected = UnsupportedOperationException.class)
public void setMargin() throws Exception {
    streamingSheet.setMargin(Sheet.BottomMargin, 0);
}

From source file:org.talend.dataprep.schema.xls.streaming.StreamingSheetTest.java

License:Open Source License

@Test(expected = UnsupportedOperationException.class)
public void showInPane() throws Exception {
    streamingSheet.showInPane(Sheet.BottomMargin, 0);
}

From source file:uk.co.spudsoft.birt.emitters.excel.StyleManagerHUtils.java

License:Open Source License

@Override
public void prepareMarginDimensions(Sheet sheet, IPageContent page) {
    double headerHeight = 0.5;
    double footerHeight = 0.5;
    if ((page.getHeaderHeight() != null) && isAbsolute(page.getHeaderHeight())) {
        headerHeight = page.getHeaderHeight().convertTo(DimensionType.UNITS_IN);
        sheet.getPrintSetup().setHeaderMargin(headerHeight);
    }//from  w w  w .jav  a  2 s  . com
    if ((page.getFooterHeight() != null) && isAbsolute(page.getFooterHeight())) {
        footerHeight = page.getFooterHeight().convertTo(DimensionType.UNITS_IN);
        sheet.getPrintSetup().setFooterMargin(footerHeight);
    }
    if ((page.getMarginBottom() != null) && isAbsolute(page.getMarginBottom())) {
        sheet.setMargin(Sheet.BottomMargin,
                footerHeight + page.getMarginBottom().convertTo(DimensionType.UNITS_IN));
    }
    if ((page.getMarginLeft() != null) && isAbsolute(page.getMarginLeft())) {
        sheet.setMargin(Sheet.LeftMargin, page.getMarginLeft().convertTo(DimensionType.UNITS_IN));
    }
    if ((page.getMarginRight() != null) && isAbsolute(page.getMarginRight())) {
        sheet.setMargin(Sheet.RightMargin, page.getMarginRight().convertTo(DimensionType.UNITS_IN));
    }
    if ((page.getMarginTop() != null) && isAbsolute(page.getMarginTop())) {
        sheet.setMargin(Sheet.TopMargin, headerHeight + page.getMarginTop().convertTo(DimensionType.UNITS_IN));
    }
}

From source file:uk.co.spudsoft.birt.emitters.excel.StyleManagerXUtils.java

License:Open Source License

@Override
public void prepareMarginDimensions(Sheet sheet, IPageContent page) {
    double headerHeight = 0.5;
    double footerHeight = 0.5;
    if ((page.getHeaderHeight() != null) && isAbsolute(page.getHeaderHeight())) {
        headerHeight = page.getHeaderHeight().convertTo(DimensionType.UNITS_IN);
        sheet.setMargin(Sheet.HeaderMargin, headerHeight);
    }/*w w  w  .j  ava 2 s.  com*/
    if ((page.getFooterHeight() != null) && isAbsolute(page.getFooterHeight())) {
        footerHeight = page.getFooterHeight().convertTo(DimensionType.UNITS_IN);
        sheet.setMargin(Sheet.FooterMargin, footerHeight);
    }
    if ((page.getMarginBottom() != null) && isAbsolute(page.getMarginBottom())) {
        sheet.setMargin(Sheet.BottomMargin,
                footerHeight + page.getMarginBottom().convertTo(DimensionType.UNITS_IN));
    }
    if ((page.getMarginLeft() != null) && isAbsolute(page.getMarginLeft())) {
        sheet.setMargin(Sheet.LeftMargin, page.getMarginLeft().convertTo(DimensionType.UNITS_IN));
    }
    if ((page.getMarginRight() != null) && isAbsolute(page.getMarginRight())) {
        sheet.setMargin(Sheet.RightMargin, page.getMarginRight().convertTo(DimensionType.UNITS_IN));
    }
    if ((page.getMarginTop() != null) && isAbsolute(page.getMarginTop())) {
        sheet.setMargin(Sheet.TopMargin, headerHeight + page.getMarginTop().convertTo(DimensionType.UNITS_IN));
    }
}