How can I set font color in cell (half text other color) in delphi 7 and with MS Excel 2007+ ?
Example:
You use the Characters
property of a cell to apply per-character formatting. Here is a very simple example:
uses
ComObj, ActiveX, Graphics;
var
Excel: OleVariant;
Book: OleVariant;
Cell: OleVariant;
begin
CoInitialize(nil);
Excel := CreateOleObject('Excel.Application');
Book := Excel.WorkBooks.Add;
Cell := Excel.Cells[1,1];
Cell.Value := 'I DON''T SAY BLEH BLEH BLEH!!!';
Cell.Characters(13, 14).Font.Color := clRed;
Book.SaveAs('temp.xlsx');
Excel.Quit;
end.
Here 13 is the index of the first character, and 14 is the number of characters to select.
This uses late binding. If you prefer early binding then I would expect that the code would need a little adjustment.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With