我想使用 DocX 以编程方式创建和操作 Word 文档!并创建一个单词模板InvoiceTemplate.docx
这是我的代码:
protected void CreateDoc_Click(object sender, EventArgs e)
{
//Createa docx File
DocX gDocument;
gDocument =
DocX.Load(@Server.MapPath("InvoiceTemplate.docx"));
gDocument =
CreateInvoiceFromTemplate(DocX.Load(@Server.MapPath("InvoiceTemplate.docx")));
gDocument.SaveAs(@Server.MapPath("~/DocX/NewLoadedShipment.docx"));
}
private static DocX CreateInvoiceFromTemplate(DocX template)
{
template.AddCustomProperty(
new CustomProperty("{rechnung}", "5"));
template.AddCustomProperty(
new CustomProperty("{name}", "Maziar"));
template.AddCustomProperty(
new CustomProperty("{date}", DateTime.Now.ToString("dd.MM.yyyy")));
template.AddCustomProperty(
new CustomProperty("{address}", "12345hamburg"));
template.AddCustomProperty(
new CustomProperty("{tell}", "2234543"));
template.AddCustomProperty(
new CustomProperty("{amount}", "1000"));
template.AddCustomProperty(
new CustomProperty("{rest}", "500"));
template.AddCustomProperty(
new CustomProperty("{tax}", "100"));
template.AddCustomProperty(
new CustomProperty("{total}", "600"));
return template;
}
但我什么也没发生NewLoadedShipment.docx
!请有人帮忙!