Skip to main content
Chinnadk
Legend
October 22, 2016
Answered

How to get a cell count of a column?

  • October 22, 2016
  • 1 reply
  • 1171 views

Hi All,

How to get a cell count of a column?

Regards,

Chinna

This topic has been closed for replies.
Correct answer Norio Kawamura

Sorry, checking IIDXMLElement is no good.

Remove (skip) kTextChar_ZeroSpaceNoBreak (xmltag mark) char in cell text.


// Have you resolved?

InterfacePtr<ITableTextContainer> tableTextContainer(tableModel, UseDefaultIID()); 

InterfacePtr<ITextModel> textModel(tableTextContainer->QueryTextModel()); 

InterfacePtr<IComposeScanner> composeScanner(textModel, UseDefaultIID());

InterfacePtr<ITextStoryThreadDict> textStoryThreadDict(tableModel, UseDefaultIID()); 

//int32 totalRowsCount = tableModel->GetTotalRows().count;

//int32 totalColsCount = tableModel->GetTotalCols().count;

ITableModel::const_iterator iterTable(tableModel->begin());

ITableModel::const_iterator end(tableModel->end());

while (iterTable != end) {

  GridAddress gridAddress = *iterTable;

  GridSpan gridSpan = tableModel->GetCellSpan(gridAddress);

  GridArea gridArea(gridAddress, gridSpan);

  const GridID gridID = tableModel->GetGridID(gridAddress);

  InterfacePtr<ITextStoryThread> textStoryThread(textStoryThreadDict->QueryThread(gridID));

  if (textStoryThread == nil) {

  iterTable++;

  continue;

  }

  TextIndex threadStart = 0;

  int32 threadLength = -1;

  threadStart = textStoryThread->GetTextStart(&threadLength);

  int32 cellStrLength = threadLength - 1;

  PMString cellStr;

  if (cellStrLength > 0) {

  WideString tempCopy;

  composeScanner->CopyText(threadStart, cellStrLength, &tempCopy);

  cellStr = PMString(tempCopy);

  // remove kTextChar_ZeroSpaceNoBreak (xmltag mark)

  for (int32 i=0; i<cellStrLength; i++) {

  UTF32TextChar uniChar = cellStr.GetWChar(i);

  if (uniChar == kTextChar_ZeroSpaceNoBreak) {

  cellStr.Remove(i);

  cellStrLength--;

  i--;

  }

  }

  }

  //cellStrlength = cellStr.WCharLength();

  PMString infoStr("row:");

  infoStr.AppendNumber(gridAddress.row+1);

  infoStr.Append(", col:");

  infoStr.AppendNumber(gridAddress.col+1);

  infoStr.Append(", rowSpan:");

  infoStr.AppendNumber(gridArea.Height());

  infoStr.Append(", colSpan:");

  infoStr.AppendNumber(gridArea.Width());

  infoStr.Append(", textLength:");

  infoStr.AppendNumber(cellStrLength);

  if (cellStrLength > 0) {

  infoStr.Append(", text:");

  infoStr.Append(cellStr);

  }

  CAlert::InformationAlert(infoStr);

  iterTable++;

}

1 reply

Inspiring
October 24, 2016

Are you asking about merged cells?

Chinnadk
ChinnadkAuthor
Legend
October 25, 2016

Thanks for your reply,

I got the solution for my question. But I need a clarification on the below.

I need to get the character count for each cell in the column. I'm using this code, it gives character count exactly when it is not an xml element. If it is an xml element it counts including xml tags.

Is it possible to get only the characters count in the cell not the xml tags.

for(int j=0;j<colcount;j++)

{

  for(int k=0;k<rowcount;k++)

  {

  GridAddress gridAddress(k,j);

  const GridID gridID = tableModel->GetGridID(gridAddress);

  InterfacePtr<ITableTextContainer> tableTextContainer(tableModel, UseDefaultIID());

  InterfacePtr<ITextModel> textModel(tableTextContainer->QueryTextModel());

  InterfacePtr<ITextStoryThreadDict> textStoryThreadDict(tableModel, UseDefaultIID());

  InterfacePtr<ITextStoryThread> textStoryThread(textStoryThreadDict->QueryThread(gridID));

  TextIndex threadStart;

  int32 threadLength;

  threadStart = textStoryThread->GetTextStart(&threadLength);

  WideString wstr;

  TextIterator beginTextChunk(textModel, threadStart);

  TextIterator endTextChunk(textModel, threadStart + threadLength);

  std::copy(beginTextChunk, endTextChunk, std::back_inserter(wstr));

  PMString sysString;

  wstr.GetSystemString(&sysString);

  int32 charcount;

  charcount = sysString.CharCount();

  sysString.AppendNumber(sysString.ByteLength());

  CAlert::InformationAlert(sysString);

  }

  }

Regards,

Chinna

Chinnadk
ChinnadkAuthor
Legend
October 25, 2016

If the cell has IIDXMLElement, minus 2.

Refer ::InspectTable() in sdksamples/codesnippets/SnpInspectSelectionXMLProperties.cpp.


Hi Norio,

I'm not clear on this. Could you please write down the lines of code if possible.

Regards,

Chinna