Dataset
을 통해 루프를 만들고 Aspose.Words Mail-Merge 기능을 사용하여 항목 당 페이지를 만듭니다. 아래 코드는 Dataset
을 통해 루핑하고 일부 값을 Mail-Merge Execute 함수에 전달합니다.Aspose.Words - MailMerge images
var blankDocument = new Document();
var pageDocument = new Document(sFilename);
...
foreach (DataRow row in ds.Tables[0].Rows){
var sBarCode = row["BarCode"].ToString();
var imageFilePath = HttpContext.Current.Server.MapPath("\\_temp\\") + sBarCode + ".png";
var tempDoc = (Document)pageDocument.Clone(true);
var fieldNames = new string[] { "Test", "Barcode" };
var fieldData = new object[] { imageFilePath, imageFilePath };
tempDoc.MailMerge.Execute(fieldNames, fieldData);
blankDocument.AppendDocument(tempDoc, ImportFormatMode.KeepSourceFormatting);
}
var stream = new MemoryStream();
blankDocument.Save(stream, SaveFormat.Docx);
// I then output this stream using headers,
// to cause the browser to download the document.
편지 병합 항목 { MERGEFIELD Test }
는 Dataset
에서 올바른 데이터를 가져옵니다. 그러나 사용하는 모든 페이지에 실제 이미지 표시 1 페이지의 이미지 : 텍스트에 c:\img1.png
를 표시
c:\img1.png
c:\img2.png
c:\img3.png
페이지이 문서 중 하나를
{ INCLUDEPICTURE "{MERGEFIELD Barcode }" \* MERGEFORMAT \d }
이는 "바코드"필드에 내 데이터를 말해봐 "Test"필드. 그리고 보여지는 이미지는 img1.png
입니다.
그러나 페이지 2는 c:\img2.png
을 텍스트로 표시하지만 img1.png
을 실제 이미지로 표시합니다.
누구에게도 통찰력이 있습니까?
편집 : 이것은 Word 문제가 더 많은 것처럼 보입니다. Word 내에서 Alt + F9 모드 사이를 전환하면 이미지에 실제로 c:\img1.png
이 소스로 표시됩니다. 이것이 모든 페이지에 표시되는 이유입니다.
나는 그것을 단순화했습니다 :
{ INCLUDEPICTURE "{MERGEFIELD Barcode }" \d }
는 또한, Word의 우편물 수신자 목록 내부의이 분야에 대한 테스트 데이터를 추가했다. 미리 볼 때 데이터를 가져 와서 이미지를 변경하지 않습니다. 그래서 이것은 근본적인 문제입니다.