private void button3_Click(object sender, EventArgs e)
{
string sourcePath =Environment.CurrentDirectory + "/temple/" + "2.doc";
new Aspose.Words.License().SetLicense(new MemoryStream(Convert.FromBase64String("PExpY2Vuc2U+CiAgPERhdGE+CiAgICA8TGljZW5zZWRUbz5TdXpob3UgQXVuYm94IFNvZnR3YXJlIENvLiwgTHRkLjwvTGljZW5zZWRUbz4KICAgIDxFbWFpbFRvPnNhbGVzQGF1bnRlYy5jb208L0VtYWlsVG8+CiAgICA8TGljZW5zZVR5cGU+RGV2ZWxvcGVyIE9FTTwvTGljZW5zZVR5cGU+CiAgICA8TGljZW5zZU5vdGU+TGltaXRlZCB0byAxIGRldmVsb3BlciwgdW5saW1pdGVkIHBoeXNpY2FsIGxvY2F0aW9uczwvTGljZW5zZU5vdGU+CiAgICA8T3JkZXJJRD4yMDA2MDIwMTI2MzM8L09yZGVySUQ+CiAgICA8VXNlcklEPjEzNDk3NjAwNjwvVXNlcklEPgogICAgPE9FTT5UaGlzIGlzIGEgcmVkaXN0cmlidXRhYmxlIGxpY2Vuc2U8L09FTT4KICAgIDxQcm9kdWN0cz4KICAgICAgPFByb2R1Y3Q+QXNwb3NlLlRvdGFsIGZvciAuTkVUPC9Qcm9kdWN0PgogICAgPC9Qcm9kdWN0cz4KICAgIDxFZGl0aW9uVHlwZT5FbnRlcnByaXNlPC9FZGl0aW9uVHlwZT4KICAgIDxTZXJpYWxOdW1iZXI+OTM2ZTVmZDEtODY2Mi00YWJmLTk1YmQtYzhkYzBmNTNhZmE2PC9TZXJpYWxOdW1iZXI+CiAgICA8U3Vic2NyaXB0aW9uRXhwaXJ5PjIwMjEwODI3PC9TdWJzY3JpcHRpb25FeHBpcnk+CiAgICA8TGljZW5zZVZlcnNpb24+My4wPC9MaWNlbnNlVmVyc2lvbj4KICAgIDxMaWNlbnNlSW5zdHJ1Y3Rpb25zPmh0dHBzOi8vcHVyY2hhc2UuYXNwb3NlLmNvbS9wb2xpY2llcy91c2UtbGljZW5zZTwvTGljZW5zZUluc3RydWN0aW9ucz4KICA8L0RhdGE+CiAgPFNpZ25hdHVyZT5wSkpjQndRdnYxV1NxZ1kyOHFJYUFKSysvTFFVWWRrQ2x5THE2RUNLU0xDQ3dMNkEwMkJFTnh5L3JzQ1V3UExXbjV2bTl0TDRQRXE1aFAzY2s0WnhEejFiK1JIWTBuQkh1SEhBY01TL1BSeEJES0NGbWg1QVFZRTlrT0FxSzM5NVBSWmJRSGowOUNGTElVUzBMdnRmVkp5cUhjblJvU3dPQnVqT1oyeDc4WFE9PC9TaWduYXR1cmU+CjwvTGljZW5zZT4=")));
//byte[] sampleXls = Properties.Resources.GroundSteelPipeCal_模板;
//FileStream outputExcelFile = new FileStream(sourcePath, FileMode.Create, FileAccess.Write);
//outputExcelFile.Write(sampleXls, 0, sampleXls.Length);
//outputExcelFile.Close();
//outputExcelFile.Dispose();
//替换文本
Document doc = new Document(sourcePath);
DocumentBuilder builder = new DocumentBuilder(doc);
doc.Range.Replace("Evaluation Only. Created with Aspose.Words. Copyright 2003-2020 Aspose Pty Ltd.", "");
doc.Range.Replace("$姓名$", "李白");
doc.Range.Replace("$学历$", "研究生");
doc.Range.Replace("$联系方式$", "QQ");
doc.Range.Replace("$邮箱$", "[email protected]");
doc.Range.Replace("$内容$", "唐代诗人");
doc.Save(sourcePath); //保存word
//文件保存
SaveFileDialog sfd = new SaveFileDialog();
sfd.Filter = "Word Document(*.doc)|*.doc";
sfd.DefaultExt = "Word Document(*.doc)|*.doc";
if (sfd.ShowDialog() == DialogResult.OK)
{
try
{
string targetPath = sfd.FileName;
File.Copy(sourcePath, targetPath, true);
MessageBox.Show("报告文档生成成功");
}
catch (Exception ex)
{
MessageBox.Show("报告文档生成失败,原因:" + ex.Message);
}
}
}
标签:word,sourcePath,doc,Replace,关键字,Range,new,aspose,sfd From: https://www.cnblogs.com/wugh8726254/p/17736612.html