在不使用Interop的情况下读取doc(word)文件 [英] Reading the doc (word) file without using Interop

查看:107
本文介绍了在不使用Interop的情况下读取doc(word)文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



是否有任何可能的方法来读取doc文件中的数据而不使用Interop。我尝试过使用StreamReader,但我以非人类可读的格式获取数据。



提前致谢。

Hi,
Is there is a any possible way to read data in doc file without using Interop. I have tried with StreamReader but I m getting the data in non human readable format.

Thanks in advance.

推荐答案

你必须自己解析 Word 文件格式( Microsoft 轻轻提供其规范:Microsoft Office文件格式 [ ^ ])。我猜是可行但很难
You have to parse yourself the Word file format (Microsoft gently provides its specification: "Microsoft Office File Formats"[^] ). Feasible but hard, I guess.


你应该检查下面的资源。



1。 在没有安装Office的服务器上操作Word文档(ASP.NET) [ ^ ]。

2. 不使用Interop.word dll读取word文件...不想在IIS中安装单词。 [ ^ ]。
You should check the below resources.

1. Manipulating Word documents on server without Office installed (ASP.NET)[^].
2. Read a word file without using Interop.word dll...Do not want to install word in IIS..[^].


使用添加引用添加命名空间 - >浏览 - > Code7248。来自给定URL的word_reader.dll:

Code7248.word_reader / Wiki / Home [ ^ ] [ ]

(与.NET兼容的简单.NET库) C#为2.0,3.0,3.5和4.0。它目前只能从.doc或.docx文件中提取原始文本。)



示例代码在C#中的简单控制台中:



Add the Namespace using Add Reference-->Browse-->Code7248.word_reader.dll from the given URL :
Code7248.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.


这篇关于在不使用Interop的情况下读取doc(word)文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆