Package org.apache.poi.xssf.usermodel

Examples of org.apache.poi.xssf.usermodel.XSSFWorkbook


        ExcelPrinter.logger.warn("Unable to read predefined xls-data.", e);
      }
    }
    if (isUseXlsxFormat())
    {
      return new XSSFWorkbook();
    }
    else
    {
      return new HSSFWorkbook();
    }
View Full Code Here


    this.dataFormat = workbook.createDataFormat();
    this.hardLimit = hardLimit;

    if (workbook instanceof XSSFWorkbook)
    {
      final XSSFWorkbook xssfWorkbook = (XSSFWorkbook) workbook;
      final short predefinedStyles = workbook.getNumCellStyles();
      for (short i = 0; i < predefinedStyles; i++)
      {
        final XSSFCellStyle cellStyleAt = xssfWorkbook.getCellStyleAt(i);
        this.styleCache.put(new HSSFCellStyleKey(cellStyleAt), cellStyleAt);
      }
    }
    else
    {
View Full Code Here

      bis = new BufferedInputStream(leaf.getInputStream());
      POIXMLTextExtractor extractor = (POIXMLTextExtractor) ExtractorFactory.createExtractor(bis);
      POIXMLDocument document = extractor.getDocument();

      if (document instanceof XSSFWorkbook) {
        XSSFWorkbook xDocument = (XSSFWorkbook) document;
        extractContent(buffy, xDocument);
      }

      return buffy.toString();
    } catch (Exception e) {
View Full Code Here

        Workbook result;
        try {
            ByteArrayOutputStream baos = new ByteArrayOutputStream(8192);
            wb.write(baos);
            InputStream is = new ByteArrayInputStream(baos.toByteArray());
            result = new XSSFWorkbook(is);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        return result;
    }
View Full Code Here

* Illustrates how to create a simple scatter chart.
*/
public class ScatterChart {

  public static void main(String[]args) throws Exception {
    Workbook wb = new XSSFWorkbook();
    CreationHelper creationHelper = wb.getCreationHelper();
    Sheet sheet = wb.createSheet("Sheet 1");
    final int NUM_OF_ROWS = 3;
    final int NUM_OF_COLUMNS = 10;

    // Create a row and put some cells in it. Rows are 0 based.
    Row row;
    Cell cell;
    for (int rowIndex = 0; rowIndex < NUM_OF_ROWS; rowIndex++) {
      row = sheet.createRow((short)rowIndex);
      for (int colIndex = 0; colIndex < NUM_OF_COLUMNS; colIndex++) {
        cell = row.createCell((short)colIndex);
        cell.setCellValue(colIndex * (rowIndex + 1));
      }
    }

    Drawing drawing = sheet.createDrawingPatriarch();
    ClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 0, 5, 10, 15);

    Chart chart = drawing.createChart(anchor);
    ChartLegend legend = chart.getOrCreateLegend();
    legend.setPosition(LegendPosition.TOP_RIGHT);

    ScatterChartData data = chart.getChartDataFactory().createScatterChartData();

    ValueAxis bottomAxis = chart.getChartAxisFactory().createValueAxis(AxisPosition.BOTTOM);
    ValueAxis leftAxis = chart.getChartAxisFactory().createValueAxis(AxisPosition.LEFT);

    ScatterChartSerie firstSerie = data.addSerie();
    firstSerie.setXValues(sheet, new CellRangeAddress(0, 0, 0, NUM_OF_COLUMNS - 1));
    firstSerie.setYValues(sheet, new CellRangeAddress(1, 1, 0, NUM_OF_COLUMNS - 1));

    ScatterChartSerie secondSerie = data.addSerie();
    secondSerie.setXValues(sheet, new CellRangeAddress(0, 0, 0, NUM_OF_COLUMNS - 1));
    secondSerie.setYValues(sheet, new CellRangeAddress(2, 2, 0, NUM_OF_COLUMNS - 1));

    chart.plot(data, bottomAxis, leftAxis);

    // Write the output to a file
    FileOutputStream fileOut = new FileOutputStream("ooxml-scatter-chart.xlsx");
    wb.write(fileOut);
    fileOut.close();
  }
View Full Code Here

  @Override
  public void processExport(OutputStream output) {

    try {
      XSSFWorkbook workbook = new XSSFWorkbook();
      XSSFSheet sheet = workbook.createSheet(exportConf.getFileName());
      Row row = null;
      Cell cell = null;
      int rowIndex = 0;
      int columnIndex;

      // Header
      if (exportConf.getIncludeHeader()) {

        for (HtmlRow htmlRow : table.getHeadRows()) {

          row = sheet.createRow(rowIndex++);
          columnIndex = 0;

          for (HtmlColumn column : htmlRow.getColumns(ReservedFormat.ALL, ReservedFormat.XLSX)) {
            cell = row.createCell(columnIndex++);
            cell.setCellValue(column.getContent().toString());
          }
        }
      }

      // Body
      for (HtmlRow htmlRow : table.getBodyRows()) {

        row = sheet.createRow(rowIndex++);
        columnIndex = 0;

        for (HtmlColumn column : htmlRow.getColumns(ReservedFormat.ALL, ReservedFormat.XLSX)) {
          cell = row.createCell(columnIndex++);
          cell.setCellValue(column.getContent().toString());
        }
      }

      // Column auto-sizing
      for (columnIndex = 0; columnIndex < table.getLastHeaderRow().getColumns(ReservedFormat.ALL, ReservedFormat.XLSX).size(); columnIndex++) {
        if (exportConf.getAutoSize()) {
          sheet.autoSizeColumn(columnIndex);
        }
      }

      workbook.write(output);
    } catch (IOException e) {
      StringBuilder sb = new StringBuilder("Something went wrong during the XLSX generation of the table '");
      sb.append(table.getOriginalId());
      sb.append("' and with the following export configuration: ");
      sb.append(exportConf.toString());
View Full Code Here

    // TODO: this should be done by Tika, the extractors should be split.
    private Workbook createWorkbook(URI document, InputStream is) throws IOException {
        final String documentURI = document.toString();
        if(documentURI.endsWith(".xlsx")) {
            return new XSSFWorkbook(is);
        } else if(documentURI.endsWith("xls")) {
            return new HSSFWorkbook(is);
        } else {
            throw new IllegalArgumentException("Unsupported extension for resource [" + documentURI + "]");
        }
View Full Code Here

        }
        switch (version) {
        case EXCEL97:
            return new HSSFWorkbook();
        case EXCEL2007:
            return new XSSFWorkbook();
        default:
            throw new IOException(MessageFormat.format(
                    "サポートしていないExcelワークブックの形式です: {0}",
                    version));
        }
View Full Code Here

        InputStream in = new FileInputStream(file);
        try {
            if (file.getName().endsWith(".xls")) {
                return new HSSFWorkbook(in);
            } else if (file.getName().endsWith(".xlsx")) {
                return new XSSFWorkbook(in);
            } else {
                throw new IOException(file.getPath());
            }
        } finally {
            in.close();
View Full Code Here

    static Workbook openWorkbookFor(String path, InputStream input) throws IOException {
        if (isHssf(path)) {
            return new HSSFWorkbook(input);
        } else if (isXssf(path)) {
            return new XSSFWorkbook(input);
        } else {
            return new HSSFWorkbook(input);
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.poi.xssf.usermodel.XSSFWorkbook

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.