Dear Sir
請問一下如何把MSSQL中儲存為圖檔的(varbinary)資料經由word範本寫入word檔案中?
謝謝!
目前圖檔是存在DB的Blob然後再使用SQL抓出來,這部分是可以寫在哪個區段呢?(以下是我的原始碼)
謝謝!
public class HandleMergeImageFieldFromBlob implements IFieldMergingCallback {
public void fieldMerging(FieldMergingArgs args) throws Exception {
// Do nothing.
}
public void imageFieldMerging(ImageFieldMergingArgs e) throws Exception {
System.out.println(e);
if(e.getFieldName().equals("head")){
DocumentBuilder builder = new DocumentBuilder(e.getDocument());
builder.moveToMergeField("head");
ByteArrayInputStream imageStream = new ByteArrayInputStream((byte[]) e.getFieldValue());
e.setImageStream(imageStream);
}
}
}
IFieldMergingCallback.ImageFieldMerging 方法在 Aspose.Words 邮件合并引擎将要插入图像到合并字段时调用。 无需调用 DocumentBuilder.moveToMergeField 方法。 您可以使用以下代码片段来实现您的要求。
我们建议您阅读 ImageFieldMergingArgs 类的成员。
public void imageFieldMerging(ImageFieldMergingArgs e) throws Exception {
// The field value is a byte array, just cast it and create a stream on it.
ByteArrayInputStream imageStream = new ByteArrayInputStream((byte[]) e.getFieldValue());
// Now the mail merge engine will retrieve the image from the stream.
e.setImageStream(imageStream);
}
@tahir.manzoor
你好,目前測試過圖片是有顯示出來,但顯示不完全,有3/4最被會被遮住,設定文字在後面,圖片在前面才可以顯示出來,可以在getMailMerge()使用shape.setWrapType(WrapType.NONE);shape.setBehindText(true);,使其能夠全面顯示呢?
擷圖.png (7.4 KB)
具有字段«Image:head» 的段落的行距是“完全正确”,请查看所附图片以了解详细信息。 请将其更改为 Single 以获得所需的输出。
paragraph formatting.png (53.5 KB)
謝謝!已排除問題。