Community

How to get cell value from ITableBlock object

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.

0

Comments

2 comments

  • Avatar
    Robert Klaij

    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; }

    2
    Comment actions Permalink
  • Avatar
    Shaown

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

    0
    Comment actions Permalink

Please sign in to leave a comment.