On Nov 7, 5:37 am, sonal gupta <
guptasonal1...@gmail.com> wrote:
> Hello,
>
> What is the format to write formula to a spreadsheet being edited by
> Saveparser package.
Hi,
As stated in the documentation, it isn't possible to rewrite a formula
in an Excel file using SaveParser due to the format of formulas in an
xls file and due to limitations of the module.
You can write a formula again by getting a reference to the underlying
Spreadsheet::WriteExcel module and using that to write a new formula.
Something like this.
#!/usr/bin/perl -w
use strict;
use Spreadsheet::ParseExcel;
use Spreadsheet::ParseExcel::SaveParser;
# Open the template with SaveParser
my $parser = new Spreadsheet::ParseExcel::SaveParser;
my $template = $parser->Parse( 'template.xls' );
my $sheet = $template->worksheet( 0 );
my $row = 0;
my $col = 0;
# Get the format form cell A1.
my $cell = $sheet->get_cell( 0, 0 );
my $format_number = $cell->{FormatNo};
# Write data to some cells
$template->AddCell( 0, $row, $col, 1, $format_number );
$template->AddCell( 0, $row + 1, $col, "Hello", $format_number );
# Add a new worksheet
$template->AddWorksheet( 'New Data' );
# The SaveParser SaveAs() method returns a reference to a
# Spreadsheet::WriteExcel object. If you wish you can then
# use this to access any of the methods that aren't
# available from the SaveParser object. If you don't need
# to do this just use SaveAs().
#
my $workbook = $template->SaveAs( 'new.xls' );
# Use Spreadsheet::WriteExcel methods
my $worksheet = $workbook->sheets( 0 );
$worksheet->write( $row + 2, $col, "World2" );
$worksheet->write( 'D3', '=1+2' );
$workbook->close();