首页 > 解决方案 > 使用 xceed.words.net.docx 写入 docx,在 VS 中运行时有效,在作为内置 exe 运行时每页写入一行

问题描述

我已经使用了一段时间,它总是工作得很好。项目在运行时写入 docx 日志文件。我最近对它写入日志的路径进行了修改,以供其他人使用。从那时起,当我将它作为构建的 exe 运行时,它每页写一行。但是当我尝试解决问题时,我无法在 VS 中重新创建它运行它。从那里它像往常一样工作。

有任何想法吗?有人可以指出我的方向吗?

        public static void WritetoLogFile(string logUpdate)
    {
        DateTime now            = DateTime.Now;
        string logDate          = now.ToString("MM-dd");
        string folderNameDate   = now.ToString("MM_dd_yyyy");
        string folderName       = folderNameDate + "_Logs";
        string stateFolder      = " ";

        System.IO.Directory.CreateDirectory(Crawlspace.networkSharePath + "//" + folderName);

        string logName = logDate + "_" + Crawlspace.browser + "_" + Crawlspace.computerName + "_" + Crawlspace.SuiteTable + ".docx";
        Crawlspace.LogFileName = logName;


        System.IO.Directory.CreateDirectory(Crawlspace.networkSharePath + folderName + "//" + stateFolder);

        Crawlspace.LogFile = Crawlspace.networkSharePath + folderName + "//" + stateFolder + "//" + logName;

        if (System.IO.File.Exists(Crawlspace.LogFile))
        {
            using (DocX document = DocX.Load(Crawlspace.LogFile))
            {
                Paragraph par1 = document.InsertParagraph();
                par1.Append(logUpdate);
                par1.Font("Courier New");
                par1.FontSize(8);
                document.Save();
            }
        }
        else
        {
            using (DocX document = DocX.Create(Crawlspace.LogFile))
            {
                Paragraph par1 = document.InsertParagraph();
                par1.Append(logUpdate);
                par1.Font("Courier New");
                par1.FontSize(8);
                document.Save();
            }
        }
    }

标签: c#.netdocxxceed

解决方案


解决:

我在 nuget 管理器中检查了 xceed.words.net.docx dll,发现有更新。更新到最新并修改了我的 using 语句以反映更新,它现在正在工作......

using Image     = Xceed.Document.NET.Image;
using Paragraph = Xceed.Document.NET.Paragraph;
using Picture   = Xceed.Document.NET.Picture;

推荐阅读