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

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

Introduction

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

Prototype

short RightMargin

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

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  a  va 2 s. c o m
 * @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:coverageqc.functions.MyExcelEditor.java

public static void excelFormator(XSSFSheet currentSheet, File variantTsvFile, String tsvHeadingLine)
        throws IOException {
    String[] headingsArray = tsvHeadingLine.split("\t");
    HashMap<String, Integer> headings = new HashMap<String, Integer>();
    for (int x = 0; x < headingsArray.length; x++) {
        headings.put(headingsArray[x].substring(0, headingsArray[x].indexOf("_")), x);
    }//from  w w w.ja  v  a  2s  . c  o  m

    XSSFPrintSetup printSetup = (XSSFPrintSetup) currentSheet.getPrintSetup();

    File xslxTempFile = new File(variantTsvFile.getCanonicalPath() + ".coverage_qc.xlsx");
    currentSheet.getHeader().setLeft(xslxTempFile.getName());
    currentSheet.getHeader().setRight("DO NOT DISCARD!!!  Keep with patient folder.");
    //in Dr. Carter's VBA was set at points 18 which is .25 inches
    currentSheet.setMargin(Sheet.RightMargin, .25);
    currentSheet.setMargin(Sheet.LeftMargin, .25);

    printSetup.setOrientation(PrintOrientation.LANDSCAPE);

    //NOTE: setFitWidth doesn't work for columns, ie can't setFitToPageColumns, this 
    //is the best workaround I can do, it will only looked cramped for those with a lot of calls
    printSetup.setFitWidth((short) 1);
    printSetup.setFitHeight((short) 3);
    currentSheet.setRepeatingRows(CellRangeAddress.valueOf("1"));
    currentSheet.setFitToPage(true);
    //making it by default not print the fellow's interp
    currentSheet.getWorkbook().setPrintArea(0, 1, currentSheet.getRow(0).getPhysicalNumberOfCells(), 0,
            currentSheet.getLastRowNum());

    for (int x = 0; x < currentSheet.getRow(0).getPhysicalNumberOfCells(); x++) {
        currentSheet.autoSizeColumn(x);
    }
    currentSheet.setColumnWidth(0, 10000);
    currentSheet.setColumnWidth(1, 10000);

    currentSheet.setColumnWidth(headings.get("Consequence").intValue() + 2, 3500);
    currentSheet.setColumnHidden(headings.get("Classification").intValue() + 2, true);
    currentSheet.setColumnHidden(headings.get("Inherited From").intValue() + 2, true);
    currentSheet.setColumnHidden(headings.get("Allelic Depths").intValue() + 2, true);
    currentSheet.setColumnHidden(headings.get("Custom Annotation").intValue() + 2, true);
    currentSheet.setColumnHidden(headings.get("Custom Gene Annotation").intValue() + 2, true);
    currentSheet.setColumnHidden(headings.get("Num Transcripts").intValue() + 2, true);
    currentSheet.setColumnHidden(headings.get("Transcript").intValue() + 2, true);
    currentSheet.setColumnHidden(headings.get("cDNA Position").intValue() + 2, true);
    currentSheet.setColumnHidden(headings.get("CDS Position").intValue() + 2, true);
    currentSheet.setColumnHidden(headings.get("Protein Position").intValue() + 2, true);
    currentSheet.setColumnHidden(headings.get("Amino Acids").intValue() + 2, true);
    currentSheet.setColumnHidden(headings.get("Codons").intValue() + 2, true);
    currentSheet.setColumnHidden(headings.get("HGNC").intValue() + 2, true);
    currentSheet.setColumnHidden(headings.get("Transcript HGNC").intValue() + 2, true);
    currentSheet.setColumnHidden(headings.get("Canonical").intValue() + 2, true);
    currentSheet.setColumnHidden(headings.get("Sift").intValue() + 2, true);
    currentSheet.setColumnHidden(headings.get("PolyPhen").intValue() + 2, true);
    currentSheet.setColumnHidden(headings.get("ENSP").intValue() + 2, true);
    currentSheet.setColumnHidden(headings.get("HGVSc").intValue() + 2, true);
    currentSheet.setColumnHidden(headings.get("HGVSp").intValue() + 2, true);
    currentSheet.setColumnHidden(headings.get("dbSNP ID").intValue() + 2, true);
    currentSheet.setColumnHidden(headings.get("Ancestral Allele").intValue() + 2, true);
    currentSheet.setColumnHidden(headings.get("Allele Freq").intValue() + 2, true);
    //everything beyond this is hidden
    for (int x = headings.get("Global Minor Allele").intValue() + 2; x < currentSheet.getRow(0)
            .getPhysicalNumberOfCells(); x++) {
        currentSheet.setColumnHidden(x, true);
    }

}

From source file:coverageqc.functions.MyExcelGenerator.java

public void excelFormator(String sheetName, File variantTsvFile) throws IOException {
    // String[] headingsArray = tsvHeadingLine.split("\t");
    // HashMap<String, Integer> headings = new HashMap<String, Integer>();
    // for(int x = 0; x < headingsArray.length; x++) {
    //     headings.put(headingsArray[x].substring(0, headingsArray[x].indexOf("_")), x);
    // }//from  w w  w. ja va  2 s. c  om
    XSSFSheet currentSheet = this.workbookcopy.getSheet(sheetName);

    XSSFPrintSetup printSetup = (XSSFPrintSetup) currentSheet.getPrintSetup();

    File xslxTempFile = new File(variantTsvFile.getCanonicalPath() + ".coverage_qc.xlsx");
    currentSheet.getHeader().setLeft(xslxTempFile.getName());
    currentSheet.getHeader().setRight("DO NOT DISCARD!!!  Keep with patient folder.");
    //in Dr. Carter's VBA was set at points 18 which is .25 inches
    currentSheet.setMargin(Sheet.RightMargin, .25);
    currentSheet.setMargin(Sheet.LeftMargin, .25);

    printSetup.setOrientation(PrintOrientation.LANDSCAPE);

    //NOTE: setFitWidth doesn't work for columns, ie can't setFitToPageColumns, this 
    //is the best workaround I can do, it will only looked cramped for those with a lot of calls
    printSetup.setFitWidth((short) 1);
    printSetup.setFitHeight((short) 3);
    currentSheet.setRepeatingRows(CellRangeAddress.valueOf("1"));
    currentSheet.setFitToPage(true);
    //making it by default not print the fellow's interp
    currentSheet.getWorkbook().setPrintArea(0, 2, 20, 0, currentSheet.getLastRowNum());

    for (int x = 0; x < currentSheet.getRow(0).getPhysicalNumberOfCells(); x++) {
        currentSheet.autoSizeColumn(x);
        if (x > 33) {
            currentSheet.setColumnHidden(x, true);
        }
    }
    currentSheet.setColumnWidth(0, 10000);
    currentSheet.setColumnWidth(1, 10000);
    currentSheet.setColumnWidth(2, 10000);

    //                 currentSheet.setColumnWidth(this.tsvRearrangeConversion.get(this.originalHeadings.get("Consequence"))+3, 3500);
    //                 currentSheet.setColumnHidden(this.tsvRearrangeConversion.get(this.originalHeadings.get("Gene"))+3, false);
    //                 currentSheet.setColumnHidden(this.tsvRearrangeConversion.get(this.originalHeadings.get("Variant"))+3, false);
    //                 currentSheet.setColumnHidden(this.tsvRearrangeConversion.get(this.originalHeadings.get("Chr"))+3, false);
    //                 currentSheet.setColumnHidden(this.tsvRearrangeConversion.get(this.originalHeadings.get("Coordinate"))+3, false);
    //                 currentSheet.setColumnHidden(this.tsvRearrangeConversion.get(this.originalHeadings.get("Type"))+3, false);
    //                 currentSheet.setColumnHidden(this.tsvRearrangeConversion.get(this.originalHeadings.get("Genotype"))+3, false);
    //                 currentSheet.setColumnHidden(this.tsvRearrangeConversion.get(this.originalHeadings.get("Exonic"))+3, false);
    //                 currentSheet.setColumnHidden(this.tsvRearrangeConversion.get(this.originalHeadings.get("Filters"))+3, false);
    //                 currentSheet.setColumnHidden(this.tsvRearrangeConversion.get(this.originalHeadings.get("Quality"))+3, false);
    //                 currentSheet.setColumnHidden(this.tsvRearrangeConversion.get(this.originalHeadings.get("GQX"))+3, false);
    //                 currentSheet.setColumnHidden(this.tsvRearrangeConversion.get(this.originalHeadings.get("Alt Variant Freq"))+3, false);
    //                 currentSheet.setColumnHidden(this.tsvRearrangeConversion.get(this.originalHeadings.get("Read Depth"))+3, false);
    //                 currentSheet.setColumnHidden(this.tsvRearrangeConversion.get(this.originalHeadings.get("Alt Read Depth"))+3, false);
    //                 currentSheet.setColumnHidden(this.tsvRearrangeConversion.get(this.originalHeadings.get("Consequence"))+3, false);
    //                 currentSheet.setColumnHidden(this.tsvRearrangeConversion.get(this.originalHeadings.get("Sift"))+3, false);
    //                 currentSheet.setColumnHidden(this.tsvRearrangeConversion.get(this.originalHeadings.get("PolyPhen"))+3, false);
    //                 currentSheet.setColumnHidden(this.tsvRearrangeConversion.get(this.originalHeadings.get("Allele Freq Global Minor"))+3, false);
    //                 currentSheet.setColumnHidden(this.tsvRearrangeConversion.get(this.originalHeadings.get("Classification"))+3, true);
    //                 currentSheet.setColumnHidden(this.tsvRearrangeConversion.get(this.originalHeadings.get("Inherited From"))+3, true);
    //                 currentSheet.setColumnHidden(this.tsvRearrangeConversion.get(this.originalHeadings.get("Allelic Depths"))+3, true); 
    //                 currentSheet.setColumnHidden(this.tsvRearrangeConversion.get(this.originalHeadings.get("Custom Annotation"))+3, true);
    //                 currentSheet.setColumnHidden(this.tsvRearrangeConversion.get(this.originalHeadings.get("Custom Gene Annotation"))+3, true);
    //                 currentSheet.setColumnHidden(this.tsvRearrangeConversion.get(this.originalHeadings.get("Num Transcripts"))+3, true);
    //                 currentSheet.setColumnHidden(this.tsvRearrangeConversion.get(this.originalHeadings.get("Transcript"))+3, true);
    //                 currentSheet.setColumnHidden(this.tsvRearrangeConversion.get(this.originalHeadings.get("cDNA Position"))+3, false);
    //                 currentSheet.setColumnHidden(this.tsvRearrangeConversion.get(this.originalHeadings.get("CDS Position"))+3, false);
    //                 currentSheet.setColumnHidden(this.tsvRearrangeConversion.get(this.originalHeadings.get("Protein Position"))+3, true);
    //                 currentSheet.setColumnHidden(this.tsvRearrangeConversion.get(this.originalHeadings.get("Amino Acids"))+3, true);
    //                 currentSheet.setColumnHidden(this.tsvRearrangeConversion.get(this.originalHeadings.get("Codons"))+3, true);
    //                 currentSheet.setColumnHidden(this.tsvRearrangeConversion.get(this.originalHeadings.get("HGNC"))+3, true);
    //                 currentSheet.setColumnHidden(this.tsvRearrangeConversion.get(this.originalHeadings.get("Transcript HGNC"))+3, true);
    //                 currentSheet.setColumnHidden(this.tsvRearrangeConversion.get(this.originalHeadings.get("Canonical"))+3, true);
    //                 //currentSheet.setColumnHidden(this.tsvRearrangeConversion.get(this.originalHeadings.get("Sift"))+3, false);
    //                 //currentSheet.setColumnHidden(this.tsvRearrangeConversion.get(this.originalHeadings.get("PolyPhen"))+3, false);
    //                 currentSheet.setColumnHidden(this.tsvRearrangeConversion.get(this.originalHeadings.get("ENSP"))+3, false);
    //                 currentSheet.setColumnHidden(this.tsvRearrangeConversion.get(this.originalHeadings.get("HGVSc"))+3, false);
    //                 currentSheet.setColumnHidden(this.tsvRearrangeConversion.get(this.originalHeadings.get("HGVSp"))+3, false);
    //                 currentSheet.setColumnHidden(this.tsvRearrangeConversion.get(this.originalHeadings.get("dbSNP ID"))+3, false);
    //                 currentSheet.setColumnHidden(this.tsvRearrangeConversion.get(this.originalHeadings.get("Ancestral Allele"))+3, true);
    //                 currentSheet.setColumnHidden(this.tsvRearrangeConversion.get(this.originalHeadings.get("Global Minor Allele"))+3, true);
    //                 currentSheet.setColumnHidden(this.tsvRearrangeConversion.get(this.originalHeadings.get("Allele Freq Amr"))+3, true);
    //                 currentSheet.setColumnHidden(this.tsvRearrangeConversion.get(this.originalHeadings.get("Allele Freq Asn"))+3, true);
    //                 currentSheet.setColumnHidden(this.tsvRearrangeConversion.get(this.originalHeadings.get("Allele Freq Af"))+3, true);
    //                 currentSheet.setColumnHidden(this.tsvRearrangeConversion.get(this.originalHeadings.get("Allele Freq Eur"))+3, true);
    //                 currentSheet.setColumnHidden(this.tsvRearrangeConversion.get(this.originalHeadings.get("Allele Freq Evs"))+3, true);
    //                 currentSheet.setColumnHidden(this.tsvRearrangeConversion.get(this.originalHeadings.get("EVS Coverage"))+3, true);
    //                 currentSheet.setColumnHidden(this.tsvRearrangeConversion.get(this.originalHeadings.get("EVS Samples"))+3, true);
    //                 currentSheet.setColumnHidden(this.tsvRearrangeConversion.get(this.originalHeadings.get("Conserved Sequence"))+3, true);
    //                 currentSheet.setColumnHidden(this.tsvRearrangeConversion.get(this.originalHeadings.get("COSMIC ID"))+3, false);
    //                 currentSheet.setColumnHidden(this.tsvRearrangeConversion.get(this.originalHeadings.get("COSMIC Wildtype"))+3, true);
    //                 currentSheet.setColumnHidden(this.tsvRearrangeConversion.get(this.originalHeadings.get("COSMIC Allele"))+3, true);
    //                 currentSheet.setColumnHidden(this.tsvRearrangeConversion.get(this.originalHeadings.get("COSMIC Gene"))+3, true);
    //                 currentSheet.setColumnHidden(this.tsvRearrangeConversion.get(this.originalHeadings.get("COSMIC Primary Site"))+3, false);
    //                 currentSheet.setColumnHidden(this.tsvRearrangeConversion.get(this.originalHeadings.get("COSMIC Histology"))+3, true);
    //                 currentSheet.setColumnHidden(this.tsvRearrangeConversion.get(this.originalHeadings.get("ClinVar Accession"))+3, false);
    //                 currentSheet.setColumnHidden(this.tsvRearrangeConversion.get(this.originalHeadings.get("ClinVar Ref"))+3, false);
    //                 currentSheet.setColumnHidden(this.tsvRearrangeConversion.get(this.originalHeadings.get("ClinVar Alleles"))+3, false);
    //                 currentSheet.setColumnHidden(this.tsvRearrangeConversion.get(this.originalHeadings.get("ClinVar Allele Type"))+3, false);
    //                 currentSheet.setColumnHidden(this.tsvRearrangeConversion.get(this.originalHeadings.get("ClinVar Significance"))+3, false);
    //                 currentSheet.setColumnHidden(this.tsvRearrangeConversion.get(this.originalHeadings.get("Alternate Alleles"))+3, true);
    //                 currentSheet.setColumnHidden(this.tsvRearrangeConversion.get(this.originalHeadings.get("Google Scholar"))+3, true);
    //                 currentSheet.setColumnHidden(this.tsvRearrangeConversion.get(this.originalHeadings.get("PubMed"))+3, true);
    //                 currentSheet.setColumnHidden(this.tsvRearrangeConversion.get(this.originalHeadings.get("UCSC Browser"))+3, true);
    //                 currentSheet.setColumnHidden(this.tsvRearrangeConversion.get(this.originalHeadings.get("ClinVar RS"))+3, true);
    //                 currentSheet.setColumnHidden(this.tsvRearrangeConversion.get(this.originalHeadings.get("ClinVar Disease Name"))+3, true);
    //                 currentSheet.setColumnHidden(this.tsvRearrangeConversion.get(this.originalHeadings.get("ClinVar MedGen"))+3, true);
    //                 currentSheet.setColumnHidden(this.tsvRearrangeConversion.get(this.originalHeadings.get("ClinVar OMIM"))+3, true);
    //                 currentSheet.setColumnHidden(this.tsvRearrangeConversion.get(this.originalHeadings.get("ClinVar Orphanet"))+3, true);
    //                 currentSheet.setColumnHidden(this.tsvRearrangeConversion.get(this.originalHeadings.get("ClinVar GeneReviews"))+3, true);
    //                 currentSheet.setColumnHidden(this.tsvRearrangeConversion.get(this.originalHeadings.get("ClinVar SnoMedCt ID"))+3, true);

}

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

License:Open Source License

/**
 * Les paramtres sont en mm//from w w  w .jav a  2 s.  c o  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);//ww  w .  j av a  2 s.  c  o  m
    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 w w  .  j a  v a2 s  . 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 . java2s.  c o  m*/

    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: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 www .  ja  va  2s .  c  om*/
    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  ww .  j a v a  2 s  .  c  o  m*/
    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));
    }
}

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

License:Open Source License

@Test
public void testRunReportXlsx() throws BirtException, IOException {

    InputStream inputStream = runAndRenderReport("PageLayout.rptdesign", "xlsx");
    assertNotNull(inputStream);// w  w  w  .j  a  v  a2  s  .com
    try {

        XSSFWorkbook workbook = new XSSFWorkbook(inputStream);
        assertNotNull(workbook);

        assertEquals(1, workbook.getNumberOfSheets());
        assertEquals("Page Layout Test", workbook.getSheetAt(0).getSheetName());

        XSSFSheet sheet0 = workbook.getSheetAt(0);
        XSSFPrintSetup printSetup = sheet0.getPrintSetup();
        assertEquals(PaperSize.A4_PAPER, printSetup.getPaperSizeEnum());
        assertEquals(PrintOrientation.LANDSCAPE, printSetup.getOrientation());
        assertEquals(1.0 / 2.54, printSetup.getHeaderMargin(), 0.01);
        assertEquals(1.0 / 2.54, printSetup.getFooterMargin(), 0.01);
        assertEquals(0.7 / 2.54, sheet0.getMargin(Sheet.LeftMargin), 0.01);
        assertEquals(0.7 / 2.54, sheet0.getMargin(Sheet.RightMargin), 0.01);
        assertEquals(1.7 / 2.54, sheet0.getMargin(Sheet.TopMargin), 0.01);
        assertEquals(1.7 / 2.54, sheet0.getMargin(Sheet.BottomMargin), 0.01);

    } finally {
        inputStream.close();
    }
}