如何使用apache POI在ppt中跨多个幻灯片拆分长表

时间:2011-11-25 14:12:04

标签: java split apache-poi powerpoint

我正在尝试使用POI将表导出到PPT。但是我的表可以包含n行。

问题是整个表格显示在同一张幻灯片中。我想根据行数将幻灯片拆分。

2 个答案:

答案 0 :(得分:2)

我可能会遗漏一些东西,但显而易见的是什么?

 Slide slide = hslf.createSlide();
 int rows = 0;
 int maxRowsPerSlide = 10; // Tune this

 for(MyRowThingy row : getMeMyRows()) {
     doAddRowToSlide(row, slide);

     rows++;
     if(rows % maxRowsPerSlide == 0) {
        // Slide is full, time for a new slide!
        slide = hslf.createSlide();
     }
 }

答案 1 :(得分:0)

在上面的代码中,我遇到了一个问题,即最后一张幻灯片将包含额外的列。所以maxRowsPerSlide必须是动态的。因为我使用了以下函数

public int getMaxRowsInOneSlide(int sizeOfTotalRowsArray, int totalCount){   //totalCount is the count of current row
    int maxRowsPerSlide = 0;

    if(sizeOfArray - totalCount >= 10){  //10 is the default rows in a slide
        maxRowsPerSlide = 10;
    }
    else{
        maxRowsPerSlide = (sizeOfArray - totalCount)+1;              //'+1' because each slide contains a row for the column names in the table
    }
    return maxRowsPerSlide;
}
}