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

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

Introduction

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

Prototype

void setRepeatingColumns(CellRangeAddress columnRangeRef);

Source Link

Document

Sets the repeating columns used when printing the sheet, as found in File->PageSetup->Sheet.

Repeating columns cover a range of contiguous columns, e.g.:

 Sheet1!$A:$A Sheet2!$C:$F
The parameter CellRangeAddress should specify a row part which spans all rows, and a column part which specifies the contiguous range of repeating columns, e.g.:
 sheet.setRepeatingColumns(CellRangeAddress.valueOf("B:C"));
A null parameter value indicates that repeating columns should be removed from the Sheet:
 sheet.setRepeatingColumns(null);

Usage

From source file:org.bbreak.excella.reports.util.ReportsUtil.java

License:Open Source License

/**
 * fromIdx??toIdx?????/*from  w  ww .  j a va2s  .com*/
 * @param workbook fromIdx?toIdx??workbook
 * @param fromIdx ?
 * @param sheet 
 */
public static void copyPrintSetup(Workbook workbook, int fromIdx, Sheet toSheet) {
    Sheet fromSheet = workbook.getSheetAt(fromIdx);
    // ?
    PrintSetup fromPrintSetup = fromSheet.getPrintSetup();
    PrintSetup printSetup = toSheet.getPrintSetup();
    printSetup.setCopies(fromPrintSetup.getCopies());
    printSetup.setDraft(fromPrintSetup.getDraft());
    printSetup.setFitHeight(fromPrintSetup.getFitHeight());
    printSetup.setFitWidth(fromPrintSetup.getFitWidth());
    printSetup.setFooterMargin(fromPrintSetup.getFooterMargin());
    printSetup.setHeaderMargin(fromPrintSetup.getHeaderMargin());
    printSetup.setHResolution(fromPrintSetup.getHResolution());
    printSetup.setLandscape(fromPrintSetup.getLandscape());
    printSetup.setLeftToRight(fromPrintSetup.getLeftToRight());
    printSetup.setNoColor(fromPrintSetup.getNoColor());
    printSetup.setNoOrientation(fromPrintSetup.getNoOrientation());
    printSetup.setPageStart(fromPrintSetup.getPageStart());
    printSetup.setPaperSize(fromPrintSetup.getPaperSize());
    printSetup.setScale(fromPrintSetup.getScale());
    printSetup.setUsePage(fromPrintSetup.getUsePage());
    printSetup.setValidSettings(fromPrintSetup.getValidSettings());
    printSetup.setVResolution(fromPrintSetup.getVResolution());
    // ?
    String printArea = workbook.getPrintArea(fromIdx);
    if (printArea != null) {
        if (printArea.contains("!")) {
            printArea = printArea.substring(printArea.indexOf("!") + 1);
        }
        int toIdx = workbook.getSheetIndex(toSheet);
        workbook.setPrintArea(toIdx, printArea);
    }
    // ?
    toSheet.setRepeatingColumns(fromSheet.getRepeatingColumns());
    toSheet.setRepeatingRows(fromSheet.getRepeatingRows());
}

From source file:packtest.WorkingWithPageSetup.java

License:Apache License

public static void main(String[] args) throws Exception {
    Workbook wb = new XSSFWorkbook(); //or new HSSFWorkbook();

    /**/*w  ww.ja v a2  s  .  c  o  m*/
     * It's possible to set up repeating rows and columns in your printouts by using the setRepeatingRowsAndColumns() function in the Workbook object.
     *
     * This function Contains 5 parameters:
     * The first parameter is the index to the sheet (0 = first sheet).
     * The second and third parameters specify the range for the columns to repreat.
     * To stop the columns from repeating pass in -1 as the start and end column.
     * The fourth and fifth parameters specify the range for the rows to repeat.
     * To stop the columns from repeating pass in -1 as the start and end rows.
     */
    Sheet sheet1 = wb.createSheet("new sheet");
    Sheet sheet2 = wb.createSheet("second sheet");

    // Set the columns to repeat from column 0 to 2 on the first sheet
    Row row1 = sheet1.createRow(0);
    row1.createCell(0).setCellValue(1);
    row1.createCell(1).setCellValue(2);
    row1.createCell(2).setCellValue(3);
    Row row2 = sheet1.createRow(1);
    row2.createCell(1).setCellValue(4);
    row2.createCell(2).setCellValue(5);

    Row row3 = sheet2.createRow(1);
    row3.createCell(0).setCellValue(2.1);
    row3.createCell(4).setCellValue(2.2);
    row3.createCell(5).setCellValue(2.3);
    Row row4 = sheet2.createRow(2);
    row4.createCell(4).setCellValue(2.4);
    row4.createCell(5).setCellValue(2.5);

    // Set the columns to repeat from column 0 to 2 on the first sheet
    sheet1.setRepeatingColumns(CellRangeAddress.valueOf("A:C"));
    // Set the the repeating rows and columns on the second sheet.
    CellRangeAddress cra = CellRangeAddress.valueOf("E2:F3");
    sheet2.setRepeatingColumns(cra);
    sheet2.setRepeatingRows(cra);

    //set the print area for the first sheet
    wb.setPrintArea(0, 1, 2, 0, 3);

    FileOutputStream fileOut = new FileOutputStream("xssf-printsetup.xlsx");
    wb.write(fileOut);
    fileOut.close();

    wb.close();
}