Reputation: 521
I am trying to export tables to PPT using POI. But my tables can contain n number of rows.
The problem is that the entire table is displayed in the same slide. I want to split the table across slides depending on the number of rows.
Upvotes: 3
Views: 2712
Reputation: 521
in the above code i faced a problem where the last slides will contain extra columns. so the maxRowsPerSlide must be dynamic.for tht i used folowing function
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;
}
}
Upvotes: 0
Reputation: 48396
I may be missing something, but what's wrong with the obvious?
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();
}
}
Upvotes: 2