关闭

word转html

标签: .NETC#htmlword
86人阅读 评论(0) 收藏 举报
分类:
以前知道word/PDF在线预览都是用aspose,但实际使用时发现aspose处理页码有问题,会丢页,今天又找了找原生的word在线预览的实现方案,小文件测试没有问题,大文件还没测试,没有找到太大的word文件。。。word中有图片会在本地生成个对应的图片文件夹,如果有朋友有大的word文件也 测测,顺便告诉我一下
using System.Web.Mvc;
using Microsoft.Office;
using Microsoft.Office.Interop.Word;
namespace WebApplication1.Controllers
{
    public class HomeController : Controller
    {
        public void Test()
        {
            Microsoft.Office.Interop.Word.ApplicationClass objWord = new ApplicationClass();
            object fltDocFormat = 10; //For filtered HTML Output
            object missing = System.Reflection.Missing.Value;
            object readOnly = false; //Open file in readOnly mode

            object isVisible = false;//The process has to be in invisible mode
            object FileName =Server.MapPath("test.docx");
            object FileToSave = Server.MapPath("test.htm");
            objWord.Documents.Open(ref FileName, ref readOnly, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref isVisible, ref missing, ref missing, ref missing, ref missing, ref missing);
            objWord.Visible = false;
            Microsoft.Office.Interop.Word.Document oDoc = objWord.ActiveDocument;
            oDoc.SaveAs(ref FileToSave, ref fltDocFormat, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);
            objWord.Quit(ref missing, ref missing, ref missing);
        }
    }
}

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:40220次
    • 积分:816
    • 等级:
    • 排名:千里之外
    • 原创:42篇
    • 转载:14篇
    • 译文:0篇
    • 评论:4条
    文章分类
    最新评论