Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Excel.Application copy sheet with embedded charts

I have a php page using a Excel.Application to duplicate a sheet containing some data and an embedded chart.

the code is this:

$Excel=new COM("Excel.application");
$workbook=$Excel->Workbooks->Open($fileName);

//alternative 1
$workbook->Worksheets("Sheet1")->Copy(NULL,$workbook->Worksheets("Sheet2"));

//alternative 2
$added=$workbook->Worksheets->Add();
$added->Name=$destName;
$workbook->Worksheets($sourceName)->Range("A1:Z100")->Copy($added->Range("A1"));

$workbook->SaveAs($fileNameDest);

The result is that the data and the formula are correctly copied and formatted, but the chart in the sheet1 is not copied in the sheet2. No error, no exception, but also no chart for both code alternatives.

Can anyone help me copying this sheet... fully?

Thanks!

like image 631
Redax Avatar asked May 12 '14 10:05

Redax


People also ask

How can you print just a particular chart embedded in a worksheet without printing the entire worksheet?

Print a chart without worksheet data If the chart is on a separate chart sheet, click the chart sheet tab. , and then click Print. By default, Selected Chart is selected under Print what. You can click Preview to see how the chart will look on the printed page.

How do you copy and paste a chart from Excel to another sheet?

Select the Excel chart (single click) and then right click to choose Copy. Move to a different location in the same worksheet or add a new worksheet and then right click and choose Paste. This gives you an exact copy of the chart so it is linked to the original data range and has the same formatting.

What is the difference between an embedded chart and a chart sheet in Excel?

In Microsoft Excel and other spreadsheet programs, there are two types of charts: an embedded chart and chart sheet. An embedded chart is a chart object that can be inserted into a worksheet. A chart sheet is a chart that is a sheet of its own.


1 Answers

There is a permission problem:

  • Execute "dcomcnfg"
  • Open Component Services > Computers > My Computer > DCOM Config
  • Search for "Microsoft Excel Application"
  • Right-Click on it and open the properties
    • if not exists run "excel.exe -regserver"
  • Choose "Identity" tab
  • Normally this is set to "the launching user". You have to change this to "the interactive user" or a admin user of your choice.
  • Apply these new settings and test your COM application. It should work fine now.

I got it from the comments here: http://www.php.net/manual/en/class.com.php

like image 60
Chris Lear Avatar answered Sep 30 '22 16:09

Chris Lear