Examples of Workbook


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

        catch (URISyntaxException e) {
            throw new AssertionError(e);
        }
        InputStream in = resource.openStream();
        try {
            Workbook book = Util.openWorkbookFor(file, in);
            Sheet sheet = book.getSheetAt(0);
            return new ExcelSheetDataModelSource(SIMPLE, uri, sheet);
        } finally {
            in.close();
        }
    }
View Full Code Here

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

    private Sheet sheet(String name) {
        InputStream in = getClass().getResourceAsStream(name);
        assertThat(name, in, not(nullValue()));
        try {
            Workbook book = new HSSFWorkbook(in);
            return book.getSheetAt(0);
        } catch (IOException e) {
            throw new AssertionError(e);
        } finally {
            try {
                in.close();
View Full Code Here

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

        if (parent != null && parent.isDirectory() == false && parent.mkdirs() == false) {
            throw new IOException(MessageFormat.format(
                    "Failed to create an output directory for {0}",
                    output));
        }
        final Workbook workbook = Util.createEmptyWorkbookFor(output.getPath());
        Sheet sheet = workbook.createSheet("results");
        return new ExcelSheetSink(definition, sheet, version.getMaxColumns()) {
            private boolean closed = false;
            @Override
            public void close() throws IOException {
                if (closed) {
                    return;
                }
                closed = true;
                LOG.info("Generating job result into {}", output);
                OutputStream stream = new FileOutputStream(output);
                try {
                    workbook.write(stream);
                } finally {
                    stream.close();
                }
            }
        };
View Full Code Here

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

        }

        LOG.debug("Processing Excel workbook: {}", source);
        URL url = source.toURL();
        InputStream in = url.openStream();
        Workbook book;
        try {
            InputStream bin = new BufferedInputStream(in);
            book = openWorkbookFor(path, bin);
            bin.close();
        } catch (IOException e) {
            throw new IOException(MessageFormat.format(
                    "Excelファイルの展開に失敗しました: {0}",
                    source));
        } finally {
            in.close();
        }

        if (matcher.group(1) != null) {
            int sheetNumber = Integer.parseInt(matcher.group(1));
            LOG.debug("Opening sheet by index : {}", sheetNumber);
            try {
                Sheet sheet = book.getSheetAt(sheetNumber);
                assert sheet != null;
                return sheet;
            } catch (RuntimeException e) {
                throw new IOException(MessageFormat.format(
                        "Excelシートの展開に失敗しました: {0} (シート{1}番がありません)",
                        source,
                        sheetNumber), e);
            }
        } else {
            String sheetName = matcher.group(2);
            LOG.debug("Opening sheet by name : {}", sheetName);
            assert sheetName != null;
            Sheet sheet = book.getSheet(sheetName);
            if (sheet == null) {
                throw new IOException(MessageFormat.format(
                        "Excelシートの展開に失敗しました: {0} (シート\"{1}\"がありません)",
                        source,
                        sheetName));
View Full Code Here

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

        return null;
    }

    private void evaluateInCell(Cell cell) throws IOException {
        try {
            Workbook workbook = cell.getSheet().getWorkbook();
            FormulaEvaluator formulaEvaluator = workbook.getCreationHelper().createFormulaEvaluator();
            formulaEvaluator.evaluateInCell(cell);
        } catch (RuntimeException e) {
            throw new IOException(MessageFormat.format(
                    "セルの数式を計算できませんでした: (pos=({1}, {2}), id={0})",
                    id,
View Full Code Here

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

   * Creates an XLSX or an XLS type file using apache poi library depending on the extension.
   * Only the first row of every sheet is initialized.
   */
  public void createFile(LinkedList<String> tests) {
     
    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");
      workbook.write(fileOutput);
      fileOutput.close();
    } catch (FileNotFoundException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (IOException e) {
View Full Code Here

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

  public void writeNewData(String file, int assigNumber, int testListPosition, String ... argument) {
   
    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);
          cell.setCellValue(argument[cn]);
        }
      }
     
      FileOutputStream fileOutput = new FileOutputStream(file);
      workbook.write(fileOutput);

      input.close();
      fileOutput.close();
     
    } catch (FileNotFoundException e) {
View Full Code Here

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

    }

    @Override
    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

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

        return schema;
    }

    @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);
        }
View Full Code Here

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

        _updateCallback.close();

        // read the workbook without streaming, since this will not wrap it in a
        // streaming workbook implementation (which do not support random
        // accessing rows).
        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();
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.