Skip to main content
Known Participant
March 26, 2024
Answered

Get width of a table column in InDesign C++ SDK

  • March 26, 2024
  • 1 reply
  • 354 views

Hello,

 

I am having the following code snippet to get the width of a specific column of a InDesign table

 

InterfacePtr<ITableSuite> tableSuite(..);

 
// code to select text in cell (0,2) to get the width of column 2
 
if (tableSuite->CanGetColumnSize())
{
PMReal columnsize = tableSuite->GetColumnSize();
colWidth = ::ToDouble(columnsize);
}
 
For some reason, this is always giving me the width of column 0. Is this the right way or are there other ways of getting column width of a specific column?
 
Thanks
This topic has been closed for replies.
Correct answer Rahul_Rastogi

Refer the following code snippet -

 

InterfacePtr<ITableModel> iTableModel(tableModelRef, UseDefaultIID());
InterfacePtr<ITableCommands> iTableCommands(tableModelRef, UseDefaultIID());
 
InterfacePtr<ITableAttrAccessor> iTableAttrAccessor(iTableModel, UseDefaultIID());
 
 
InterfacePtr<ITableAttrRealNumber> iTableColumnWidth((ITableAttrRealNumber*)iTableAttrAccessor->QueryColAttribute(columnIndex, kColAttrWidthBoss, IID_ITABLEATTRREALNUMBER));
// pass the correct columnIndex
 
colWidth = ::ToDouble(iTableColumnWidth->Get());
 
- Rahul Rastogi
Adobe InDesign C++ Custom Plugin Architect

1 reply

Rahul_RastogiCorrect answer
Inspiring
March 26, 2024

Refer the following code snippet -

 

InterfacePtr<ITableModel> iTableModel(tableModelRef, UseDefaultIID());
InterfacePtr<ITableCommands> iTableCommands(tableModelRef, UseDefaultIID());
 
InterfacePtr<ITableAttrAccessor> iTableAttrAccessor(iTableModel, UseDefaultIID());
 
 
InterfacePtr<ITableAttrRealNumber> iTableColumnWidth((ITableAttrRealNumber*)iTableAttrAccessor->QueryColAttribute(columnIndex, kColAttrWidthBoss, IID_ITABLEATTRREALNUMBER));
// pass the correct columnIndex
 
colWidth = ::ToDouble(iTableColumnWidth->Get());
 
- Rahul Rastogi
Adobe InDesign C++ Custom Plugin Architect
asaxenaAuthor
Known Participant
March 26, 2024

Thank you. Works like a charm!