none
how to load(import) word table C# RRS feed

  • Question

  • hello,

    my program load and edit ms word (.doc,.docx) for users.

    What i want to read table data(cell) and to recognize table's rows and columns.

    what can i do?

    Saturday, November 15, 2014 10:39 AM

Answers

  • Hello,

       If you use VSTO, try following source code,
     List<Word.Range> TablesRanges = new List<Word.Range>();
    
            wordApp = new Microsoft.Office.Interop.Word.Application();
            doc = wordApp.Documents.OpenNoRepairDialog(FileName: @"c:\AAAAA.docx", ConfirmConversions: false, ReadOnly: true, AddToRecentFiles: false, NoEncodingDialog: true);
    
    
            for (int iCounter = 1; iCounter <= doc.Tables.Count; iCounter++)
            {
                Word.Range TRange = doc.Tables[iCounter].Range;
                TablesRanges.Add(TRange);
            }
    
            Boolean bInTable;
            for (int par = 1; par <= doc.Paragraphs.Count; par++)
            {
                bInTable = false;
                Word.Range r = doc.Paragraphs[par].Range;
                foreach (Word.Range range in TablesRanges)
                {
                    if (r.Start >= range.Start && r.Start <= range.End)
                    {
                        Console.WriteLine("In Table - Paragraph number " + par.ToString() + ":" + r.Text);
                        bInTable = true;
                        break;
                    }
    
                }
    
                if (!bInTable)
                    Console.WriteLine("!!!!!! Not In Table - Paragraph number " + par.ToString() + ":" + r.Text);
            }

    ---------------------------------------

     if the reply help you mark it as your answer.
     Free No OLE C# PowerPoint, Word ExcelPDF  Component(Create, Modify, Convert & Print)


    Tuesday, November 18, 2014 2:02 AM

All replies

  • Are you using COM Automation via Interop (or VSTO) or are you using a library such as the Open XML SDK?

    Or maybe you are trying to decide?
     


    Peter Jamieson

    Sunday, November 16, 2014 10:33 AM
  • Hello,

       If you use VSTO, try following source code,
     List<Word.Range> TablesRanges = new List<Word.Range>();
    
            wordApp = new Microsoft.Office.Interop.Word.Application();
            doc = wordApp.Documents.OpenNoRepairDialog(FileName: @"c:\AAAAA.docx", ConfirmConversions: false, ReadOnly: true, AddToRecentFiles: false, NoEncodingDialog: true);
    
    
            for (int iCounter = 1; iCounter <= doc.Tables.Count; iCounter++)
            {
                Word.Range TRange = doc.Tables[iCounter].Range;
                TablesRanges.Add(TRange);
            }
    
            Boolean bInTable;
            for (int par = 1; par <= doc.Paragraphs.Count; par++)
            {
                bInTable = false;
                Word.Range r = doc.Paragraphs[par].Range;
                foreach (Word.Range range in TablesRanges)
                {
                    if (r.Start >= range.Start && r.Start <= range.End)
                    {
                        Console.WriteLine("In Table - Paragraph number " + par.ToString() + ":" + r.Text);
                        bInTable = true;
                        break;
                    }
    
                }
    
                if (!bInTable)
                    Console.WriteLine("!!!!!! Not In Table - Paragraph number " + par.ToString() + ":" + r.Text);
            }

    ---------------------------------------

     if the reply help you mark it as your answer.
     Free No OLE C# PowerPoint, Word ExcelPDF  Component(Create, Modify, Convert & Print)


    Tuesday, November 18, 2014 2:02 AM