NPOI实现word模板替换2
using System;
using System.IO;
namespace WordExportDemo
{
internal class Program
{
private static void Main(string[] args)
{
string root = System.AppDomain.CurrentDomain.BaseDirectory;
string tempPath = root + Path.Combine("TempleCourt", "调解笔录2.docx");
CourtRecord model = new CourtRecord();
model.title = "福州市仲裁院";
model.time = "2021年9月17号20点55分";
model.address = "福州市鼓楼区";
model.caseNo = "福仲案001号";
MemoryStream ms = DocHelper.ExportDoc<CourtRecord>(model, tempPath);
byte [] dataByte= ms.ToArray();
string docPath = root + Path.Combine("TempleCourt",DateTime.Now.ToString("yyyyMMddhh")+"调解笔录.docx");
if (File.Exists(docPath) == false)
{
File.Create(docPath);
}
using (FileStream fs = new FileStream(docPath, FileMode.Create))
{
fs.Write(dataByte, 0, dataByte.Length);
}
Console.WriteLine("导出完成,"+ docPath);
Console.ReadKey();
}
}
}
本文来自博客园,作者:.net&new,转载请注明原文链接:https://www.cnblogs.com/wugh8726254/p/15306353.html