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!

有帮助吗?

解决方案

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top