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

General TRichView support forum. Please post your questions here
Post Reply
fchintc
Posts: 47
Joined: Thu Oct 25, 2007 2:49 pm

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

Post 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
Sergey Tkachenko
Site Admin
Posts: 17555
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post 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?
fchintc
Posts: 47
Joined: Thu Oct 25, 2007 2:49 pm

Post 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
Sergey Tkachenko
Site Admin
Posts: 17555
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post 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);
fchintc
Posts: 47
Joined: Thu Oct 25, 2007 2:49 pm

Post by fchintc »

Thanks for your help.

Frederick
Post Reply