

我正在使用apache POI - XSLF生成powerpoint演示文稿,当用户单击我的网站上的某个链接时,该演示文稿是动态的。我有几个表,其中包含演示文稿文件中的数据,还有一个使用jfreechart生成的图像(折线图)。当我打开我机器上的PPTX时,它似乎工作得很好。但是,当我在另一台安装了powerpoint 2013的计算机上打开该文件时,出现以下错误。
"powerpoint发现内容有问题,powerpoint可以尝试修复演示文稿“。
我想摆脱这个错误。我在网上读到,解决方案是“解锁”powerpoint,这可以通过文件的属性部分来完成。我想知道我是否可以通过编程的方式为我的用户抑制这种错误。这个错误消息至少很烦人。
我在这上面的最后一个帖子被删除了-- https://stackoverflow.com/questions/41163148/how-to-unblock-pptx-using-apache-poi
因此,在这里再次创建此线程。在用于apache POI的bugzilla中也输入了一个错误。错误Id - 60633 (https://bz.apache.org/bugzilla/show_bug.cgi?id=60633)。
XSLFTableCell cell
XSLFTextParagraph p
XSLFTextRun line
XSLFTable tbl = slide.createTable();
tbl.setAnchor(new Rectangle(X, Y, WIDTH, HEIGHT));
XSLFTableRow headerRow = tbl.addRow();
headerRow.setHeight(45);
//Loop through the data collection and populate rows and columns.
for(int i = 0; i < numberOfCols; i++) {
XSLFTableCell th = headerRow.addCell();
p = th.addNewTextParagraph();
p.setTextAlign(TextAlign.CENTER);
line = p.addNewTextRun();.....}
for (int item=0; item < 8; item++)
{
XSLFTableRow itemRow = tbl.addRow();.....}
//finally write the file
File pptFile = File.createTempFile("fileName", ".ppt")
FileOutputStream out = new FileOutputStream(pptFile)
ppt.write(out)
out.close()发布于 2017-01-26 02:48:12
如果你提供了代码和错误报告,那么这个代码必须是完整的和可验证的。您的代码不完整且无法验证。如果我真的完成了,那么它就能正常工作。
import java.io.FileOutputStream;
import org.apache.poi.xslf.usermodel.*;
import org.apache.poi.sl.usermodel.TextParagraph.TextAlign;
import org.apache.poi.sl.usermodel.TableCell.BorderEdge;
import org.apache.poi.sl.usermodel.TextParagraph.TextAlign;
import java.awt.Rectangle;
import java.awt.Point;
import java.awt.Color;
public class CreatePPTX {
public static void main(String[] args) throws Exception {
XMLSlideShow ppt = new XMLSlideShow();
XSLFSlide slide = ppt.createSlide();
XSLFTableCell cell;
XSLFTextParagraph p;
XSLFTextRun line;
XSLFTable tbl = slide.createTable();
tbl.setAnchor(new Rectangle(new Point(100, 100)));
XSLFTableRow headerRow = tbl.addRow();
headerRow.setHeight(45);
for(int i = 0; i < 5; i++) {
XSLFTableCell th = headerRow.addCell();
p = th.addNewTextParagraph();
p.setTextAlign(TextAlign.CENTER);
line = p.addNewTextRun();
line.setText("Header " + i);
th.setBorderWidth(BorderEdge.bottom, 2.0);
th.setBorderColor(BorderEdge.bottom, Color.black);
}
for (int item=0; item < 8; item++) {
XSLFTableRow itemRow = tbl.addRow();
for (int i = 0; i < 5; i++) {
XSLFTableCell td = itemRow.addCell();
p = td.addNewTextParagraph();
p.setTextAlign(TextAlign.CENTER);
line = p.addNewTextRun();
line.setText("Cell " + item + ":" +i);
}
}
FileOutputStream out = new FileOutputStream("fileName.pptx");
ppt.write(out);
out.close();
}
}因此,使用您提供的代码无法重现您的问题。
但有一件事可能会导致你的问题。如果表格中的单元格应该是空的,那么不要创建空运行,而是让单元格完全为空。
示例使用上面的代码,如果单元格1:1应该为空,则不要:
...
for (int item=0; item < 8; item++) {
XSLFTableRow itemRow = tbl.addRow();
for (int i = 0; i < 5; i++) {
XSLFTableCell td = itemRow.addCell();
p = td.addNewTextParagraph();
p.setTextAlign(TextAlign.CENTER);
line = p.addNewTextRun();
if (!(item==1 && i==1)) {
line.setText("Cell " + item + ":" +i);
}
}
}
...这会导致错误。
取而代之的是:
...
for (int item=0; item < 8; item++) {
XSLFTableRow itemRow = tbl.addRow();
for (int i = 0; i < 5; i++) {
XSLFTableCell td = itemRow.addCell();
p = td.addNewTextParagraph();
p.setTextAlign(TextAlign.CENTER);
if (!(item==1 && i==1)) {
line = p.addNewTextRun();
line.setText("Cell " + item + ":" +i);
}
}
}
...https://stackoverflow.com/questions/41819081
复制相似问题