http://www.perlmonks.org?node_id=999946


in reply to convert excel cell into "Text" format with Excel:: Write::xlsx modul

sarf13:

In the Excel::Writer::XLSX documentation, under write, it mentions that you can use the add_write_handler() method to make write do something differently. So if you have too many write() methods in your project, you might just add a write handler to treat everything as a string, so you'd only need to add a bit of code at the beginning.

...roboticus

When your only tool is a hammer, all problems look like your thumb.

  • Comment on Re: convert excel cell into "Text" format with Excel:: Write::xlsx modul

Replies are listed 'Best First'.
Re^2: convert excel cell into "Text" format with Excel:: Write::xlsx modul
by sarf13 (Beadle) on Oct 19, 2012 at 18:24 UTC
    Hi roboticus. i have gone through your feedback.when i am writing data into Excel with "write_string()" in given way
    @val $worksheet->write_string($row,$col,$val[$col]);

    its giving me some error. i don't know how to fix it.i would probably have to do some more R&D on this. if you could suggest some way that would be gr8. Thanks

      sarf13:

      You'll have to be a bit more specific. What error message are you getting?

      ...roboticus

      When your only tool is a hammer, all problems look like your thumb.

        please find my test code

        #!/usr/bin/perl use strict; use warnings; use Benchmark; my $t0 = Benchmark->new; #use Spreadsheet::WriteExcel; use Excel::Writer::XLSX; my $filePath = 'D:\work\test.txt'; open(FILE,"$filePath"); my $workbook = Excel::Writer::XLSX->new('tab.xls'); my $worksheet = $workbook->add_worksheet(); my $row = 0; while (my $line = <FILE>){ chomp($line); # Split on single tab #print "$line\n"; my @Fld = split('\|', $line); my $cnt = scalar(@Fld); my $col = 0; while ($cnt>= $col){ $worksheet->write_string($row, $col, $Fld[$col]); $col++; } $row++; } my $t1 = Benchmark->new; my $td = timediff($t1, $t0); print "the code took:",timestr($td),"\n";

        it giving me this error --- Use of uninitialized value $str in hash element while i am using $worksheet->write_string($row, $col, $Fld[$col]);

        its working fine with write subroutine $worksheet->write($row, $col, $Fld[$col]);