We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Spilling Data to Subsequent Slides

Hi,

I have been evaluating Aspose slides for java.
I have a scenario of filling dynamic data to table and once the rows are filled in a slide it should create a new table with same styles and start filling with remaining data in next slide and so on.
However what we observed is table is getting stretched in the same slide which is very weird.
So can you Please advise any solution to the above problem so that we can effectively spill the remaining data to subsequent slides effectively.

Here i have attached sample code.

public class FillTable {
public static void main(String[] args) {
try {
fillTable();
} catch (FileNotFoundException e) {
e.printStackTrace();
}

}

public static void fillTable() throws FileNotFoundException {
com.aspose.slides.License license = new License();
license.setLicense(“Aspose.Slides.lic”);

// The path to the documents directory.

// Instantiate Presentation class that represents PPTX file
for (CustomerTemplates template : CustomerTemplates.values()) {

IPresentation pres =
PresentationFactory.getInstance().readPresentation(Utils.getCustomerTemplate(template.getFileName()));
ISlide slide = pres.getSlides().addEmptySlide(pres.getLayoutSlides()
.add(pres.getMasters().get_Item(0), SlideLayoutType.TitleAndObject, “GSBlank”));
/ISlide slide=pres.getSlides().get_Item(0);
/
// Define columns with widths and rows with heights
double[] dblCols = {150, 150, 150};
double[] dblRows = {50, 30, 30, 30, 30, 30};
// Add table shape to slide
ITable tbl = slide.getShapes().addTable(100, 50, dblCols, dblRows);
IShapeCollection sourceShapes = pres.getSlides().get_Item(0).getShapes();

// Set border format for each cell

for (int row = 0; row < tbl.getRows().size(); row++) {
for (int cell = 0; cell < tbl.getRows().get_Item(row).size(); cell++) {
tbl.getRows().get_Item(row).get_Item(cell).getBorderTop().getFillFormat().setFillType(FillType.Solid);
tbl.getRows().get_Item(row).get_Item(cell).getBorderTop().getFillFormat().getSolidFillColor()
.setColor(Color.BLACK);
tbl.getRows().get_Item(row).get_Item(cell).getBorderTop().setWidth(1);
/* tbl.getRows().get_Item(row).get_Item(cell).getTextFrame().getTextFrameFormat()
.setAutofitType(NullableBool.True);*/
tbl.getRows().get_Item(row).get_Item(cell).getTextFrame().getTextFrameFormat().setWrapText(NullableBool.True);
tbl.getRows().get_Item(row).get_Item(cell).getTextFrame()
.setText(“Here is some data which needs to autofit like it has mind of Here is some data which needs to autofit like it has mind ofHere is some data which needs to autofit like it has mind of Here is some data which needs to autofit like it has mind of”);
tbl.getRows().get_Item(row).get_Item(cell).getTextFrame().getTextFrameFormat().setAutofitType(NullableBool.True);
tbl.getRows().get_Item(row).get_Item(cell).getFillFormat().getSolidFillColor().setLuminance(0.50f);


tbl.getRows().get_Item(row).get_Item(cell).getBorderBottom().getFillFormat().setFillType(FillType.Solid);
tbl.getRows().get_Item(row).get_Item(cell).getBorderBottom().getFillFormat().getSolidFillColor()
.setColor(Color.BLACK);
tbl.getRows().get_Item(row).get_Item(cell).getBorderBottom().setWidth(1);

tbl.getRows().get_Item(row).get_Item(cell).getBorderLeft().getFillFormat().setFillType(FillType.Solid);
tbl.getRows().get_Item(row).get_Item(cell).getBorderLeft().getFillFormat().getSolidFillColor()
.setColor(Color.BLACK);
tbl.getRows().get_Item(row).get_Item(cell).getBorderLeft().setWidth(1);

tbl.getRows().get_Item(row).get_Item(cell).getBorderRight().getFillFormat().setFillType(FillType.Solid);
tbl.getRows().get_Item(row).get_Item(cell).getBorderRight().getFillFormat().getSolidFillColor()
.setColor(Color.BLACK);
tbl.getRows().get_Item(row).get_Item(cell).getBorderRight().setWidth(1);
System.out.println(“Cell Height IS ::”+tbl.getRows().get_Item(row).get_Item(cell).getHeight()+" minimal height "+tbl.getRows().get_Item(row).get_Item(cell).getMinimalHeight());

}
if (tbl.getHeight() + tbl.getY() + tbl.getRows().get_Item(row).getHeight() >
pres.getSlideSize().getSize().getHeight()) {
tbl = fillTableClone(tbl, pres, sourceShapes);
}

}
/PortionFormat portionFormat = new PortionFormat();
portionFormat.setFontHeight(14);
tbl.setTextFormat(portionFormat);
portionFormat.setFontItalic(NullableBool.True);

// setting table cells’ text alignment and right margin in one call
ParagraphFormat paragraphFormat = new ParagraphFormat();
paragraphFormat.setAlignment(TextAlignment.Right);
paragraphFormat.setMarginRight(20);
tbl.setTextFormat(paragraphFormat);


// setting table cells’ text vertical type
TextFrameFormat textFrameFormat = new TextFrameFormat();
textFrameFormat.setTextVerticalType(TextVerticalType.Vertical);
tbl.setTextFormat(textFrameFormat);
/


// Save PPTX to Disk
File file = new File(“Generated-Presentation-” + template.getFileName()+“table” + “.pptx”);
pres.save(new FileOutputStream(file), SaveFormat.Pptx);
}
}

private static ITable fillTableClone(ITable tbl, IPresentation presentation, IShapeCollection sourceShapes) {
ILayoutSlide blankLayout =
presentation.getMasters().get_Item(0).getLayoutSlides().getByType(SlideLayoutType.TitleAndObject);

// Add Empty Slide and InsertClone
ISlide destSlide = presentation.getSlides().addEmptySlide(blankLayout);

IShapeCollection destShapes = destSlide.getShapes();

// destShapes.AddClone(sourceShapes[1], 50, 150 + sourceShapes[0].Height);
ITable table = null;
for (int i = 0; i < sourceShapes.size(); i++) {
IShape newShape = destShapes.addClone(sourceShapes.get_Item(i));
if (newShape instanceof ITable) {
table = (ITable) newShape;
}
}
// IShape newShape = destShapes.addClone(sourceShapes.get_Item(1));
// destShapes.InsertClone(0, sourceShapes[0], 50, 150);


for (IRow row : table.getRows()) {
for (int i = 0; i < row.size(); i++) {
ICell cell = row.get_Item(i);
cell.getTextFrame().getParagraphs().clear();
}
}
return tbl;
}

}

Hi,

I have observed the requirement shared by you and like
to share that when you add the content inside the table you need to
check that on every instance of text addition. There is no automatic way available to judge if slide is overflown and new slide automatically gets added with similar table. If the table height
exceeds the slide height, you can use the slide cloning feature to clone
the existing table slide and populate that with new text. Please try
using the attached sample code to serve the purpose as it checks if the table has exceeded
the slide size or not.

I hope the shared information will be helpful.

Many Thanks,

i have used your code as suggested ,still it fails to comply.I am attaching the code and generated ppt.

public static void fillTable() throws FileNotFoundException {
com.aspose.slides.License license = new License();
license.setLicense(“Aspose.Slides.lic”);

// The path to the documents directory.

// Instantiate Presentation class that represents PPTX file
for (CustomerTemplates template : CustomerTemplates.values()) {

IPresentation pres =
PresentationFactory.getInstance().readPresentation(Utils.getCustomerTemplate(template.getFileName()));
ISlide slide = pres.getSlides().addEmptySlide(pres.getLayoutSlides()
.add(pres.getMasters().get_Item(0), SlideLayoutType.TitleAndObject, “GSBlank”));
/ISlide slide=pres.getSlides().get_Item(0);
/
// Define columns with widths and rows with heights
double[] dblCols = {150, 150, 150};
double[] dblRows = {50, 30, 30, 30, 30, 30};
// Add table shape to slide
ITable tbl = slide.getShapes().addTable(100, 50, dblCols, dblRows);
String TableName=“MyTable”;
tbl.setAlternativeText(TableName);

// Set border format for each cell
for (int row = 0; row < tbl.getRows().size(); row++) {
for (int cell = 0; cell < tbl.getRows().get_Item(row).size(); cell++) {
tbl.getRows().get_Item(row).get_Item(cell).getBorderTop().getFillFormat().setFillType(FillType.Solid);
tbl.getRows().get_Item(row).get_Item(cell).getBorderTop().getFillFormat().getSolidFillColor()
.setColor(Color.BLACK);
tbl.getRows().get_Item(row).get_Item(cell).getBorderTop().setWidth(1);
/* tbl.getRows().get_Item(row).get_Item(cell).getTextFrame().getTextFrameFormat()
.setAutofitType(NullableBool.True);*/
tbl.getRows().get_Item(row).get_Item(cell).getTextFrame().getTextFrameFormat().setWrapText(NullableBool.True);
tbl.getRows().get_Item(row).get_Item(cell).getTextFrame()
.setText(“Here is some data which needs to autofit like it has mind of Here is some data which needs to autofit like it has mind ofHere is some data which needs to autofit like it has mind of Here is some data which needs to autofit like it has mind of”);
tbl.getRows().get_Item(row).get_Item(cell).getTextFrame().getTextFrameFormat().setAutofitType(NullableBool.True);
tbl.getRows().get_Item(row).get_Item(cell).getFillFormat().getSolidFillColor().setLuminance(0.50f);


tbl.getRows().get_Item(row).get_Item(cell).getBorderBottom().getFillFormat().setFillType(FillType.Solid);
tbl.getRows().get_Item(row).get_Item(cell).getBorderBottom().getFillFormat().getSolidFillColor()
.setColor(Color.BLACK);
tbl.getRows().get_Item(row).get_Item(cell).getBorderBottom().setWidth(1);

tbl.getRows().get_Item(row).get_Item(cell).getBorderLeft().getFillFormat().setFillType(FillType.Solid);
tbl.getRows().get_Item(row).get_Item(cell).getBorderLeft().getFillFormat().getSolidFillColor()
.setColor(Color.BLACK);
tbl.getRows().get_Item(row).get_Item(cell).getBorderLeft().setWidth(1);

tbl.getRows().get_Item(row).get_Item(cell).getBorderRight().getFillFormat().setFillType(FillType.Solid);
tbl.getRows().get_Item(row).get_Item(cell).getBorderRight().getFillFormat().getSolidFillColor()
.setColor(Color.BLACK);
tbl.getRows().get_Item(row).get_Item(cell).getBorderRight().setWidth(1);
System.out.println(“Cell Height IS ::”+tbl.getRows().get_Item(row).get_Item(cell).getHeight()+" minimal height "+tbl.getRows().get_Item(row).get_Item(cell).getMinimalHeight());

}
if (tbl.getHeight() + tbl.getY()+tbl.getRows().get_Item(row).getHeight()>
pres.getSlideSize().getSize().getHeight()) {
tbl = fillTableClone(pres,TableName,slide);
}
}
/PortionFormat portionFormat = new PortionFormat();
portionFormat.setFontHeight(14);
tbl.setTextFormat(portionFormat);
portionFormat.setFontItalic(NullableBool.True);

// setting table cells’ text alignment and right margin in one call
ParagraphFormat paragraphFormat = new ParagraphFormat();
paragraphFormat.setAlignment(TextAlignment.Right);
paragraphFormat.setMarginRight(20);
tbl.setTextFormat(paragraphFormat);


// setting table cells’ text vertical type
TextFrameFormat textFrameFormat = new TextFrameFormat();
textFrameFormat.setTextVerticalType(TextVerticalType.Vertical);
tbl.setTextFormat(textFrameFormat);
/


// Save PPTX to Disk
File file = new File(“Generated-Presentation-” + template.getFileName()+“table” + “.pptx”);
pres.save(new FileOutputStream(file), SaveFormat.Pptx);
}
}

private static ITable fillTableClone(IPresentation presentation,String tableName,ISlide slide) {
ILayoutSlide blankLayout =
presentation.getMasters().get_Item(0).getLayoutSlides().getByType(SlideLayoutType.TitleAndObject);

System.out.println(“Table exceeded slide height…”);
//You can make a recursive approach for cloning based on your data
ISlide newSlide = presentation.getSlides().addClone(slide);
//Getting the exisiting table on new slide and start populating data in new one
ITable newTable=(ITable) newSlide.findShapeByAltText(tableName);
// IShape newShape = destShapes.addClone(sourceShapes.get_Item(1));
// destShapes.InsertClone(0, sourceShapes[0], 50, 150);

return newTable;
}
Please advise,
Thanks
Ashok

Hi Ashok,

I have tried the sample code shared by you and have not been able to completely utilize that on my end owing to custom data calls in your code. However, I have found discrepancies in your logic where you are making decision to add new slide with table based on slide size exceeding. Also, you have been adding rows data by incrementing row counter on every slide clone instance, which was also wrong. You need to reset the row counter on every new slide so that population of row can be start from first row. Attached please find the working sample code to serve the purpose on your end. I have also attached the generated presentation for your kind reference. I hope this will be good enough to serve your needs and you can tailor this as per your requirements.

Many Thanks,