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

Hi ,

I am Trying to print the String stored in the Excel to a particular Cell of the Excel using the "$worksheet->write" method as follows,

my $txt = $table->Cell($i,4)->Range->{Text}; chomp($txt); $worksheet->write($j+1, 1,$txt);

in the above code if $txt contains "bite" it is printing "bite*" to the given Cell. (Note: "*" is Actually Dark Black Dot and Not the Star. As I cant replicate the Dark Black Dot here i used Star symbol instead)

How to Overcome this. Any Help is Highly Appreciated.

Replies are listed 'Best First'.
Re: Spreadsheet::WriteExcel Write through scalar variable
by Corion (Patriarch) on Oct 31, 2013 at 08:14 UTC

    Is there maybe whitespace at the end of $txt? The chomp removes one newline character at the end, but maybe the cell value contains \r\n and not \n. Try printing out the value using Data::Dumper:

    use Data::Dumper; $Data::Dumper::Useqq= 1; $txt= "foo\r"; print Dumper $txt; # $VAR1 = "foo\r";

      Thanks your prompt reply Corion, I got the print result as "bite\r\a"

      .

      How to remove the trailing '\r' and '\a'

      Thanks in Advance.

        I would remove all whitespace, or maybe even all non-printable characters from the end of the string:

        $txt=~ s!\s*$!!; # remove all whitespace

        ... or alternatively

        $txt=~ s![^A-Za-z0-9]*$!!; # remove everything except characters and d +igits at the end

        Note that the second approach will also remove trailing dashes and other stuff like that.