Here [AgreementNumber] is located in Title (Header Section), but it does not change.
Also it loses formating in one document, but not in another.
- Code: Select all
public virtual ActionResult AgreementDoc(int id, string lang = "geo")
{
string path = "";
if (lang == "rus")
{
path = "~/ExcelTemplates/VendorAgreementRus.docx";
}
else if (lang == "eng")
{
path = "~/ExcelTemplates/VendorAgreementEng.docx";
}
else
{
path = "~/ExcelTemplates/VendorAgreementGeo.docx";
}
Spire.Doc.Document doc = new Spire.Doc.Document(Server.MapPath(path));
var response = _contractorService.GetContractorGeneralInfo(new GetContractorGeneralInfoRequest { ContractorId = id });
doc.Replace("[VendorName]", response.Name, false, true);
doc.Replace("[PaymentDay]", response.PaymentDay.GetValueOrDefault().ToString(), false, true);
doc.Replace("[DateToday]", DateTime.Now.ToShortDateString(), false, true);
doc.Replace("[AgreementNumber]", "1", false, true);
using (MemoryStream ms2 = new MemoryStream())
{
doc.SaveToStream(ms2, Spire.Doc.FileFormat.Docx);
//save to byte array
byte[] toArray = ms2.ToArray();
return File(toArray, "application/vnd.openxmlformats-officedocument.wordprocessingml.document", response.Name + "_" + DateTime.Now.ToGeorgian().ToShortDateString() + ".docx");
}
}