我试图创建一个word文档并将其填充到一个数据库中。我正在使用Docx4j。在安卓系统上。没有图片,代码运行良好,但是对于图像,它会崩溃。
这里是它崩溃的地方:
private static void addImageToPackage(Tc tableCell,
byte[] bytes) throws Exception {
BinaryPartAbstractImage imagePart =
BinaryPartAbstractImage.createImagePart(wordMLPackage, bytes);
int docPrId = 1;
int cNvPrId = 2;
Inline inline = imagePart.createImageInline("Filename hint",
"Alternative text", docPrId, cNvPrId, 500000, 500000, false);
P paragraph = addInlineImageToParagraph(inline);
PPr paragraphProperties = factory.createPPr();
Jc justification = factory.createJc();
justification.setVal(JcEnumeration.RIGHT);
paragraphProperties.setJc(justification);
paragraph.setPPr(paragraphProperties);
tableCell.getContent().add(paragraph);
}更新:没有任何错误的代码。我的问题是Docx4j有问题--库和Android在BinaryPartAbstractImage.java上有一些问题。奥古斯丁·西沃普拉斯的回答帮助了我。
发布于 2016-02-03 20:30:42
发布于 2018-10-06 02:18:26
尝试更改docx4j的版本。对我起作用了。
https://stackoverflow.com/questions/35185975
复制相似问题