Example usage for org.apache.poi.ss.usermodel PrintSetup A3_PAPERSIZE

List of usage examples for org.apache.poi.ss.usermodel PrintSetup A3_PAPERSIZE

Introduction

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

Prototype

short A3_PAPERSIZE

To view the source code for org.apache.poi.ss.usermodel PrintSetup A3_PAPERSIZE.

Click Source Link

Document

A3 - 297x420 mm

Usage

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);//  ww  w. j  ava  2  s. c  o  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:net.algem.planning.export.PlanningExportService.java

License:Open Source License

/**
 * Export to Excel destination file.//from   ww w .ja  v 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:ro.nextreports.engine.exporter.XlsExporter.java

License:Apache License

private void setPaperSize() {
    String pageFormat = bean.getReportLayout().getPageFormat();
    short size = 0;
    if (ReportLayout.LETTER.equals(pageFormat)) {
        size = PrintSetup.LETTER_PAPERSIZE;
    } else if (ReportLayout.A3.equals(pageFormat)) {
        size = PrintSetup.A3_PAPERSIZE;
    } else if (ReportLayout.A4.equals(pageFormat)) {
        size = PrintSetup.A4_PAPERSIZE;/*w w w .j  a v a 2s  .  c o m*/
    } else if (ReportLayout.LEGAL.equals(pageFormat)) {
        size = PrintSetup.LEGAL_PAPERSIZE;
    } else if (ReportLayout.LEDGER.equals(pageFormat)) {
        size = PrintSetup.LEDGER_PAPERSIZE;
    } else if (ReportLayout.TABLOID.equals(pageFormat)) {
        size = PrintSetup.TABLOID_PAPERSIZE;
    }
    if (size != 0) {
        xlsSheet.getPrintSetup().setPaperSize(size);
    }
}

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

License:Open Source License

/**
 * Convert a BIRT paper size string into a POI PrintSetup.*PAPERSIZE constant.
 * @param name//from w  ww .  j a v  a 2s  .com
 * The paper size as a BIRT string.
 * @return
 * A POI PrintSetup.*PAPERSIZE constant.
 */
public short getPaperSizeFromString(String name) {
    if ("a4".equals(name)) {
        return PrintSetup.A4_PAPERSIZE;
    } else if ("a3".equals(name)) {
        return PrintSetup.A3_PAPERSIZE;
    } else if ("us-letter".equals(name)) {
        return PrintSetup.LETTER_PAPERSIZE;
    }

    return PrintSetup.A4_PAPERSIZE;
}