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

Greetings, I am trying to generate an excel report using perl spreadsheet::writeexcel.pm module. I have a column header as say "Example Name: <<Variable_input>>". This whole context is in one single cell. However, I need to have "Example Name" as bold, and Variable_Input as a normal font character. I tried splitting the two strings into two cells , but this is causing allignment issues in report , for the lower cells . Can someone please help? Any way of having two formats in one single cell using spreadsheet::writeexcel? Appreciate your reply. Regards, Rajpreet

Replies are listed 'Best First'.
Re: Excel Formatting
by jrsimmon (Hermit) on Jul 03, 2009 at 14:54 UTC
    For all these odd formatting issues in Excel, I've always found it useful to actually create the format in an excel spreadsheet first and then read that data with perl to see how it should be generated.
Re: Excel Formatting
by biohisham (Priest) on Jul 03, 2009 at 20:01 UTC
    Alright, you've gotta be aware that in Excel you can dispaly formats of a cell any way you want so a cell accepts two different textual info, like a formatted "Example Name" followed by an unformatted <<Variable_input>> as in your example. But whether that can be done through Perl, I doubt, I can not recall anything in the Spredsheet::WriteExcel module documentation that testified to this conjecture, to avoid the alignment issues use the merge_range(); instead of write() method of $worksheet.. I have come up with this code, to show the merging thing, thus solving a part of your question, as for the other part, I had to circumvent my way around and make the variable display on the right of the cell and below the "Example Name" line
    #!/usr/local/bin/perl use strict; use warnings; use Spreadsheet::WriteExcel; my $workbook=Spreadsheet::WriteExcel->new('excel.xls'); my $worksheet=$workbook->add_worksheet(''); my $var= "biohisham"; my $bold=$workbook->add_format( bold=>1, align=>'center', valign=>'vcenter', size=> 15 #font_size ); my $var_format=$workbook->add_format( align=>'left', valign=>'right', size=>15 ); $worksheet->set_column(0,1,30); $worksheet->set_row($_, 30) for (1,2); $worksheet->merge_range('A1:B2',"Example Name:", $bold); $worksheet->merge_range('A3:B3',"\b$var", $var_format);
    Excellence is an Endeavor of Persistence. Chance Favors a Prepared Mind
      @biohisham Thanks for your answer. Actually this is an existing file, where in I was supposed to fix few things. I did not want to touch other cells using merge_range, but I guess I do not have any option. I worked out the merge_range way, and my issue is resolved now. Thanks once again!