Word模板,对原数据进行转换问题


#1
  1. 数据库中,原数据Date为一个日期2017/6/1, 如何在word模板里将其变成 date+3year,即:2021/6/1

#2

@gongtianyuan,

您可以在以下Aspose.Words代码上构建逻辑,以在Word文档中插入所需的日期:

string dbDate = DateTime.Now.ToString("yyyy/MM/dd");
string[] arr = dbDate.Split(new char[] { '/' });

DateTime yearsDate = new DateTime(Convert.ToInt32(arr[0]), Convert.ToInt32(arr[1]), Convert.ToInt32(arr[2]));
yearsDate = yearsDate.AddYears(3);

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

builder.MoveToDocumentEnd();
builder.Writeln("DB Date: " + dbDate);
builder.Writeln("3 years after: " + yearsDate.ToString("yyyy/MM/dd"));

doc.Save("E:\\Temp\\19.6.docx");