Convert Table in Word document to Text

Hi,

Is there any API that converts table to text directly. Which works as ‘Convert To Text’ functionality of MS WORD. In which it can be specified if we want to separate text with ‘TAB’, ‘Comma’ or something else. Similar to what is done in Word.

Thanks

@cvsformulary,

We have logged your requirement in our issue tracking system. Your ticket number is WORDSNET-17626 . We will further look into the details of this requirement and will keep you updated on the status of the linked issue.

@cvsformulary,

Please use the following code to convert Table in Word document to Text:

public static void ConvertTableToText()
{
    string separator = ControlChar.Tab;
    Document doc = new Document("D:\\temp\\Table.docx");

    Table table = (Table)doc.GetChild(NodeType.Table, 0, true);
    Node currentPara = table.NextSibling;
    foreach (Row row in table.Rows)
    {
        foreach (Cell cell in row.Cells)
        {
            NodeCollection paragraphs = cell.GetChildNodes(NodeType.Paragraph, true);
            foreach (Paragraph paragraph in paragraphs)
            {
                if (paragraphs.Count > 1 && !paragraph.Equals(cell.FirstParagraph))
                {
                    Node node = table.ParentNode.InsertAfter(paragraph.Clone(true), currentPara);
                    currentPara = node;
                }
                else if (currentPara.NodeType == NodeType.Paragraph)
                {
                    if (!cell.IsFirstCell)
                        ((Paragraph)currentPara).AppendChild(new Run(doc, separator));
                    if (paragraph.ChildNodes.Count > 0)
                        foreach (Node node in paragraph.ChildNodes)
                        {
                            ((Paragraph)currentPara).AppendChild(node.Clone(true));
                        }
                            
                    ((Paragraph)currentPara).ParagraphFormat.FirstLineIndent = 0;
                    ((Paragraph)currentPara).ParagraphFormat.LeftIndent = 0;
                }
            }
        }
        ((Paragraph)currentPara).Runs.Add(new Run(doc, ControlChar.ParagraphBreak));
    }

    table.Remove();
    doc.Save("D:\\Temp\\18.11.docx");
} 

Hope, this helps.