Package org.apache.poi.ss.usermodel

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


  }
 
  private Workbook newWorkbookFrom( InputStream inputStream ) throws IOException
  {
    //
    Workbook retval = null;
   
    //
    if ( this.useXLSXFileFormat() )
    {
      retval = new XSSFWorkbook( inputStream );
View Full Code Here


  }
 
  private Workbook newWorkbookToWrite()
  {
    //
    Workbook retval = null;
   
    //
    if ( this.useXLSXFileFormat() )
    {
      retval = new SXSSFWorkbook();
View Full Code Here

  /**
   * Stores the data from the object onto disk.
   */
  public void store()
  {
    Workbook wb = this.newWorkbookToWrite();
    CreationHelper createHelper = wb.getCreationHelper();
    Sheet sheet = wb.createSheet( "all" );
   
    int lineNumber = 0;
    for ( TableRow iLine : this.tableRowList )
    {
      //
      Row row = sheet.createRow( lineNumber++ );
     
      //
      int cellIndex = 0;
      for ( String iCellText : iLine )
      {
        Cell cell = row.createCell( cellIndex++ );
        cell.setCellValue( createHelper.createRichTextString( iCellText ) );
      }
    }
   
    try
    {
      final FileOutputStream fileOutputStream = new FileOutputStream( this.file );
      final OutputStream outputStream = new BufferedOutputStream( fileOutputStream );
      wb.write( outputStream );
      outputStream.close();
      fileOutputStream.close();
    }
    catch ( FileNotFoundException e )
    {
View Full Code Here

     * Creates a new cell style in the spreadsheet
     *
     * @return
     */
    public CellStyle createCellStyle() {
        Workbook workbook = getWorkbook(true);
        return workbook.createCellStyle();
    }
View Full Code Here

        Workbook workbook = getWorkbook(true);
        return workbook.createCellStyle();
    }

    public Font createFont() {
        Workbook workbook = getWorkbook(true);
        return workbook.createFont();
    }
View Full Code Here

     *
     * @return
     */
    public short getDateCellFormat() {
        if (_dateCellFormat == null) {
            Workbook workbook = getWorkbook(true);
            _dateCellFormat = workbook.getCreationHelper().createDataFormat().getFormat("m/d/yy h:mm");
        }
        return _dateCellFormat;
    }
View Full Code Here

        }
        return _dateCellStyle;
    }

    public short getColorIndex(Color color) {
        Workbook workbook = getWorkbook(true);
        if (workbook instanceof HSSFWorkbook) {
            HSSFPalette palette = ((HSSFWorkbook) workbook).getCustomPalette();
            byte r = toRgb(color.getRed());
            byte g = toRgb(color.getGreen());
            byte b = toRgb(color.getBlue());

            HSSFColor index = palette.findColor(r, g, b);
            if (index == null) {
                index = palette.findSimilarColor(r, g, b);
            }
            return index.getIndex();
        }
        throw new IllegalStateException("Unexpected workbook type: " + workbook.getClass());
    }
View Full Code Here

      if (Thread.currentThread().isInterrupted())
      {
        return;
      }

      final Workbook workbook = WorkbookFactory.create(new ByteArrayInputStream(bout.toByteArray()));
      int sheetIndex = 0;
      if (workbook.getNumberOfSheets() > 1)
      {
        final SheetSelectorDialog selectorDialog = new SheetSelectorDialog(workbook, parent);
        if (selectorDialog.performSelection())
        {
          sheetIndex = selectorDialog.getSelectedIndex();
        }
        else
        {
          return;
        }
      }

      final TypedTableModel tableModel = new TypedTableModel();
      final Sheet sheet = workbook.getSheetAt(sheetIndex);
      final Iterator rowIterator = sheet.rowIterator();

      if (firstRowIsHeader)
      {
        if (rowIterator.hasNext())
View Full Code Here

            InputStream in,
            ExtractionResult er
    ) throws IOException, ExtractionException {
        try {
            final URI documentURI = context.getDocumentURI();
            final Workbook workbook = createWorkbook(documentURI, in);
            processWorkbook(documentURI, workbook, er);
        } catch (Exception e) {
            throw new ExtractionException("An error occurred while extracting MS Excel content.", e);
        }
    }
View Full Code Here

         * But first delete an existing file
         */
        File file = new File("test1.xls");

        FileInputStream fis = new FileInputStream(file);
        Workbook wb = new HSSFWorkbook(fis);

        assert wb.getNumberOfSheets() ==2 : "Workbook does not have 2 sheets";

        Sheet overview = wb.getSheetAt(0);
        assert overview.getSheetName().equals("Overview") : "Sheet 0 is not the Overview";
        assert wb.getSheetAt(1).getSheetName().equals("DummyTest.one") : "Sheet 1 is not DummyTest.one";

        // 0 based as opposed to xls where it rows are 1 based.
        assert overview.getLastRowNum() == 2 :"Last row of overview is not 4, but " + overview.getLastRowNum();

        fis.close();
View Full Code Here

TOP

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

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.