我正在尝试使用 docx4j 将图像添加到新的 Word 文档中。我已经从网上获取了这段代码并为我的程序修改了它,但是我收到一个奇怪的错误,我不确定是什么导致了它或如何调试它......
这是我的代码
private static void test()
{
WordprocessingMLPackage wordMLPackage = null;
try {
wordMLPackage = WordprocessingMLPackage.createPackage();
} catch (InvalidFormatException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
javax.swing.JOptionPane.showMessageDialog(panel, "Cannnot create package.");
}
wordMLPackage.getMainDocumentPart().addStyledParagraphOfText("Title", "Hello Word! \n\t" + "Try This!");
byte[] bytes = null;
try {
bytes = convertImageToByteArray();
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
javax.swing.JOptionPane.showMessageDialog(panel, "Image file not found.");
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
javax.swing.JOptionPane.showMessageDialog(panel, …Run Code Online (Sandbox Code Playgroud)