Search in sources :

Example 1 with PrintSetup

use of org.apache.poi.ss.usermodel.PrintSetup in project poi by apache.

the class FitSheetToOnePage method main.

public static void main(String[] args) throws IOException {
    //or new HSSFWorkbook();
    Workbook wb = new XSSFWorkbook();
    Sheet sheet = wb.createSheet("format sheet");
    PrintSetup ps = sheet.getPrintSetup();
    sheet.setAutobreaks(true);
    ps.setFitHeight((short) 1);
    ps.setFitWidth((short) 1);
    // Create various cells and rows for spreadsheet.
    FileOutputStream fileOut = new FileOutputStream("fitSheetToOnePage.xlsx");
    wb.write(fileOut);
    fileOut.close();
    wb.close();
}
Also used : FileOutputStream(java.io.FileOutputStream) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) PrintSetup(org.apache.poi.ss.usermodel.PrintSetup) Sheet(org.apache.poi.ss.usermodel.Sheet) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) Workbook(org.apache.poi.ss.usermodel.Workbook)

Example 2 with PrintSetup

use of org.apache.poi.ss.usermodel.PrintSetup in project poi by apache.

the class TestSXSSFBugs method bug49253.

/**
     * Setting repeating rows and columns shouldn't break
     *  any print settings that were there before
     */
@Test
public void bug49253() throws Exception {
    Workbook wb1 = new SXSSFWorkbook();
    Workbook wb2 = new SXSSFWorkbook();
    CellRangeAddress cra = CellRangeAddress.valueOf("C2:D3");
    // No print settings before repeating
    Sheet s1 = wb1.createSheet();
    s1.setRepeatingColumns(cra);
    s1.setRepeatingRows(cra);
    PrintSetup ps1 = s1.getPrintSetup();
    assertEquals(false, ps1.getValidSettings());
    assertEquals(false, ps1.getLandscape());
    // Had valid print settings before repeating
    Sheet s2 = wb2.createSheet();
    PrintSetup ps2 = s2.getPrintSetup();
    ps2.setLandscape(false);
    assertEquals(true, ps2.getValidSettings());
    assertEquals(false, ps2.getLandscape());
    s2.setRepeatingColumns(cra);
    s2.setRepeatingRows(cra);
    ps2 = s2.getPrintSetup();
    assertEquals(true, ps2.getValidSettings());
    assertEquals(false, ps2.getLandscape());
    wb1.close();
    wb2.close();
}
Also used : SXSSFWorkbook(org.apache.poi.xssf.streaming.SXSSFWorkbook) PrintSetup(org.apache.poi.ss.usermodel.PrintSetup) CellRangeAddress(org.apache.poi.ss.util.CellRangeAddress) Sheet(org.apache.poi.ss.usermodel.Sheet) SXSSFWorkbook(org.apache.poi.xssf.streaming.SXSSFWorkbook) Workbook(org.apache.poi.ss.usermodel.Workbook) Test(org.junit.Test)

Aggregations

PrintSetup (org.apache.poi.ss.usermodel.PrintSetup)2 Sheet (org.apache.poi.ss.usermodel.Sheet)2 Workbook (org.apache.poi.ss.usermodel.Workbook)2 FileOutputStream (java.io.FileOutputStream)1 CellRangeAddress (org.apache.poi.ss.util.CellRangeAddress)1 SXSSFWorkbook (org.apache.poi.xssf.streaming.SXSSFWorkbook)1 XSSFWorkbook (org.apache.poi.xssf.usermodel.XSSFWorkbook)1 Test (org.junit.Test)1