hagmgoe has asked for the wisdom of the Perl Monks concerning the following question:

Hallo Forum if I convert following the converter tells my the mistake Failed on 1,0,"BT0900085211",4613,"[",0,4480,1274678734,"2010-05-24 07:25:36",3,4459,6,"1.1.107",3.47,"2/2/5",NULL Couldn't parse formula: =@ at xxxxx/csv2excel.pl line 49 the line 49 contents  $worksheet->write($i++, 0, $row); I think something happen in this part
for my $row (@$data) { $qty++; if ($i > $limit) { $i = $start_row; $w++; $worksheet = $workbook->add_worksheet("$base_name - $w"); $worksheet->write('A1', $colums,$bold); } $worksheet->write($i++, 0, $row); } autofit_columns($worksheet); warn "Convereted $qty rows."; return $worksheet;
It would be nice if somebody is able help me

Replies are listed 'Best First'.
Re: csv 2 excel
by roboticus (Chancellor) on Jul 03, 2010 at 16:21 UTC

    hagmgoe:

    The write() method tries to figure out what type of thing you're putting in the spreadsheet cell (number, formula, string, date, etc.), and one of your data fields is apparently confusing it. Just use the writestring() method to force it to be a string value rather than attempting to treat it as a formula. (There are other variations for other data types, too. Read perldoc Spreadsheet::WriteExcel for details.

    ...roboticus

    Update: After re-reading the node, I notice that you're writing a row at a time, rather than a cell at a time. You may want to create your own function to write a row, and call that. Something like (untested):

    sub write_row { my $worksheet = shift; my $row = shift; my $col = 0; while (my $cell = shift) { if ($cell =~ /"/) { $worksheet->writestring($row, $col++, $cell) + } else { $worksheet->write($row, $col++, $cell) } } }

    Update 2: Fixed a couple typographical errors.

      Thanks for your help, I found the Problem. The real mistake another row content some contents same data who is not compatibel wtih the script.