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

Hello, I would like to write a string into a cell using the module Spreadsheet::WriteExcel where part of the string is in regular font and the other part is bold (or italic).
I.e.
The string "123 456 789" in a single cell.

Is it possible to do such thing?

Thanks,
Michael
  • Comment on Multiple formats in Excel cell (Spreadsheet::WriteExcel)

Replies are listed 'Best First'.
Re: Multiple formats in Excel cell (Spreadsheet::WriteExcel)
by afoken (Chancellor) on Apr 05, 2015 at 14:26 UTC

    I think this is an Excel problem. As far as I know, Excel defines formats on the cell level, not on the character level. Unless you find a way to make Excel use two formats in one cell, perl can't do that, either.

    Alexander

    --
    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

      I just checked in Excel 2008 (what I have at home) and can indeed format a string like "this is a string" in a single cell. Not sure how to do it in Spreadsheet::WriteExcel, but it might be possible to save the same file with just a single filled cell in it, where the bold part is the only difference and figure it out

Re: Multiple formats in Excel cell (Spreadsheet::WriteExcel)
by choroba (Cardinal) on Apr 05, 2015 at 09:18 UTC
    Crossposted at StackOverflow. It's considered polite to inform about crossposting so people not attending both sites don't waste their time hacking a solution for a problem already solved at the other end of the internet.
    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
      Sorry - you are right. It's my first post here...
Re: Multiple formats in Excel cell (Spreadsheet::WriteExcel)
by Anonymous Monk on May 08, 2015 at 10:13 UTC
    You can do this with write_rich_string() in Excel::Writer::XLSX, the replacement for Spreadsheet::WriteExcel.
    my $bold = $workbook->add_format( bold => 1 ); my $italic = $workbook->add_format( italic => 1 ); $worksheet->write_rich_string( 'A1', 'This is ', $bold, 'bold', ' and this is ', $italic, 'italic' );