App_Code/WordPreview.cs

(开头部分) 2KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

using Microsoft.Office.Interop.Word;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Web;

/// <summary>
/// Summary description for WordPreview
/// </summary>
public class WordPreview
{
    public static void Priview(System.Web.UI.Page p, string inFilePath, string outDirPath = "")
    {
        object missingType = Type.Missing;
        object readOnly = true;
        object isVisible = false;
        object documentFormat = 8;
        string randomName = DateTime.Now.Ticks.ToString();
        object htmlFilePath = outDirPath + randomName + ".htm";
        string directoryPath = outDirPath + randomName + "_files";

        object filePath = inFilePath;
        //Open the word document in background
        ApplicationClass applicationclass = new ApplicationClass();
        applicationclass.Documents.Open(ref filePath,
                                        ref readOnly,
                                        ref missingType, ref missingType, ref missingType,
                                        ref missingType, ref missingType, ref  missingType,
                                        ref missingType, ref missingType, ref isVisible,
                                        ref missingType, ref missingType, ref missingType,
                                        ref missingType, ref missingType);
        applicationclass.Visible = false;
        Document document = applicationclass.ActiveDocument;

        //Save the word document as HTML file
        document.SaveAs(ref htmlFilePath, ref documentFormat, ref missingType,
                        ref missingType, ref missingType, ref missingType,
                        ref missingType, ref missingType, ref missingType,
                        ref missingType, ref missingType, ref missingType,
                        ref missingType, ref missingType, ref missingType,
                        ref missingType);

        //Close the word document
        document.Close(ref missingType, ref missingType, ref missingType);

        #region Read the Html File as Byte Array and Display it on browser
        //byte[] bytes;
        //using (FileStream fs = new FileStream(htmlFilePath.ToString(), FileMode.Open, FileAccess.Read))
        //{
        //    BinaryReader reader = new BinaryReader(fs);
        //    bytes = reader.ReadBytes((int)fs.Length);
        //    fs.Close();
        //}
        //p.Response.BinaryWrite(bytes);
        //p.Response.Flush();
        //p.Response.End();
        #endregion

后面还有 15 行代码,解锁后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。