Page 1 of 1

How To Get Table Cell's Font Name And Size?

Posted: Wed Sep 10, 2008 3:47 pm
by fchintc
I have a table with two columns and I want to insert text in the cell at row 0 and column 0. How do I find the font name and size used in the cell(0,0)?

My current code is:-

Code: Select all

table.Cells[0,0].Clear;

// Code to get font name and size?

table.Cells[0,0].AddNLATag('Some Text', ?, ?, 0);
Frederick

Posted: Thu Sep 11, 2008 8:46 am
by Sergey Tkachenko
Initially, the 0th text and the 0th paragraph styles are used.
But if the table is not empty, the cell may contain several text items of several text styles and several paragraphs of several paragraph styles.
Which one do you want to use?

Posted: Thu Sep 11, 2008 9:49 am
by fchintc
I would like to use the style from the first available format. Currently, my Style component that is linked to the DBRichEdit has a font name of Arial with size 10. However, the table cell at row 0, column 0, which is blank, is formatted with a font of Times New Roman and size 12.

Frederick

Posted: Thu Sep 11, 2008 10:48 am
by Sergey Tkachenko

Code: Select all

// Returns the style of the first text item in RVData (having empty tag)
function GetFirstTextStyleNo(RVData: TCustomRVData): Integer;
var i: Integer;
begin
  Result := 0;
  for i := 0 to RVData.ItemCount-1 do
    if (RVData.GetItemStyle(i)>=0) and (RVData.GetItemTag(i)=0) then begin
      Result := RVData.GetItemStyle(i);
      exit;
    end;
end;
// Returns the style of the first paragraph in RVData
function GetFirstParaStyleNo(RVData: TCustomRVData): Integer;
begin
  if RVData.ItemCount>0 then
    Result := RVData.GetItemPara(0)
  else
    Result := 0;
end;

Code: Select all

StyleNo := GetFirstTextStyleNo(table.Cells[0,0]);
ParaNo  := GetFirstParaStyleNo(table.Cells[0,0]);
table.Cells[0,0].Clear; 
table.Cells[0,0].AddNLATag('Some Text', StyleNo, ParaNo, 0);

Posted: Thu Sep 11, 2008 2:30 pm
by fchintc
Thanks for your help.

Frederick