我尝试创建一个Word文档并用数据库填充它。我正在使用Docx4j。
在Android上。没有图片,代码运行良好,但带有图片则崩溃。
这是崩溃的地方:
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-Libraries出了问题,而Android Studio的BinaryPartAbstractImage.java出了些问题。
AgustinSivoplás的回答对我有所帮助。
最佳答案
罐子似乎有问题。我过去曾与docx4j和android进行过激烈的斗争。
这是带有jar的libs文件夹。为我工作。
https://drive.google.com/file/d/1eKnci5RtL9x7D_OSSkWMkOEAEMvhLN-t/view?usp=sharing