my $workbook = Spreadsheet::WriteExcel->new($out);
my $worksheet = $workbook->add_worksheet("Result");
my $t1 = xl_rowcol_to_cell(2, 4); # E2
my $t2 = xl_rowcol_to_cell(2, 5); # F2
my ($t1_h, $t1_min, $t1_sec) = split (/\:/, $t1);
my ($t2_h, $t2_min, $t2_sec) = split (/\:/, $t1);
my $delta= $worksheet->write('G2', '=$t2_h - t1_h', $unlocked);
But it doesn't work!
The value I get is E2....E400, so I can't split it and the
calculation, what I need is to get the value of the cell not columns
number!
> my $worksheet = $workbook->add_worksheet("Result");
You have created a new worksheet in the above workbook, it too is empty.
> my $t1 = xl_rowcol_to_cell(2, 4); # E2
> my $t2 = xl_rowcol_to_cell(2, 5); # F2
$t1 now contains the string "E3" (not E2 as you state).
$t2 now contains the string "F3" (rows/cols counted from zero not one)
> my ($t1_h, $t1_min, $t1_sec) = split (/\:/, $t1);
> my ($t2_h, $t2_min, $t2_sec) = split (/\:/, $t1);
This makes no sense in light of what you have set those variables to
above.
> my $delta= $worksheet->write('G2', '=$t2_h - t1_h', $unlocked);
>
> But it doesn't work!
To read Excel files you need Spreadsheet::ParseExcel it should be
available from the same place you got Spreadsheet::WriteExcel.
In addition, the number format you've given looks like a time. Excel
stores time and date differently, in Excel it may look like 12:03:20,
but that may be down to the cell formatting, and not the actual contents
of the cell. You need to be sure that the actual cell content *is* as
you have shown, otherwise you'll not be able to split as you intend. For
example, 0.62 in a cell, with standard number formatting looks just like
that, change it to time formatting nn:nn:nn and it reads 14:57:02, but
you won't be able to split it with perl because that's not what perl
will see, it will see only 0.62. There are methods for reading the cell
formatting with perl, these may help you out if the number is stored as
I describe.
Justin.
--
Justin C, by the sea.
You use Spreadsheet::ParseExcel (S:PE) to read data from an Excel
spreadsheet document. You use Spreadsheet::WriteExcel (S:WE) to create
an Excel spreadsheet and add data to its cells. You cannot use S:PE to
add data to an existing spreadsheet, nor can you use S:WE to read data
from a newly-created spreadsheet.
If you are creating a spreadsheet with S:WE and want to see what has
been added, you need to get the data from whatever source was used to
generate the cell contents in the first place, not the spreadsheet
itself.
I suppose you could create a spreadsheet with S:WE, close it, then read
its contents with S:PE. Just don't try to do both at the same time.
Perhaps you can give us an idea of what you are really trying to
accomplish.
--
Jim Gibson