Recent

Author Topic: How to bold some characters of a cell?  (Read 683 times)

Jvan

  • Full Member
  • ***
  • Posts: 156
How to bold some characters of a cell?
« on: April 13, 2021, 10:06:51 pm »
I wanna bolt from character 0 to 5, for instance. How to do it?

wp

  • Hero Member
  • *****
  • Posts: 8413
Re: How to bold some characters of a cell?
« Reply #1 on: April 14, 2021, 12:36:50 am »
You can add an optional array of "rich-text parameters" to the WriteText command; each element of this array contains the character index at which the font specified by its font index will be applied until revoked by another rich-text element.

It is easier, however, when you write html codes to the cell:

Code: Pascal  [Select][+][-]
  1. program Project1;
  2.  
  3. uses
  4.   fpspreadsheet, fpstypes, fpsopendocument;
  5. var
  6.   wb: TsWorkbook;
  7.   sh: TsWorksheet;
  8. begin
  9.   wb := TsWorkbook.Create;
  10.   try
  11.     sh := wb.AddWorksheet('Page 1');
  12.  
  13.     sh.WriteTextAsHTML(0, 0, '<b>12345</b>6789');
  14.     sh.WriteTextAsHTML(1, 0, 'This is <b>bold</b>.');
  15.     sh.WriteTextAsHTML(2, 0, '10 cm<sup>3</sup>');
  16.     sh.WriteTextAsHTML(3, 0, '<font color="red">red</font> <font color="green">green</font> <font color="blue">blue</font>');
  17.     sh.WriteTextAsHTML(4, 0, 'This is <u><i>important</i></u>');
  18.     sh.WriteTextAsHTML(5, 0, 'This is <s>wrong</s>');
  19.  
  20.     wb.WriteToFile('test.ods', true);
  21.   finally
  22.     wb.Free;
  23.   end;
  24. end.

See also: https://wiki.lazarus.freepascal.org/FPSpreadsheet#Rich-text_formatting

Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

Jvan

  • Full Member
  • ***
  • Posts: 156
Re: How to bold some characters of a cell?
« Reply #2 on: April 14, 2021, 03:12:04 am »
Thanks, it works.

 

TinyPortal © 2005-2018