I just did a search for "text" in the doco. There's plenty of information in there and in the examples. Here's just one way you can write strings but check out the formats.pl example for lots of tricks.
write_string($row, $column, $string, $format)
Write a string to the cell specified by $row and $column:
$worksheet->write_string(0, 0, "Your text here" );
$worksheet->write_string('A2', "or here" );
The maximum string size is 32767 characters. However the maximum string
segment that Excel can display in a cell is 1000. All 32767 characters
can be displayed in the formula bar.
The $format parameter is optional.
I'm not sure this is your case, but it seems to be:
You can have format control, not just over rows, but also over
individual cells.
In my case, what I did is first specify the formats I needed:
my $formatd = $workbookd->addformat();
$formatd->set_bold();
$formatd->set_size(12);
$formatd->set_color('black');
$formatd->set_align('center');
my $format_alarm0d= $workbookd->addformat();
$format_alarm0d->set_bold();
$format_alarm0d->set_size(12);
$format_alarm0d->set_color('green');
$format_alarm0d->set_align('center');
my $format_alarm2d= $workbookd->addformat();
$format_alarm2d->set_bold();
$format_alarm2d->set_size(12);
$format_alarm2d->set_color('red');
$format_alarm2d->set_align('center');
my $format_alarm1d= $workbookd->addformat();
$format_alarm1d->set_bold();
$format_alarm1d->set_size(12);
$format_alarm1d->set_color('orange');
$format_alarm1d->set_align('center');
Next,
if(condition1){$formatday=$formatd;}
elsif(condition2){$formatday=$format_alarm2d;}
elsif(condition3){$formatday=$format_alarm0d;}
....
my $column=0; while($column<=$max_no_columns){
$rworksheettimdaily->{$date1}->write($row,$column,$date,$formatday);$column++;}
Does this sound like what you want?
>
> Sorry John,
>
> But I don't understand how to use the add_write_handler function - I
> am starting to work with perl :( .
> The code that I am using is bellow.
>
> foreach my $record (@$fields_listref)
> {
> $worksheet->write_row($row++, $col, $record);
> }
>
> The $record is the data that will be write and I don't know who data
> are these. Can be number, text etc.
>
> My main question is:
> Is it possible to change the cells format using perl? addformat()
> function
> change the bold, underlined etc. Can this function change the cells
> format?
>
> Thanks again
>
> F?lvio
>
>
>
> On Dec 5, 9:02 am, jmcnamara <jmcnam...@cpan.org> wrote:
>> On Dec 5, 11:08 am, "F?lvio" <fulvi...@gmail.com> wrote:
>>
>> > Hi Wardman,
>>
>> > The problem in this case is that my program is structured to use
>> > write_row.
>> > This function(write_row) is called a lot of time in my program so, I
>> > can't change these calls.
>> > In my case I need to format the cells in addformat to indicate that
>> > the cells format is
>> > "text" instead of "general".
>>
>> Hi F?lvio,
my $APOS = q{'};
if ( $string =~ m/ \A = /xms ) {
$string = $APOS . $string;
I had a feeling I'd tried that before.
But I was only thinking of a way to prevent the ==== giving errors.
Similar to your earlier suggestion of getting rid of them altogether.
I have a similar problem with write_row and I ended up just using a loop
to write_* depending on a setting I have in each column's format.
So, rather than write a while row, I just loop through and write each
cell the way I want it.
for my $rowid ( @{$row_heading_ref} ) {
my $multi_line_cell = 0; # Is there a newline in this row?
$col = 0;
for my $column_ref ( @{$column_list_ref} ) {
my $column = $column_ref->[0];
my $format = $column_ref->[2];
if ( defined $row_detail_ref->{DETAIL}->{$rowid}{$column} ) {
# Write any cell value
my $cell_value =
$row_detail_ref->{DETAIL}->{$rowid}{$column};
if ( defined $format and $format eq 'text' ) {
$sheet->write_string( $row, $col, $cell_value );
}
else {
$sheet->write( $row, $col, $cell_value );
}
# Does this row have any mulit-line cells. If so we let
Excel
# pick the row height
if ( !$multi_line_cell and index( $cell_value, "\n" ) >= 0 )
{
$multi_line_cell = 1;
}
# Write any comment
my $cell_comment
= $row_detail_ref->{COMMENT}->{$rowid}{$column} ||
$EMPTY;
if ( $cell_comment ne $EMPTY ) {
$sheet->write_comment( $row, $col, $cell_comment );
}
} ## end if ( defined $row_detail_ref...
$col++;
} ## end for my $column_ref ( @{...
# Fix row height. Don't know why but sometimes it looks
double-spaced
$sheet->set_row( $row, 17 ) unless $multi_line_cell;
$row++;
} ## end for my $rowid ( @{$row_heading_ref...
The column ref thing gets set up elsewhere like:
push @columns, (
['metahead', 10, 'text' ],
['metapos' ],
['metaconf', 13 ],
['metastripe' ],
[qw(mapped), undef, undef, 'hide' ],
[qw(ports), 11 ],
[qw(luns), 11, 'text' ],
);
-----Original Message-----
From: spreadsheet...@googlegroups.com
[mailto:spreadsheet...@googlegroups.com] On Behalf Of jmcnamara
Sent: Thursday, 6 December 2007 9:49 AM
To: Spreadsheet::WriteExcel
Subject: [Spreadsheet::WriteExcel] Re: Change the cell format to "text"
instead of "general"