Package org.apache.poi.ss.usermodel

Examples of org.apache.poi.ss.usermodel.Sheet


     * @throws Exception if occur
     */
    @Test
    public void extractNullityCondition() throws Exception {
        ExcelRuleExtractor extractor = new DefaultExcelRuleExtractor();
        Sheet sheet = sheet("nullity.xls");
        assertThat(extractor.extractNullityCondition(sheet.getRow(3)), is(NullityConditionKind.NORMAL));
        assertThat(extractor.extractNullityCondition(sheet.getRow(4)), is(NullityConditionKind.ACCEPT_ABSENT));
        assertThat(extractor.extractNullityCondition(sheet.getRow(5)), is(NullityConditionKind.DENY_ABSENT));
        assertThat(extractor.extractNullityCondition(sheet.getRow(6)), is(NullityConditionKind.ACCEPT_PRESENT));
        assertThat(extractor.extractNullityCondition(sheet.getRow(7)), is(NullityConditionKind.DENY_PRESENT));
    }
View Full Code Here


     
    Workbook workbook = new HSSFWorkbook();
     
    for (int cnt=0; cnt<tests.size(); cnt++) {
      setColumns(tests.get(cnt));
      Sheet sheet = workbook.createSheet("Test " + cnt);
      Row row = sheet.createRow(0);

      int counter = 2; //A counter which is used to determine how many additional columns are needed.
      createCell(workbook, row, 0, "Grupa", CellStyle.ALIGN_CENTER, CellStyle.VERTICAL_CENTER);
      createCell(workbook, row, 1, "Indeks", CellStyle.ALIGN_CENTER, CellStyle.VERTICAL_CENTER);
      createCell(workbook, row, 2, "Naziv Fajla", CellStyle.ALIGN_CENTER, CellStyle.VERTICAL_CENTER);     
      if (bInput) {
        createCell(workbook, row, counter+1, "Ulaz", CellStyle.ALIGN_CENTER, CellStyle.VERTICAL_CENTER);
        counter++;
      }
      if (bOutput) {
        createCell(workbook, row, counter+1, "Izlaz", CellStyle.ALIGN_CENTER, CellStyle.VERTICAL_CENTER);
        counter++;
      }
      if (bTimeLimit) {
        createCell(workbook, row, counter+1, "Vremensko Ogranicenje", CellStyle.ALIGN_CENTER, CellStyle.VERTICAL_CENTER);
        counter++;
      }
      if (bMemory) {
        createCell(workbook, row, counter+1, "Zauzece Memorije", CellStyle.ALIGN_CENTER, CellStyle.VERTICAL_CENTER);
        counter++;
      }
      if (bCPUTime) {
        createCell(workbook, row, counter+1, "CPU Vreme", CellStyle.ALIGN_CENTER, CellStyle.VERTICAL_CENTER);
        counter++;
      }
      if (bThreadNumber) {
        createCell(workbook, row, counter+1, "Broj Niti", CellStyle.ALIGN_CENTER, CellStyle.VERTICAL_CENTER);
        counter++;
      }
      if (bHandlers) {
        createCell(workbook, row, counter+1, "Rukovaoci Greskama", CellStyle.ALIGN_CENTER, CellStyle.VERTICAL_CENTER);
        counter++;
      }
      if (bProcessID) {
        createCell(workbook, row, counter+1, "Proces ID", CellStyle.ALIGN_CENTER, CellStyle.VERTICAL_CENTER);
        counter++;
      }     
      createCell(workbook, row, counter+1, "Uspesno/Neuspesno", CellStyle.ALIGN_CENTER, CellStyle.VERTICAL_CENTER);
      createCell(workbook, row, counter+2, "Komentar", CellStyle.ALIGN_CENTER, CellStyle.VERTICAL_CENTER);
     
      for (int i=0; i<counter+3; i++) {
        sheet.autoSizeColumn(i);
      }
    }
     
    try {
      FileOutputStream fileOutput = new FileOutputStream(reportFile + ".xls");
View Full Code Here

   
    try {
     
      InputStream input = new FileInputStream(file);
      Workbook workbook = WorkbookFactory.create(input);
      Sheet sheet = workbook.getSheetAt(testListPosition);
      Row row = sheet.createRow(assigNumber);
     
      int lastColumn = sheet.getRow(0).getPhysicalNumberOfCells();     
      for (int cn=0; cn<lastColumn; cn++) {
        Cell cell = row.getCell(cn, Row.RETURN_BLANK_AS_NULL);
        if (cell == null) {
          cell = row.createCell(cn);
          cell.setCellType(Cell.CELL_TYPE_STRING);
View Full Code Here

    public Schema createSchema(InputStream inputStream, String schemaName) {
        final MutableSchema schema = new MutableSchema(schemaName);
        final Workbook wb = ExcelUtils.readWorkbook(inputStream);

        for (int i = 0; i < wb.getNumberOfSheets(); i++) {
            final Sheet currentSheet = wb.getSheetAt(i);
            final MutableTable table = createTable(wb, currentSheet);
            table.setSchema(schema);
            schema.addTable(table);
        }
View Full Code Here

    }

    @Override
    public DataSet executeQuery(InputStream inputStream, Table table, Column[] columns, int maxRows) {
        final Workbook wb = ExcelUtils.readWorkbook(inputStream);
        final Sheet sheet = wb.getSheet(table.getName());

        if (sheet == null || sheet.getPhysicalNumberOfRows() == 0) {
            return new EmptyDataSet(columns);
        }

        DataSet dataSet = ExcelUtils.getDataSet(wb, sheet, table, _configuration);
View Full Code Here

        final Workbook workbook = _updateCallback.getWorkbook(false);

        final String tableName = getTable().getName();
        final SelectItem[] selectItems = MetaModelHelper.createSelectItems(getTable().getColumns());
        final DataSetHeader header = new SimpleDataSetHeader(selectItems);
        final Sheet sheet = workbook.getSheet(tableName);

        final Iterator<Row> rowIterator = ExcelUtils.getRowIterator(sheet, _updateCallback.getConfiguration(), true);
        final List<Row> rowsToDelete = new ArrayList<Row>();
        while (rowIterator.hasNext()) {
            final Row excelRow = rowIterator.next();
            final DefaultRow row = ExcelUtils.createRow(workbook, excelRow, header);

            final boolean deleteRow = deleteRow(row);
            if (deleteRow) {
                rowsToDelete.add(excelRow);
            }
        }

        // reverse the list to not mess up any row numbers
        Collections.reverse(rowsToDelete);

        for (Row row : rowsToDelete) {
            sheet.removeRow(row);
        }
    }
View Full Code Here

public class ZeroBasedRowIteratorTest extends TestCase {

  public void testHasNext() throws Exception {
    Workbook workbook = WorkbookFactory.create(new FileInputStream(
        "src/test/resources/xls_single_cell_sheet.xls"));
    Sheet sheet = workbook.getSheetAt(0);

    // POI's row numbers are 0-based also - the last cell in the sheet is
    // actually A6.
    assertEquals(5, sheet.getLastRowNum());

    ZeroBasedRowIterator it = new ZeroBasedRowIterator(sheet);

    assertTrue(it.hasNext());
    assertNull(it.next());
View Full Code Here

    @Override
    public Table execute() {
        final ExcelUpdateCallback updateCallback = getUpdateCallback();
        final MutableTable table = getTable();

        final Sheet sheet = updateCallback.createSheet(table.getName());

        final int lineNumber = updateCallback.getConfiguration().getColumnNameLineNumber();
        if (lineNumber != ExcelConfiguration.NO_COLUMN_NAME_LINE) {
            final int zeroBasedLineNumber = lineNumber - 1;
            final Row row = sheet.createRow(zeroBasedLineNumber);
            final Column[] columns = table.getColumns();
            for (int i = 0; i < columns.length; i++) {
                final Column column = columns[i];
                final int columnNumber = column.getColumnNumber();
                row.createCell(columnNumber).setCellValue(column.getName());
View Full Code Here

        File.separator + "WithVariousData.xlsx"
    );
    assertTrue(xml.exists());
     
    XSSFWorkbook workbook = new XSSFWorkbook(xml.toString());
    Sheet sheet1 = workbook.getSheetAt(0);
    Sheet sheet2 = workbook.getSheetAt(1);
   
    assertTrue( ((XSSFSheet)sheet1).hasComments() );
    assertFalse( ((XSSFSheet)sheet2).hasComments() );
   
    // Comments should be in C5 and C7
View Full Code Here

        File.separator + "WithVariousData.xlsx"
    );
    assertTrue(xml.exists());
     
    XSSFWorkbook workbook = new XSSFWorkbook(xml.toString());
    Sheet sheet1 = workbook.getSheetAt(0);
    XSSFSheet sheet2 = (XSSFSheet)workbook.getSheetAt(1);
   
    assertTrue( ((XSSFSheet)sheet1).hasComments() );
    assertFalse( ((XSSFSheet)sheet2).hasComments() );
   
    // Change on comment on sheet 1, and add another into
    //  sheet 2
    Row r5 = sheet1.getRow(4);
    Comment cc5 = r5.getCell(2).getCellComment();
    cc5.setAuthor("Apache POI");
    cc5.setString(new XSSFRichTextString("Hello!"));
   
    Row r2s2 = sheet2.createRow(2);
    Cell c1r2s2 = r2s2.createCell(1);
    assertNull(c1r2s2.getCellComment());
   
    Comment cc2 = sheet2.createComment();
    cc2.setAuthor("Also POI");
    cc2.setString(new XSSFRichTextString("A new comment"));
    c1r2s2.setCellComment(cc2);
   
   
    // Save, and re-load the file
        workbook = XSSFTestDataSamples.writeOutAndReadBack(workbook);

    // Check we still have comments where we should do
    sheet1 = workbook.getSheetAt(0);
    sheet2 = (XSSFSheet)workbook.getSheetAt(1);
    assertNotNull(sheet1.getRow(4).getCell(2).getCellComment());
    assertNotNull(sheet1.getRow(6).getCell(2).getCellComment());
    assertNotNull(sheet2.getRow(2).getCell(1).getCellComment());
   
    // And check they still have the contents they should do
    assertEquals("Apache POI",
        sheet1.getRow(4).getCell(2).getCellComment().getAuthor());
    assertEquals("Nick Burch",
        sheet1.getRow(6).getCell(2).getCellComment().getAuthor());
    assertEquals("Also POI",
        sheet2.getRow(2).getCell(1).getCellComment().getAuthor());
   
    assertEquals("Nick Burch:\nThis is a comment",
        sheet1.getRow(4).getCell(2).getCellComment().getString().getString());
  }
View Full Code Here

TOP

Related Classes of org.apache.poi.ss.usermodel.Sheet

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.