Retrieve all paragraph text, including returns

Hello,

   I am working with DocIO in my Xamarin.Forms app and need to read a table cells text but am not able to get the text with carriage returns (aka new lines).  For example if my cell text is:

Corpus Christi


Texas


78414

I get (note that I am manually adding "\r\n" to display my text with returns as it seems all carriage returns and new line characters are consumed by the WTextRange):

Corpus Christi
Texas
78414

Using the following code:

            row = section.Tables[tableVal].Rows[rowVal];
            cell = row.Cells[cellVal];
            
            foreach (WParagraph para in cell.Paragraphs)
            {
                foreach (ParagraphItem paraItem in para.ChildEntities)
                {
                    if (paraItem is WTextRange)
                    {
                        WTextRange textItem = paraItem as WTextRange;

                        if (text == "")
                        {
                            if (textItem.Text == "")
                            {
                                text = "\r\n";
                            }
                            else
                            {
                                text = textItem.Text;
                            }
                        }
                        else
                        {
                            if (textItem.Text == "")
                            {
                                text += "\r\n";
                            }
                            else
                            {
                                text += "\r\n";
                                text += textItem.Text;
                            }
                        }
                    }
                }                
            }

Question 1:  How do I get all of the cells contents including new lines
Question 2:  Is there a method that I can use to simply get all text in a cell with all of the loops?  Something like string text = cell.Paragraph.Text?

Thanks for any help you can provide.

1 Reply

MJ Mohanaselvam Jothi Syncfusion Team June 28, 2018 12:18 PM UTC

Hi Michael,

Thank you for contacting Syncfusion support.

Regarding How do I get all of the cells contents including new lines:
To achieve your requirement, we suggest you to iterate all the items in the table cell and append new line (“\r\n”) for each paragraph content. We have prepared a sample application to iterate into the table cell and get contents inside the cell.

Please find the sample from the below link and let us know if this helps you:
http://www.syncfusion.com/downloads/support/forum/138399/ze/DocIOSample172639550.zip
Note: Please find the input word document in “WordToPDF\Assests” folder location of above sample application.

Regarding Is there a method that I can use to simply get all text in a cell with all of the loops?  Something like string text = cell.Paragraph.Text?
DocIO doesn’t provide API to get the cell contents directly from the table in the Word document. To achieve your requirement, we suggest to iterate into all the items in the table cell to get cell content.


Please let us know if you have any other questions.

Regards,
Mohanaselvam J
 


Loader.
Up arrow icon