Reading .doc file without launching MSWord

后端 未结 3 856
广开言路
广开言路 2021-01-19 10:34

I\'m trying to open .doc file and read its content. But i can\'t find any way how to do this without launching MSWord.

Now I have following code:

Mic         


        
3条回答
  •  隐瞒了意图╮
    2021-01-19 11:11

    Add the Namespace using Add Reference-->Browse-->Code7248.word_reader.dll

    Download dll from the given URL :

    sourceforge.net/p/word-reader/wiki/Home

    (A simple .NET Library compatible with .NET 2.0, 3.0, 3.5 and 4.0 for C#. It can currently extract only the raw text from a .doc or .docx file.)

    The Sample Code is in simple Console in C#:

    using System;
    using System.Collections.Generic;
    using System.Text;
    //add extra namespaces
    using Code7248.word_reader;
    
    
    namespace testWordRead
    {
        class Program
        {
            private void readFileContent(string path)
            {
                TextExtractor extractor = new TextExtractor(path);
                string text = extractor.ExtractText();
                Console.WriteLine(text);
            }
            static void Main(string[] args)
            {
                Program cs = new Program();
                string path = "D:\Test\testdoc1.docx";
                cs.readFileContent(path);
                Console.ReadLine();
            }
        }
    }
    

    It is working fine.

提交回复
热议问题