Package org.apache.poi.ss.usermodel

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


  }
 
  private void writeSheet(Sheet sheet, ExcelSheet sheetDefinition,
      OgnlStack stack, Map<String, CellStyle> styleMap,
      WriteStatus writeStatus){
    Workbook wb = sheet.getWorkbook();
    String sheetName = sheetDefinition.getDisplayName();   
    if(stack.getValue("sheetName") != null)
      sheetName = (String)stack.getValue("sheetName");
    if(sheetName != null) wb.setSheetName(wb.getSheetIndex(sheet), sheetName);
   
    Map<ExcelBlock, List<CellRangeAddress>> mergedRegions = new HashMap<ExcelBlock, List<CellRangeAddress>>();
    for(int i=0; i< sheet.getNumMergedRegions(); i++){
      CellRangeAddress cra = sheet.getMergedRegion(i);
      logger.debug("Merged Region:[{}-{}]",
View Full Code Here


    final MasterReport report = (MasterReport) directly.getResource();
    final MemoryByteArrayOutputStream mbos = new MemoryByteArrayOutputStream();
    ExcelReportUtil.createXLS(report, new NoCloseOutputStream(mbos));

    final ByteArrayInputStream bin = new ByteArrayInputStream(mbos.getRaw(), 0, mbos.getLength());
    final Workbook workbook = WorkbookFactory.create(bin);
    assertEquals(4, workbook.getNumberOfSheets());
    assertEquals("Summary", workbook.getSheetAt(0).getSheetName());
    assertEquals("AuthorPublisher A", workbook.getSheetAt(1).getSheetName());
    assertEquals("AuthorPublisher B", workbook.getSheetAt(2).getSheetName());
    assertEquals("AuthorPublisher C", workbook.getSheetAt(3).getSheetName());
  }
View Full Code Here

  }

  private void validateExcelSheet(final ByteArrayOutputStream boutSlow, final TableModel data)
      throws IOException, InvalidFormatException
  {
    Workbook workbook = WorkbookFactory.create(new ByteArrayInputStream(boutSlow.toByteArray()));
    Sheet sheet = workbook.getSheetAt(0);
    Assert.assertEquals(0, sheet.getFirstRowNum());
    Assert.assertEquals(data.getRowCount() - 1, sheet.getLastRowNum());

    for (int r = 0; r < data.getRowCount(); r += 1)
    {
View Full Code Here

    if (templateInputStream != null)
    {
      // do some preprocessing ..
      try
      {
        final Workbook workbook = WorkbookFactory.create(templateInputStream);

        // OK, we have a workbook, but we can't stop here..
        final int sheetCount = workbook.getNumberOfSheets();
        for (int i = 0; i < sheetCount; i++)
        {
          final String sheetName = workbook.getSheetName(i);
          // make sure that that name is marked as used ..
          makeUnique(sheetName);
        }

        return workbook;
View Full Code Here

  protected Sheet openSheet(final String sheetName)
  {
    patriarch = null;

    Workbook workbook = getWorkbook();
    if (sheetName == null)
    {
      return workbook.createSheet();
    }
    else
    {
      final String uniqueSheetname = makeUnique(sheetName);
      if (uniqueSheetname.length() == 0 || uniqueSheetname.length() > 31)
      {
        logger.warn("A sheet name must not be empty and greater than 31 characters");
        return workbook.createSheet();
      }
      else if (isValidSheetName(uniqueSheetname) == false)
      {
        logger.warn("A sheet name must not contain any of ':/\\*?[]'");
        // OpenOffice is even more restrictive and only allows Letters,
        // Digits, Spaces and the Underscore
        return workbook.createSheet();
      }
      else
      {
        return workbook.createSheet(uniqueSheetname);
      }
    }
  }
View Full Code Here

  }

  private int loadImage(final ImageContainer reference)
      throws IOException, UnsupportedEncoderException
  {
    final Workbook workbook = printerBase.getWorkbook();
    Image image = null;
    // The image has an assigned URL ...
    if (reference instanceof URLImageContainer)
    {
      final URLImageContainer urlImage = (URLImageContainer) reference;
      final ResourceKey url = urlImage.getResourceKey();
      // if we have an source to load the image data from ..
      if (url != null && urlImage.isLoadable())
      {
        // and the image is one of the supported image formats ...
        // we we can embedd it directly ...
        final int format = getImageFormat(url);
        if (format == -1)
        {
          // This is a unsupported image format.
          if (reference instanceof LocalImageContainer)
          {
            final LocalImageContainer li = (LocalImageContainer) reference;
            image = li.getImage();
          }
          if (image == null)
          {
            try
            {
              final Resource resource = resourceManager.create(url, null, Image.class);
              image = (Image) resource.getResource();
            }
            catch (final ResourceException re)
            {
              logger.info("Failed to load image from URL " + url, re)// NON-NLS
            }
          }
        }
        else
        {
          try
          {
            final ResourceData data = resourceManager.load(url);
            // create the image
            return workbook.addPicture(data.getResource(resourceManager), format);
          }
          catch (final ResourceException re)
          {
            logger.info("Failed to load image from URL " + url, re)// NON-NLS
          }

        }
      }
    }

    if (reference instanceof LocalImageContainer)
    {
      // Check, whether the imagereference contains an AWT image.
      // if so, then we can use that image instance for the recoding
      final LocalImageContainer li = (LocalImageContainer) reference;
      if (image == null)
      {
        image = li.getImage();
      }
    }

    if (image != null)
    {
      // now encode the image. We don't need to create digest data
      // for the image contents, as the image is perfectly identifyable
      // by its URL
      final byte[] data = RenderUtility.encodeImage(image);
      return workbook.addPicture(data, Workbook.PICTURE_TYPE_PNG);
    }
    return -1;
  }
View Full Code Here

    URL resource = getClass().getResource("Prd-4968.prpt");
    ResourceManager mgr = new ResourceManager();
    MasterReport report = (MasterReport) mgr.createDirectly(resource, MasterReport.class).getResource();
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    ExcelReportUtil.createXLS(report, bout);
    Workbook workbook = WorkbookFactory.create(new ByteArrayInputStream(bout.toByteArray()));
    assertEquals(34, workbook.getNumCellStyles());
    assertEquals(9, workbook.getNumberOfFonts());
  }
View Full Code Here

    URL resource = getClass().getResource("Prd-4968.prpt");
    ResourceManager mgr = new ResourceManager();
    MasterReport report = (MasterReport) mgr.createDirectly(resource, MasterReport.class).getResource();
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    ExcelReportUtil.createXLSX(report, bout);
    Workbook workbook = WorkbookFactory.create(new ByteArrayInputStream(bout.toByteArray()));
    assertEquals(14, workbook.getNumCellStyles());
    assertEquals(6, workbook.getNumberOfFonts());

//    File testOutputFile = DebugReportRunner.createTestOutputFile();
//    ExcelReportUtil.createXLSX(report, "test-output/Prd-4988.xlsx");

  }
View Full Code Here

        this._useFirstSheet = true;
    }

    public void parseFile( InputStream inStream ) {
        try {
            Workbook workbook = WorkbookFactory.create( inStream );

            if ( _useFirstSheet ) {
                Sheet sheet = workbook.getSheetAt( 0 );
                processSheet( sheet, _listeners.get( DEFAULT_RULESHEET_NAME ) );
            } else {
                for ( String sheetName : _listeners.keySet() ) {
                    Sheet sheet = workbook.getSheet( sheetName );
                    if ( sheet == null ) {
                        throw new IllegalStateException( "Could not find the sheetName (" + sheetName
                                                                 + ") in the workbook sheetNames." );
                    }
                    processSheet( sheet,
View Full Code Here

  {
    try
    {
      //
      InputStream inputStream = new BufferedInputStream( new FileInputStream( this.file ) );
      Workbook wb = this.newWorkbookFrom( inputStream );
      Sheet sheet = wb.getSheet( MAINSHEETPAGENAME );
     
      //
      this.clear();
      for ( Row iRow : sheet )
      {
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.