in reply to Problem adding long string to excel cell

Okay. I found a solution while messing around with the code. Instead of doing the following code to set the values of a range of cells at once like this:

$range = $worksheet->Range(sprintf("%s%d:%s%d", 'A', $nRow, 'C', $nR +ow)); $range->{Value} = [@Params[0], $sTextData, @Params[2];
I changed it so the code added the values to the cells one at a time like this:
$range = $worksheet->Range(sprintf("%s%d", 'A', $nRow)); $range->{Value} = @Params[0]; $range = $worksheet->Range(sprintf("%s%d", 'B', $nRow)); $range->{Value} = $sTextData; $range = $worksheet->Range(sprintf("%s%d", 'C', $nRow)); $range->{Value} = @Params[2];
For some reason, this did the trick. I haven't gotten the exception anymore and the long text is now showing in the cell where as before it wouldn't get inserted. If anyone has a good explanation as to why this code makes that much of a difference I would be more than happy to listen.

Replies are listed 'Best First'.
Re^2: Problem adding long string to excel cell
by googleabc (Initiate) on Aug 03, 2010 at 07:43 UTC
    Thanks very much for your solution.
Re^2: Problem adding long string to excel cell
by dasgar (Priest) on Aug 03, 2010 at 16:21 UTC

    I don't claim to be an expert, but here's my guess. Your first method that failed looks like what it's doing is the equivalent of highlighting and selecting 3 cells and then trying to put values in there. The $range->{Value} is expecting a scalar (such as a number or string). So when you try to give it an array, you're giving it something that it's not expecting.

    In your second method that is working, your giving $range->{Value} scalars.