0

As I understand it - the shortest way is to convert file to XML. That would then allow to find the table by tag.

var fileinfo = new FileInfo(@"c:\Users\a1oleg\Desktop\myFile.docx");                        

XDocument xml = null;
using (StreamReader oReader = new StreamReader(fileinfo.FullName)
{                
    xml = XDocument.Load(oReader);
}

The error is:

System.Xml.XmlException: 'Data at the root level is invalid. Line 1, position 1.'

Striezel
  • 3,693
  • 7
  • 23
  • 37
a1oleg
  • 73
  • 7

1 Answers1

0

Well you can use Microsoft.Office.Interop.Word

Microsoft.Office.Interop.Word.Application app = new Microsoft.Office.Interop.Word.Application();
Documents docs = app.Documents;
Document doc = docs.Open("C:\\users\\Test.docx", ReadOnly:true);
Table tbl = doc.Tables[1];
Range rg = tbl.Range;
Cells cells = rg.Cells;
Prany
  • 2,078
  • 2
  • 13
  • 31
  • with Project - Properties - Build - Target Platform: Any CPU || x64 The error is: > System.Runtime.InteropServices.COMException: 'Retrieving the COM class factory for component with CLSID {000209FF-0000-0000-C000-000000000046} failed due to the following error: 80040154 Класс не зарегистрирован (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).' with x86 Drops out of the debug with no result, without reaching the breakpoint after your code. – a1oleg Jun 10 '18 at 05:03
  • 1
    answer to this error can be found here- https://stackoverflow.com/questions/35284589/system-runtime-interopservices-comexception-retrieving-the-com-class-factory-fo – Prany Jun 10 '18 at 05:22