Search in sources :

Example 16 with CTWorksheet

use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet in project poi by apache.

the class TestXSSFPrintSetup method testSetGetNotes.

public void testSetGetNotes() {
    CTWorksheet worksheet = CTWorksheet.Factory.newInstance();
    CTPageSetup pSetup = worksheet.addNewPageSetup();
    pSetup.setCellComments(STCellComments.NONE);
    XSSFPrintSetup printSetup = new XSSFPrintSetup(worksheet);
    assertEquals(false, printSetup.getNotes());
    printSetup.setNotes(true);
    assertEquals(PrintCellComments.AS_DISPLAYED.getValue(), pSetup.getCellComments().intValue());
}
Also used : CTWorksheet(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet) CTPageSetup(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPageSetup)

Example 17 with CTWorksheet

use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet in project poi by apache.

the class TestXSSFPrintSetup method testSetGetLeftToRight.

public void testSetGetLeftToRight() {
    CTWorksheet worksheet = CTWorksheet.Factory.newInstance();
    CTPageSetup pSetup = worksheet.addNewPageSetup();
    pSetup.setPageOrder(STPageOrder.DOWN_THEN_OVER);
    XSSFPrintSetup printSetup = new XSSFPrintSetup(worksheet);
    assertEquals(false, printSetup.getLeftToRight());
    printSetup.setLeftToRight(true);
    assertEquals(PageOrder.OVER_THEN_DOWN.getValue(), pSetup.getPageOrder().intValue());
}
Also used : CTWorksheet(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet) CTPageSetup(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPageSetup)

Example 18 with CTWorksheet

use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet in project poi by apache.

the class TestXSSFSheet method removeMergedRegion_lowlevel.

@Test
public void removeMergedRegion_lowlevel() throws IOException {
    XSSFWorkbook workbook = new XSSFWorkbook();
    XSSFSheet sheet = workbook.createSheet();
    CTWorksheet ctWorksheet = sheet.getCTWorksheet();
    CellRangeAddress region_1 = CellRangeAddress.valueOf("A1:B2");
    CellRangeAddress region_2 = CellRangeAddress.valueOf("C3:D4");
    CellRangeAddress region_3 = CellRangeAddress.valueOf("E5:F6");
    CellRangeAddress region_4 = CellRangeAddress.valueOf("G7:H8");
    sheet.addMergedRegion(region_1);
    sheet.addMergedRegion(region_2);
    sheet.addMergedRegion(region_3);
    assertEquals("C3:D4", ctWorksheet.getMergeCells().getMergeCellArray(1).getRef());
    assertEquals(3, sheet.getNumMergedRegions());
    sheet.removeMergedRegion(1);
    assertEquals("E5:F6", ctWorksheet.getMergeCells().getMergeCellArray(1).getRef());
    assertEquals(2, sheet.getNumMergedRegions());
    sheet.removeMergedRegion(1);
    sheet.removeMergedRegion(0);
    assertEquals(0, sheet.getNumMergedRegions());
    assertNull(" CTMergeCells should be deleted after removing the last merged " + "region on the sheet.", sheet.getCTWorksheet().getMergeCells());
    sheet.addMergedRegion(region_1);
    sheet.addMergedRegion(region_2);
    sheet.addMergedRegion(region_3);
    sheet.addMergedRegion(region_4);
    // test invalid indexes OOBE
    Set<Integer> rmIdx = new HashSet<Integer>(Arrays.asList(5, 6));
    sheet.removeMergedRegions(rmIdx);
    rmIdx = new HashSet<Integer>(Arrays.asList(1, 3));
    sheet.removeMergedRegions(rmIdx);
    assertEquals("A1:B2", ctWorksheet.getMergeCells().getMergeCellArray(0).getRef());
    assertEquals("E5:F6", ctWorksheet.getMergeCells().getMergeCellArray(1).getRef());
    workbook.close();
}
Also used : CTWorksheet(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet) SXSSFWorkbook(org.apache.poi.xssf.streaming.SXSSFWorkbook) CellRangeAddress(org.apache.poi.ss.util.CellRangeAddress) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 19 with CTWorksheet

use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet in project poi by apache.

the class TestXSSFSheet method setDefaultColumnStyle.

@Test
public void setDefaultColumnStyle() throws IOException {
    XSSFWorkbook workbook = new XSSFWorkbook();
    XSSFSheet sheet = workbook.createSheet();
    CTWorksheet ctWorksheet = sheet.getCTWorksheet();
    StylesTable stylesTable = workbook.getStylesSource();
    XSSFFont font = new XSSFFont();
    font.setFontName("Cambria");
    stylesTable.putFont(font);
    CTXf cellStyleXf = CTXf.Factory.newInstance();
    cellStyleXf.setFontId(1);
    cellStyleXf.setFillId(0);
    cellStyleXf.setBorderId(0);
    cellStyleXf.setNumFmtId(0);
    stylesTable.putCellStyleXf(cellStyleXf);
    CTXf cellXf = CTXf.Factory.newInstance();
    cellXf.setXfId(1);
    stylesTable.putCellXf(cellXf);
    XSSFCellStyle cellStyle = new XSSFCellStyle(1, 1, stylesTable, null);
    assertEquals(1, cellStyle.getFontIndex());
    sheet.setDefaultColumnStyle(3, cellStyle);
    assertEquals(1, ctWorksheet.getColsArray(0).getColArray(0).getStyle());
    workbook.close();
}
Also used : CTXf(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTXf) CTWorksheet(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet) StylesTable(org.apache.poi.xssf.model.StylesTable) SXSSFWorkbook(org.apache.poi.xssf.streaming.SXSSFWorkbook) Test(org.junit.Test)

Example 20 with CTWorksheet

use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet in project poi by apache.

the class TestXSSFSheet method createFreezePane_XSSF.

@Test
public void createFreezePane_XSSF() throws IOException {
    XSSFWorkbook workbook = new XSSFWorkbook();
    XSSFSheet sheet = workbook.createSheet();
    CTWorksheet ctWorksheet = sheet.getCTWorksheet();
    sheet.createFreezePane(2, 4);
    assertEquals(2.0, ctWorksheet.getSheetViews().getSheetViewArray(0).getPane().getXSplit(), 0.0);
    assertEquals(STPane.BOTTOM_RIGHT, ctWorksheet.getSheetViews().getSheetViewArray(0).getPane().getActivePane());
    sheet.createFreezePane(3, 6, 10, 10);
    assertEquals(3.0, ctWorksheet.getSheetViews().getSheetViewArray(0).getPane().getXSplit(), 0.0);
    //    assertEquals(10, sheet.getTopRow());
    //    assertEquals(10, sheet.getLeftCol());
    sheet.createSplitPane(4, 8, 12, 12, 1);
    assertEquals(8.0, ctWorksheet.getSheetViews().getSheetViewArray(0).getPane().getYSplit(), 0.0);
    assertEquals(STPane.BOTTOM_RIGHT, ctWorksheet.getSheetViews().getSheetViewArray(0).getPane().getActivePane());
    workbook.close();
}
Also used : CTWorksheet(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet) SXSSFWorkbook(org.apache.poi.xssf.streaming.SXSSFWorkbook) Test(org.junit.Test)

Aggregations

CTWorksheet (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet)32 CTPageSetup (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPageSetup)13 Test (org.junit.Test)11 CTCol (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCol)7 SXSSFWorkbook (org.apache.poi.xssf.streaming.SXSSFWorkbook)6 CTCols (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCols)6 POIXMLException (org.apache.poi.POIXMLException)2 InvalidFormatException (org.apache.poi.openxml4j.exceptions.InvalidFormatException)2 PackageRelationship (org.apache.poi.openxml4j.opc.PackageRelationship)2 CellRangeAddress (org.apache.poi.ss.util.CellRangeAddress)2 StylesTable (org.apache.poi.xssf.model.StylesTable)2 XSSFSheet (org.apache.poi.xssf.usermodel.XSSFSheet)2 XSSFWorkbook (org.apache.poi.xssf.usermodel.XSSFWorkbook)2 CTXf (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTXf)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 QName (javax.xml.namespace.QName)1