turoni
turoni

Reputation: 1435

Writing to Excel

I'm testing out how to fill in info to my excel sheet and wrote a simple test program

use Win32::OLE qw(in);
use Win32::OLE::Const "Microsoft Excel";

$Win32::OLE::Warn = 3;

my $excel = Win32::OLE->new("Excel.Application", "Quit");
my $book = $excel->Workbooks->Add();
my $sheet = $book->Worksheets(1);
my $range = $sheet->Range($sheet->Cells(1,1), $sheet->Cells(5,5));

my $mat = $range->{Value};
$mat[1][1] = "x";
#for my $row (@$mat){
#   print "$i\n";
#   for my $cel (@{$row}){
#       $cel = "x";
#   }
#}

$range->{Value} = $mat;


my $fso = Win32::OLE->new("Scripting.FileSystemObject");
my $map = $fso->GetAbsolutePathName(".");
my $padnaam = $map . "\\test.xlsx";
$book->SaveAs($padnaam);

When I use the commented out code, there is a nice square of "x"s but when I just try to assign an x by index nothing appears. I'm guessing I'm not referencing the array correctly but after looking trough the perlreftut and all questions I could find about 2D arrays I can't really figure out the correct sequence that should be used instead.

So, how can I add values to the range by index?

Upvotes: 0

Views: 39

Answers (1)

Andrey
Andrey

Reputation: 1818

$mat is an array reference. You need to dereference it:

$$mat[1][1] = "x";

Upvotes: 1

Related Questions