Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

excel com

Status
Not open for further replies.

crackn101

Programmer
Dec 27, 2002
63
0
0
US
Hi Guys,
I have a question about using php5 the 'new COM("excel.application")'
function to modify an existing (pre-formated) excel template.
I can open the template and read and write to it just fine.
what i'm trying to do is select a single formated row and then
do an insert to expanded the number of formated rows.
for example if my template has 3 formated rows, but I have
5 items to stick in there, then i would need to select 1 of the formated rows, and then do an insert twice
giving me my 5 formated rows.
I can do a Select and then Insert and it does shift the
rows down, but it does not carry over the formulas.
I need to do more of an insert row, and then copy and past_special -> All or something like that.
I'm trying to search for any good documentation that
covers what methods are available.
Here's a code sample of what i have.
Code:
      $cell=$sheet->Cells("5","A");
      $cell->Activate;
      $cell->EntireRow->Select;
      for($a=0; $a<5; $a++){
        $cell->Offset(1, 0)->EntireRow->Insert;
      }
I tried $cell->EntireRow->Paste or PasteSpecial
it always gives a COM exception. it doesn't know what Paste
is.

Thanks in advance for any suggestions.


 
Ok I've figured it out.
I'm posting again in case others may be interested.
Actually i was pretty close i just didn't have the right
combination. see code below.
The line "$cell->EntireRow->Copy;" has to be inside the for loop or it doesn't work.
In this example because we are getting the "EntireRow"
you can use the "Cells()" or "Range()" method with the same results.

Code:
  #$cell=$sheet->Cells("5","A");
  $cell = $sheet->Range("A5","Q5");
  $cell->activate;
  for($a=0; $a<4; $a++){
    $cell->EntireRow->Copy;
    $cell->EntireRow->Insert;
    $cell->PasteSpecial;
  }
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top