How to get cell value from ITableBlock object

  • 1.3K Views
  • Last Post 24 September 2016
Shaown posted this 20 September 2016

I have object of tableblock type ie: fields.getElement(0).getBlocks().Item(0).AsTableBlock(). Now my concern is how can I get the cell data as IField/IFieldValue type. I try to extract the cell data. So is it possible to get cell value as IField type or how can I get the cell data as text. My tableBlock data are all text type.

Order By: Standard | Newest | Votes
Robert Klaij posted this 21 September 2016

I used a loop to cycle through all the cells of the TableBlock and for each cell get the data out of it. Hope this gives you an idea how to solve it.

private static string ProcessTable(IBlock Block) { string OutputString = ""; ITableBlock TableBlock = Block.GetAsTableBlock(); if (TableBlock != null) { for (int CellCount = 0; CellCount < TableBlock.Cells.Count; CellCount++) { ITableCell CellData = TableBlock.Cells[CellCount]; if (CellData != null) { IBlock CellBlock = CellData.Block; if (CellBlock.Type == BlockTypeEnum.BT_Text) { OutputString += ProcessText(CellBlock); } else if (CellBlock.Type == BlockTypeEnum.BT_Table) { OutputString += ProcessTable(CellBlock); } } } } else { // write in Errorlog read failed } return OutputString; } private static string ProcessText(IBlock Block) { string OutputString = ""; TextBlock textblock = Block.GetAsTextBlock(); if (textblock != null) { for (int ParagraphCount = 0; ParagraphCount < textblock.Text.Paragraphs.Count; ParagraphCount++ ) { int t = textblock.Text.Paragraphs[ParagraphCount].Words.Count; Paragraph Paragraph = textblock.Text.Paragraphs[ParagraphCount]; for (int WordCount = 0; WordCount < Paragraph.Words.Count; WordCount++ ) { Word Word = Paragraph.Words[WordCount]; OutputString += Word.Text + " "; } } } else { // write in Errorlog read failed } return OutputString; }

  • Liked by
  • Natalia Karaseva
  • Shaown
Shaown posted this 24 September 2016

thanks Robert for the reply....I placed the idea in my queue.

Close