error while writing with write_row using Spreadsheet::WriteExcel

31 views
Skip to first unread message

Ganesh Wankhede

unread,
Apr 7, 2015, 3:11:34 AM4/7/15
to spreadsheet...@googlegroups.com

to write each row I have used write_row(). 
When I try to write row having data (=) it throws an error saying:Couldn't parse formula: = ,since excel consider it as formula.
I need to write data using array as one row only, so is there any way out to do the same? 

Below is the code snippets: 

use Spreadsheet::WriteExcel; my $workbook = Spreadsheet::WriteExcel->new("../tmp/op.xls"); my $worksheet = $workbook->add_worksheet(); my @data = ('1','1','=',"testdata"); $worksheet->write_row("A1", \@data); $workbook->close();

Output:

Couldn't parse formula: = at

jmcnamara

unread,
Apr 7, 2015, 7:15:53 AM4/7/15
to spreadsheet...@googlegroups.com


On Tuesday, 7 April 2015 08:11:34 UTC+1, Ganesh Wankhede wrote:

to write each row I have used write_row(). 
When I try to write row having data (=) it throws an error saying:Couldn't parse formula: = ,since excel consider it as formula.
I need to write data using array as one row only, so is there any way out to do the same? 

Hi Ganesh,

Instead of using write_row() you can just use a for() loop and loop over the data and apply the appropriate write_*() functions for the data types.

Otherwise, you can add a write_handler to handle this particular case. Like this:

use Spreadsheet::WriteExcel;

my $workbook  = Spreadsheet::WriteExcel->new("../tmp/op.xls");
my $worksheet = $workbook->add_worksheet();

# Add a callback function to handle a single '=' in write().
$worksheet->add_write_handler( qr/^=$/, \&write_equals );

sub write_equals {
    my $worksheet = shift;
    return $worksheet->write_string(@_);

}

my @data = ( '1', '1', '=', "testdata" );

$worksheet->write_row( "A1", \@data );
$workbook->close();


Regards,

John

Reply all
Reply to author
Forward
0 new messages