Search in sources :

Example 61 with Workbook

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

the class TestXSSFSheetRowGrouping method test55640.

//private int o_groupsNumber = 0;
public void test55640() throws IOException {
    //long startTime = System.currentTimeMillis();
    Workbook wb = new XSSFWorkbook();
    fillData(wb);
    writeToFile(wb);
//System.out.println("Number of groups: " + o_groupsNumber);
//System.out.println("Execution time: " + (System.currentTimeMillis()-startTime) + " ms");
}
Also used : Workbook(org.apache.poi.ss.usermodel.Workbook)

Example 62 with Workbook

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

the class TestXSSFSheetRowGrouping method verifyGroupCollapsedSpec.

private void verifyGroupCollapsedSpec(boolean level1, boolean level2, boolean level3, Boolean[] collapsed, boolean[] hidden, int[] outlineLevel) throws IOException {
    Workbook wb = new XSSFWorkbook();
    Sheet sheet = wb.createSheet("sheet123");
    for (int i = 5; i < 9; i++) {
        sheet.createRow(i);
    }
    sheet.groupRow(5, 6);
    sheet.groupRow(5, 7);
    sheet.groupRow(5, 8);
    sheet.setRowGroupCollapsed(6, level1);
    sheet.setRowGroupCollapsed(7, level2);
    sheet.setRowGroupCollapsed(8, level3);
    checkWorkbookGrouping(wb, collapsed, hidden, outlineLevel);
}
Also used : Sheet(org.apache.poi.ss.usermodel.Sheet) Workbook(org.apache.poi.ss.usermodel.Workbook)

Example 63 with Workbook

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

the class TestXSSFSheet method testRemoveRowWithCommentAndGapAbove.

// bug 59687:  XSSFSheet.RemoveRow doesn't handle row gaps properly when removing row comments
@Test
public void testRemoveRowWithCommentAndGapAbove() throws IOException {
    final Workbook wb = _testDataProvider.openSampleWorkbook("59687.xlsx");
    final Sheet sheet = wb.getSheetAt(0);
    // comment exists
    CellAddress commentCellAddress = new CellAddress("A4");
    assertNotNull(sheet.getCellComment(commentCellAddress));
    assertEquals("Wrong starting # of comments", 1, sheet.getCellComments().size());
    sheet.removeRow(sheet.getRow(commentCellAddress.getRow()));
    assertEquals("There should not be any comments left!", 0, sheet.getCellComments().size());
}
Also used : CellAddress(org.apache.poi.ss.util.CellAddress) BaseTestXSheet(org.apache.poi.ss.usermodel.BaseTestXSheet) Sheet(org.apache.poi.ss.usermodel.Sheet) XSSFTestDataSamples.openSampleWorkbook(org.apache.poi.xssf.XSSFTestDataSamples.openSampleWorkbook) SXSSFWorkbook(org.apache.poi.xssf.streaming.SXSSFWorkbook) Workbook(org.apache.poi.ss.usermodel.Workbook) Test(org.junit.Test)

Example 64 with Workbook

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

the class TestXSSFSheetRowGrouping method verifyGroupCollapsed.

private void verifyGroupCollapsed(boolean level1, boolean level2, boolean level3, Boolean[] collapsed, boolean[] hidden, int[] outlineLevel) throws IOException {
    Workbook wb = new XSSFWorkbook();
    Sheet sheet = wb.createSheet("sheet123");
    for (int i = 0; i < 4; i++) {
        sheet.createRow(i);
    }
    sheet.groupRow(0, 4);
    sheet.groupRow(1, 4);
    sheet.groupRow(2, 4);
    sheet.setRowGroupCollapsed(0, level1);
    sheet.setRowGroupCollapsed(1, level2);
    sheet.setRowGroupCollapsed(2, level3);
    checkWorkbookGrouping(wb, collapsed, hidden, outlineLevel);
}
Also used : Sheet(org.apache.poi.ss.usermodel.Sheet) Workbook(org.apache.poi.ss.usermodel.Workbook)

Example 65 with Workbook

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

the class TestXSSFSheetShiftRows method testBug53798a.

/** negative row shift causes corrupted data or throws exception */
@Test
public void testBug53798a() throws IOException {
    Workbook wb = XSSFTestDataSamples.openSampleWorkbook("53798.xlsx");
    Sheet testSheet = wb.getSheetAt(0);
    testSheet.shiftRows(3, 3, -1);
    for (Row r : testSheet) {
        r.getRowNum();
    }
    testSheet.shiftRows(6, 6, 1);
    Workbook read = XSSFTestDataSamples.writeOutAndReadBack(wb);
    wb.close();
    assertNotNull(read);
    Sheet readSheet = read.getSheetAt(0);
    verifyCellContent(readSheet, 0, "0.0");
    verifyCellContent(readSheet, 1, "1.0");
    verifyCellContent(readSheet, 2, "3.0");
    verifyCellContent(readSheet, 3, null);
    verifyCellContent(readSheet, 4, "4.0");
    verifyCellContent(readSheet, 5, "5.0");
    verifyCellContent(readSheet, 6, null);
    verifyCellContent(readSheet, 7, "6.0");
    verifyCellContent(readSheet, 8, "8.0");
    read.close();
}
Also used : Row(org.apache.poi.ss.usermodel.Row) Sheet(org.apache.poi.ss.usermodel.Sheet) Workbook(org.apache.poi.ss.usermodel.Workbook) POITestCase.skipTest(org.apache.poi.POITestCase.skipTest) Test(org.junit.Test)

Aggregations

Workbook (org.apache.poi.ss.usermodel.Workbook)319 Sheet (org.apache.poi.ss.usermodel.Sheet)224 Test (org.junit.Test)207 Cell (org.apache.poi.ss.usermodel.Cell)140 Row (org.apache.poi.ss.usermodel.Row)123 XSSFWorkbook (org.apache.poi.xssf.usermodel.XSSFWorkbook)104 HSSFWorkbook (org.apache.poi.hssf.usermodel.HSSFWorkbook)95 FileOutputStream (java.io.FileOutputStream)33 XSSFChart (org.apache.poi.xssf.usermodel.XSSFChart)32 ByteArrayInputStream (java.io.ByteArrayInputStream)30 FormulaEvaluator (org.apache.poi.ss.usermodel.FormulaEvaluator)30 XSSFDrawing (org.apache.poi.xssf.usermodel.XSSFDrawing)27 CTChart (org.openxmlformats.schemas.drawingml.x2006.chart.CTChart)27 File (java.io.File)26 CellStyle (org.apache.poi.ss.usermodel.CellStyle)25 InternalWorkbook (org.apache.poi.hssf.model.InternalWorkbook)24 LangYearFilterPagingRequest (org.devgateway.ocds.web.rest.controller.request.LangYearFilterPagingRequest)23 IOException (java.io.IOException)22 CellRangeAddress (org.apache.poi.ss.util.CellRangeAddress)18 FileInputStream (java.io.FileInputStream)15