转换的.doc为html的使用Visual Studio 2010例preSS保存/ [英] Save/Convert .doc as .html using Visual Studio 2010 Express

查看:191
本文介绍了转换的.doc为html的使用Visual Studio 2010例preSS保存/的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有,我想转换为HTML,以便进一步处理word文档的文件夹。我只有Visual Studio 2010的前preSS版。是否有可能使用EX preSS版?我发现示例如何进行转换,但他们需要的Microsoft.Office.Tools.Word库,它没有配备防爆preSS。

I have a folder of word documents that I want to convert to html for further processing. I only have Visual Studio 2010 Express edition. Is it possible using the express edition? I've found examples for how to do the conversion, but they require the Microsoft.Office.Tools.Word library, which doesn't come with Express.

编辑:我发现,它实际上是在所谓的Microsoft Word 12.0对象库的COM对象,这是的Microsoft.Office.Interop.Word命名空间

I found it, it's actually in the COM object called Microsoft Word 12.0 Object Library, which is the Microsoft.Office.Interop.Word namespace.

推荐答案

您应该能够与前preSS版本做到这一点。我适应的答案,<一个href="http://stackoverflow.com/questions/607669/how-do-i-convert-word-files-to-pdf-programmatically">this问题。在改编code是如下。你需要添加一个引用的Microsoft.Office.Interop.Word这个工作。如果你错过了这个库,看看这篇文章在MSDN上

You should be able to do it with the express version. I adapted an answer to this question. The adapted code is below. You'll need to add a reference to Microsoft.Office.Interop.Word for this to work. If you're missing this library, have a look at this article on MSDN.

看着<一href="http://msdn.microsoft.com/en-us/library/microsoft.office.interop.word.wdsaveformat.aspx">WdSaveFormat你也可以将其保存为格式Filtered HTML(wdFormatFilteredHTML)。

Looking at WdSaveFormat you can also save it as Format Filtered HTML (wdFormatFilteredHTML).

namespace Sample {
    using Microsoft.Office.Interop.Word;
    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    using System.Text;

    class Program {

        public static void Main()
        {
            Convert("C:\\Documents", WdSaveFormat.wdFormatHTML);
        }

        private static void Convert(string path, WdSaveFormat format)
        {

            DirectoryInfo dirInfo = new DirectoryInfo(path);
            FileInfo[] wordFiles = dirInfo.GetFiles("*.doc");
            if (wordFiles.Length == 0) {
                return;
            }

            object oMissing = System.Reflection.Missing.Value;
            Microsoft.Office.Interop.Word.Application word = new Microsoft.Office.Interop.Word.Application();
            try {
                word.Visible = false;
                word.ScreenUpdating = false;
                foreach (FileInfo wordFile in wordFiles) {
                    Object filename = (Object)wordFile.FullName;
                    Document doc = word.Documents.Open(ref filename, ref oMissing,
                                                       ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
                                                       ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
                                                       ref oMissing, ref oMissing, ref oMissing, ref oMissing);
                    try {
                        doc.Activate();
                        object outputFileName = wordFile.FullName.Replace(".doc", ".html");
                        object fileFormat = format;
                        doc.SaveAs(ref outputFileName,
                                   ref fileFormat, ref oMissing, ref oMissing,
                                   ref oMissing, ref oMissing, ref oMissing, ref oMissing,
                                   ref oMissing, ref oMissing, ref oMissing, ref oMissing,
                                   ref oMissing, ref oMissing, ref oMissing, ref oMissing);

                    }
                    finally {
                        object saveChanges = WdSaveOptions.wdDoNotSaveChanges;
                        ((_Document)doc).Close(ref saveChanges, ref oMissing, ref oMissing);
                        doc = null;
                    }
                }

            }
            finally {
                ((_Application)word).Quit(ref oMissing, ref oMissing, ref oMissing);
                word = null;
            }
        }
    }
}

这篇关于转换的.doc为html的使用Visual Studio 2010例preSS保存/的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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