Embedding Excel OLE Chart in Powerpoint Issue

Last post 10-15-2011, 11:07 AM by aspose.notifier. 13 replies.
Sort Posts: Previous Next
  •  09-22-2011, 10:23 AM 331270

    Embedding Excel OLE Chart in Powerpoint Issue Java

    Hi, I'm having a problem following the following example for embedding an Excel OLE chart in a Powerpoint presentation: http://www.aspose.com/documentation/java-components/aspose.slides-for-java/creating-excel-chart-and-embedding-it-in-presentation-as-ole-object-1.html

    I'm using Aspose.Cells 7.0.1 and Aspose.Slides 2.6.0 with the following test code based from your example:

    public Test() throws Exception
        {
            //Instantiate a Workbook object that represents Excel file.
            Workbook wb = new Workbook();
            
            //Note when you create a new workbook, a default worksheet
            //"Sheet1" is added (by default) to the workbook.
            //Access the first worksheet "Sheet1" in the book.
            Worksheet sheet = wb.getWorksheets().get(0);

            //Adding some sample value to cells
            Cells cells = sheet.getCells();
            Cell cell = cells.get("A1");
            cell.setValue(50);
            cell = cells.get("A2");
            cell.setValue(100);
            cell = cells.get("A3");
            cell.setValue(150);
            cell = cells.get("B1");
            cell.setValue(4);
            cell = cells.get("B2");
            cell.setValue(20);
            cell = cells.get("B3");
            cell.setValue(50);

            ChartCollection charts = sheet.getCharts();

            //Adding a chart to the worksheet
            int chartIndex = charts.add(ChartType.COLUMN, 5, 0, 15, 5);
            Chart chart = charts.get(chartIndex);
            
            //Getting Chart Area
            ChartArea chartArea = chart.getChartArea();

            //Setting the foreground color of the chart area
            chartArea.getArea().setTransparency( 1 );
            
            //Adding NSeries (chart data source) to the chart ranging from "A1" cell to "B3"
            SeriesCollection serieses = chart.getNSeries();
            serieses.add("A1:B3", true);

            //Save the Excel file.
            //wb.save("D:\\MyBook.xlsx", FileFormatType.EXCEL_2007_XLSX);
            
            // save the chart image to stream
            ByteArrayOutputStream imageStream = new ByteArrayOutputStream();
            chart.toImage(imageStream, new ImageOrPrintOptions() );
            
            // save the workbook to stream
            ByteArrayOutputStream bout = new ByteArrayOutputStream();
            wb.save( bout, FileFormatType.EXCEL_2007_XLSX );
            
            // create presentation and slide
            PresentationEx presentation = new PresentationEx();
            SlideEx slide = presentation.getSlides().get( 0 );
            
            // add workbook to slide
            addExcelChartToPresentation(presentation, slide, bout.toByteArray(), imageStream.toByteArray() );
            
            // save presentation
            presentation.write( new FileOutputStream( "D:\\testPresentation.pptx" ) );
        }
        
        
        private void addExcelChartToPresentation( PresentationEx presentation, SlideEx slide, byte[] wbArray, byte[] imgChart ) throws Exception
        { 
            double oleHeight = presentation.getSlideSize().getSize().getHeight();
            double oleWidth = presentation.getSlideSize().getSize().getWidth();
            
            Workbook wb = new Workbook( new ByteArrayInputStream(wbArray) );
            
            OleObjectFrameEx oof = slide.getShapes().addOleObjectFrame(0f, 0f, (float)oleWidth, (float)oleHeight, "Excel.Sheet", wbArray);
            BufferedImage image = ImageIO.read(new ByteArrayInputStream(imgChart));
            oof.setImage(presentation.getImages().addImage(image));
        }


        public static void main(String[] args) throws Exception
        {
            Test t = new Test();
        }

    When I run this, I get the following error:

    Exception in thread "main" java.lang.NullPointerException
    at com.aspose.slides.pptx.OleObjectFrameEx.<init>(SourceFile:117)
    at com.aspose.slides.pptx.ShapesEx$3$3.do(SourceFile:135)
    at com.aspose.slides.obfuscated.as.if(SourceFile:36)
    at com.aspose.slides.obfuscated.as.<init>(SourceFile:20)
    at com.aspose.slides.pptx.ShapesEx$3.do(SourceFile:123)
    at com.aspose.slides.obfuscated.as.if(SourceFile:36)
    at com.aspose.slides.obfuscated.as.<init>(SourceFile:20)
    at com.aspose.slides.pptx.ShapesEx.if(SourceFile:110)
    at com.aspose.slides.pptx.ShapesEx.do(SourceFile:241)
    at com.aspose.slides.pptx.ShapesEx.addOleObjectFrame(SourceFile:273)
    at test.Test.addExcelChartToPresentation(Test.java:105)
    at test.Test.<init>(Test.java:91)
    at test.Test.main(Test.java:113)

    Thanks
    Paul

     
  •  09-22-2011, 2:29 PM 331328 in reply to 331270

    Re: Embedding Excel OLE Chart in Powerpoint Issue

    Just for some extra information, we are currently evaluating the trial version. If we can get this code working then we would look into purchasing licences for our team. 

    If we can't get round this issue then we will have to look elsewhere.
     
  •  09-23-2011, 12:08 AM 331395 in reply to 331270

    Re: Embedding Excel OLE Chart in Powerpoint Issue

    Hello Dear,

    I regret to share that the issue has already been identified in Aspose.Slides for Java. An issue with ID 28595 has already been added in our issue tracking system for further investigation and resolution. The said issue has been resolved in upcoming version of Aspose.Slides for Java 2.7.0, which will be available by end of October. For the time being you may try using Aspose.Slides for Java 2.4.0.

    We are sorry for your inconvenience,


    Mudassir Fayyaz
    Support Developer
    Aspose Sialkot Team
    Contact Us
    Aspose - The .NET and Java Component Publisher

    Keep in touch! We're on Twitter and Facebook
     
  •  09-23-2011, 2:52 AM 331441 in reply to 331395

    Re: Embedding Excel OLE Chart in Powerpoint Issue

    I'm unable to download the trial version of Aspose.slides 2.4.0 from your site.

    Is it possible that someone can enable this on your site please? Unfortunately we cannot wait till the end of October for a solution so we wouldn't purchase your software.
     
  •  09-23-2011, 7:00 AM 331515 in reply to 331441

    Re: Embedding Excel OLE Chart in Powerpoint Issue

    Hi,

    I like to share that the fix for the issue has been provided in Aspose.Slides for Java 2.6.0.2. Please download the specified product version from this link.

    Thanks and Regards,

    Mudassir Fayyaz
    Support Developer
    Aspose Sialkot Team
    Contact Us
    Aspose - The .NET and Java Component Publisher

    Keep in touch! We're on Twitter and Facebook
     
  •  09-23-2011, 7:48 AM 331523 in reply to 331515

    Re: Embedding Excel OLE Chart in Powerpoint Issue

    Attachment: Present (inaccessible)
    Hi

    Managed to get the code working with version 2.6.0.2.

    I've attached two files: ChartPresentation-Aspose.pptx which is the file the code generated; testChartPresentationFromMSOffice.pptx which is what I want to be able to produce.

    From looking at the ChartPresentation-Aspose.pptx, the chart isn't embedded its just an image. 

    Is it possible to recreate the testChartPresentationFromMSOffice.pptx with Aspose and Java?

    Thanks
     
  •  09-23-2011, 10:47 AM 331561 in reply to 331523

    Re: Embedding Excel OLE Chart in Powerpoint Issue

    Hi,

    I have worked with the code snippet shared and have been able to observe the issue as shared by you. An issue with ID 30831 has been created our issue tracking system to further investigate and resolve the issue. I like to share that the similar issue with ID 30416 has also been reported for Aspose.Slides for .NET as well. The issue is with using latest version of Aspose.Cells for Java 7.0.x.x. I would suggest you to please use Aspose.Cellls for Java 2.5.4 for the time being.

    We are sorry for your inconvenience,

    Mudassir Fayyaz
    Support Developer
    Aspose Sialkot Team
    Contact Us
    Aspose - The .NET and Java Component Publisher

    Keep in touch! We're on Twitter and Facebook
     
  •  09-23-2011, 11:01 AM 331565 in reply to 331561

    Re: Embedding Excel OLE Chart in Powerpoint Issue

    Attachment: Present (inaccessible)
    Still the same issue - see attached file. 
     
  •  09-23-2011, 12:29 PM 331585 in reply to 331565

    Re: Embedding Excel OLE Chart in Powerpoint Issue

    Hi,

    It will be really appreciable if you may please share the source code that you are using for generation of chart in presentation using Aspose.Cells for Java 2.5.4.

    Thanks and Regards,

    Mudassir Fayyaz
    Support Developer
    Aspose Sialkot Team
    Contact Us
    Aspose - The .NET and Java Component Publisher

    Keep in touch! We're on Twitter and Facebook
     
  •  09-26-2011, 2:46 AM 331760 in reply to 331585

    Re: Embedding Excel OLE Chart in Powerpoint Issue

    Its pretty much the same code just tweaked to match the available functions in 2.5.4:

    public AsposeTest() throws Exception
        {
            //Instantiate a Workbook object that represents Excel file.
            Workbook wb = new Workbook();
            
            //Note when you create a new workbook, a default worksheet
            //"Sheet1" is added (by default) to the workbook.
            //Access the first worksheet "Sheet1" in the book.
            Worksheet sheet = wb.getWorksheets().getSheet(0);

            //Adding some sample value to cells
            Cells cells = sheet.getCells();
            Cell cell = cells.getCell("A1");
            cell.setValue(50);
            cell = cells.getCell("A2");
            cell.setValue(100);
            cell = cells.getCell("A3");
            cell.setValue(150);
            cell = cells.getCell("B1");
            cell.setValue(4);
            cell = cells.getCell("B2");
            cell.setValue(20);
            cell = cells.getCell("B3");
            cell.setValue(50);

            Charts charts = sheet.getCharts();

            //Adding a chart to the worksheet
            Chart chart = charts.addChart(ChartType.COLUMN_CLUSTERED, 5, 0, 15, 5);
            
            //Getting Chart Area
            ChartArea chartArea = chart.getChartArea();

            //Setting the foreground color of the chart area
            //chartArea.getArea().setTransparency( 1 );
            
            //Adding NSeries (chart data source) to the chart ranging from "A1" cell to "B3"
            NSeries serieses = chart.getNSeries();
            serieses.add("A1:B3", true);

            //Save the Excel file.
            //wb.save("D:\\MyBook.xlsx", FileFormatType.EXCEL_2007_XLSX);
            
            // save the chart image to stream
            ByteArrayOutputStream imageStream = new ByteArrayOutputStream();
            chart.toImage(imageStream, new ImageOptions() );
            
            // save the workbook to stream
            ByteArrayOutputStream bout = new ByteArrayOutputStream();
            wb.save( bout, FileFormatType.EXCEL2003 );
            
            // create presentation and slide
            PresentationEx presentation = new PresentationEx();
            SlideEx slide = presentation.getSlides().get( 0 );
            
            // add workbook to slide
            addExcelChartToPresentation(presentation, slide, bout.toByteArray(), imageStream.toByteArray() );
            
            // save presentation
            presentation.write( new FileOutputStream( "D:\\testPresentation.ppt" ) );
        }
        
        
        private void addExcelChartToPresentation( PresentationEx presentation, SlideEx slide, byte[] wbArray, byte[] imgChart ) throws Exception
        { 
            double oleHeight = presentation.getSlideSize().getSize().getHeight();
            double oleWidth = presentation.getSlideSize().getSize().getWidth();
            
            Workbook wb = new Workbook();
            wb.loadData( new ByteArrayInputStream(wbArray) );
            
            OleObjectFrameEx oof = slide.getShapes().addOleObjectFrame(0f, 0f, (float)oleWidth, (float)oleHeight, "Excel.Sheet", wbArray);
            BufferedImage image = ImageIO.read(new ByteArrayInputStream(imgChart));
            oof.setImage(presentation.getImages().addImage(image));
        }


        public static void main(String[] args) throws Exception
        {
            AsposeTest t = new AsposeTest();
        }
     
  •  09-26-2011, 9:02 AM 331877 in reply to 331760

    Re: Embedding Excel OLE Chart in Powerpoint Issue

    Attachment: Present (inaccessible)
    Hi,

    I have worked with the code snippet shared by you. I have observed that you have been using wrong object class name while you are adding the Ole frame. Please try adding "Excel.Sheet.8" instead of "Excel.Sheet". For your kind reference, I have attached the generated presentation as well.

    Thanks and Regards,

    Mudassir Fayyaz
    Support Developer
    Aspose Sialkot Team
    Contact Us
    Aspose - The .NET and Java Component Publisher

    Keep in touch! We're on Twitter and Facebook
     
  •  09-26-2011, 10:05 AM 331902 in reply to 331877

    Re: Embedding Excel OLE Chart in Powerpoint Issue

    Its still not producing a fully embedded chart that you can edit within the powerpoint. Please see the example I attached earlier.

    Unfortunately I'm going to look elsewhere as this is necessary for the project I'm working on.
     
  •  09-26-2011, 11:18 AM 331920 in reply to 331902

    Re: Embedding Excel OLE Chart in Powerpoint Issue

    Attachment: Present (inaccessible)
    Hi,

    I have observed the issue in your former example as well. You are actually saving your Workbook as XLSX. In order to use the XSLX workbook in Ole frame you need to set class name to "Excel.Sheet.12". I have observed that you are using "Excel.Sheet" as class name. I have modified the code snippet for your reference and it works perfectly. I can edit the ole frame by double clicking on that. For your kind reference, I have shared the generated PPTX as well. We are trying our level best to facilitate your every possible way and will continue to do the same for our all worth customers. If there has been some inconvenience, we are really sorry for that.

    public static void CreateChart() throws Exception
        {
            //Instantiate a Workbook object that represents Excel file.
            Workbook wb = new Workbook();
            
            //Note when you create a new workbook, a default worksheet
            //"Sheet1" is added (by default) to the workbook.
            //Access the first worksheet "Sheet1" in the book.
            Worksheet sheet = wb.getWorksheets().get(0);

            //Adding some sample value to cells
            com.aspose.cells.Cells cells = sheet.getCells();
            com.aspose.cells.Cell cell = cells.get("A1");
            cell.setValue(50);
            cell = cells.get("A2");
            cell.setValue(100);
            cell = cells.get("A3");
            cell.setValue(150);
            cell = cells.get("B1");
            cell.setValue(4);
            cell = cells.get("B2");
            cell.setValue(20);
            cell = cells.get("B3");
            cell.setValue(50);

            ChartCollection charts = sheet.getCharts();

            //Adding a chart to the worksheet
            int chartIndex = charts.add(ChartType.COLUMN, 5, 0, 15, 5);
            Chart chart = charts.get(chartIndex);
            
            //Getting Chart Area
            ChartArea chartArea = chart.getChartArea();

            //Setting the foreground color of the chart area
            chartArea.getArea().setTransparency( 1 );
            
            //Adding NSeries (chart data source) to the chart ranging from "A1" cell to "B3"
            SeriesCollection serieses = chart.getNSeries();
            serieses.add("A1:B3", true);

            //Save the Excel file.
            //wb.save("D:\\MyBook.xlsx", FileFormatType.EXCEL_2007_XLSX);
            
            // save the chart image to stream
            ByteArrayOutputStream imageStream = new ByteArrayOutputStream();
            chart.toImage(imageStream, new ImageOrPrintOptions() );
            // save the workbook to stream
            ByteArrayOutputStream bout = new ByteArrayOutputStream();
            wb.save( bout, FileFormatType.EXCEL_2007_XLSX );
            
           // create presentation and slide
            PresentationEx presentation = new PresentationEx();
            SlideEx slide = presentation.getSlides().get( 0 );
     
            
            // add workbook to slide
            addExcelChartToPresentation(presentation, slide, bout.toByteArray(), imageStream.toByteArray() );
            
            // save presentation
            presentation.write( new FileOutputStream( "D:\\testPresentationnew.pptx" ) );
        }
        
        public static void addExcelChartToPresentation( PresentationEx presentation, SlideEx slide, byte[] wbArray, byte[] imgChart ) throws Exception
        { 
            double oleHeight = presentation.getSlideSize().getSize().getHeight();
            double oleWidth = presentation.getSlideSize().getSize().getWidth();
            
            Workbook wb = new Workbook( new ByteArrayInputStream(wbArray) );
            
            OleObjectFrameEx oof = slide.getShapes().addOleObjectFrame(0f, 0f, (float)oleWidth, (float)oleHeight, "Excel.Sheet.12", wbArray);
            BufferedImage image = ImageIO.read(new ByteArrayInputStream(imgChart));
            oof.setImage(presentation.getImages().addImage(image));
        }


    Thanks and Regards,

    Mudassir Fayyaz
    Support Developer
    Aspose Sialkot Team
    Contact Us
    Aspose - The .NET and Java Component Publisher

    Keep in touch! We're on Twitter and Facebook
     
  •  10-15-2011, 11:07 AM 335760 in reply to 331270

    Re: Embedding Excel OLE Chart in Powerpoint Issue

    The issues you have found earlier (filed as 28595) have been fixed in this update.


    This message was posted using Notification2Forum from Downloads module by aspose.notifier.
    (2)
     
View as RSS news feed in XML