C# Word替换文本
引用 Nuget包 Spire.Doc
使用Spire.Doc会在文档开头生成水印
using (Document doc = new Document(templateWordFilePath))
{
    doc.Replace("oldvalue", "newvalue", true, false);
    wordTempFilePath = Path.Combine(SavePath, $"Temp.docx");
    doc.SaveToFile(wordTempFilePath, FileFormat.Docx2013);
}
引用 Nuget包 DocX
使用docx去除水印文字
using (var doc = DocX.Load(wordTempFilePath))
{
    doc.ReplaceText("Evaluation Warning: The document was created with Spire.Doc for .NET.", "");
    wordFilePath = Path.Combine(SavePath, $"newFile.docx");
    filePathList.Add(wordFilePath);
    doc.SaveAs(wordFilePath);
}
原因:直接使用docx老版本的文件无法读取,会提示文件损坏,所以先使用可以打开老版本word的,生成一个新版本word,再去替换水印
相关推荐:
https://github.com/eiceblue/Spire.Doc-for-.NET
Spire.Doc去水印
https://blog.csdn.net/zhuozhitao510/article/details/123878867
DocX文档操作
https://blog.csdn.net/pengze0902/article/details/53366270
https://blog.csdn.net/shu19880720/article/details/125725015
 
                     
                    
                 
                    
                 
                
            
         
 
         浙公网安备 33010602011771号
浙公网安备 33010602011771号