Skip to main content
Inspiring
January 11, 2024
Answered

How can I find the paragraph style (styleUID) of each cell in a table?

  • January 11, 2024
  • 2 replies
  • 518 views

Hi everyone, 
I need some help finding the paragraph style (styleUID) of each cell in a table.

So far this is what I have. 


InterfacePtr<ITableModel> tableModel(tableFrame->GetModelRef(), UseDefaultIID());

if (tableModel == nil) break;

int rows = tableModel->GetTotalRows().count;
int cols = tableModel->GetTotalCols().count;
UID currentStyle = kInvalidUID;
 
for (int r = 0; r < rows; r++)
{
for (int c = 0; c < cols; c++)
{
GridAddress address = GridAddress(r, c);
GridID gridid = tableModel->GetGridID(address);
InterfacePtr<ITableTextContainer> tableTextContainer(tableModel, UseDefaultIID());
if (tableTextContainer == nil)
break;
 
InterfacePtr<ITextModel> textModel(tableTextContainer->QueryTextModel());
if (textModel == nil)
break;
 
InterfacePtr<ITextStoryThreadDict> textStoryThreadDict(tableModel, UseDefaultIID());
if (textStoryThreadDict == nil)
break;
 
InterfacePtr<ITextStoryThread> textStoryThread(textStoryThreadDict->QueryThread(gridid));
if (textStoryThread == nil)
break;
 
InterfacePtr<ITextModel> iTextModel(textStoryThread->QueryTextModel());
if (iTextModel == nil)
break;
 
 
const UIDRef tableRef(::GetUIDRef(tableModel));
TextIndex threadStart, threadLength;
iTextModel->FindStoryThread(tableRef.GetUID(), gridid, &threadStart, &threadLength);
 
// how can I get the styleUID (Paragraph style) of this cell?
 
}
}
This topic has been closed for replies.
Correct answer Rahul_Rastogi

Hi @Chamari_Silva ,

 

Refer the below code snippet -

 

InterfacePtr<IAttributeStrand> iParaAttributeStrand(((IAttributeStrand*) iTextModel->QueryStrand(kParaAttrStrandBoss, IAttributeStrand::kDefaultIID)));
 
int32 outParaSpan = 0;
UID paraStyleUID = iParaAttributeStrand->GetStyleUID(threadStart, &outParaSpan);
 
IN Parameter - threadStart - is the TextIndex inside the cell.
OUT Parameter - outParaSpan - is the number of characters that have same paragraph style applied in the run.
 
Hope this helps.
 
- Rahul Rastogi
Adobe InDesign SDK Custom Plugin Developer
 

2 replies

Olivier Beltrami
Legend
January 11, 2024

Note that a cell may contain multiple paragraphs, each using a different paragraph style, thus the importance of outParaSpan and "the number of characters that have same paragraph style applied in the run" in @Rahul_Rastogi's answer.

Inspiring
January 11, 2024

Thank you Oliver. This is great help. 

Rahul_RastogiCorrect answer
Inspiring
January 11, 2024

Hi @Chamari_Silva ,

 

Refer the below code snippet -

 

InterfacePtr<IAttributeStrand> iParaAttributeStrand(((IAttributeStrand*) iTextModel->QueryStrand(kParaAttrStrandBoss, IAttributeStrand::kDefaultIID)));
 
int32 outParaSpan = 0;
UID paraStyleUID = iParaAttributeStrand->GetStyleUID(threadStart, &outParaSpan);
 
IN Parameter - threadStart - is the TextIndex inside the cell.
OUT Parameter - outParaSpan - is the number of characters that have same paragraph style applied in the run.
 
Hope this helps.
 
- Rahul Rastogi
Adobe InDesign SDK Custom Plugin Developer
 
Inspiring
January 11, 2024

Thank you so much Rahul