Retrieving table data from a doc file using c#

笑着哭i 提交于 2019-12-07 19:16:52

问题


I am working on a project which involves getting data from a .doc or a .docx file. The input requirements are in a tabular format. Is it possible to retrieve data from table in a row wise manner or as a dataset.I am using Microsoft.Office.Interop.Word to get the data from the doc file.


回答1:


You can use the property Tables of the Document interface to get a collection with all the tables in your document. For each Table in this collection you can get the rows and for each row the cells.

I.e. if app is your Application object you can write something like this to get the text contained in each cell(supposing that there is exactly one in your doc):

    string aCellText;
    foreach (Row aRow in Application.ActiveDocument.Tables[0].Rows)
        foreach (Cell aCell in aRow.Cells)
            aCellText = aCell.Range.Text;



回答2:


That is not possible with the word, but if you want something like that than you should put tabular data in you excel file and than you can easily read it in the dataset object....




回答3:


this is not possible to get the data in dataset object from .doc or .docx file. But if your data is in tabular form and also in the excel sheet than you can retrieve the data in dataset object. MS Word is for documentation purpose and excel is used for maintaining data sheets..



来源:https://stackoverflow.com/questions/10696591/retrieving-table-data-from-a-doc-file-using-c-sharp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!