In PPTX, when working on a table, it is possible to do the following:
- Table Design ribbon
- Table Styles
- Clear Table
See screenshot for an example:
Clear Table.png (101.6 KB)
How to do this in Aspose Slides for Java?
In PPTX, when working on a table, it is possible to do the following:
See screenshot for an example:
Clear Table.png (101.6 KB)
How to do this in Aspose Slides for Java?
To clear the table formatting in Aspose.Slides for Java, you can use the TableFormat
class associated with the table. This class provides methods to reset the formatting of the table to its default state, effectively clearing any styles that have been applied.
Here’s a simple example of how to clear the table formatting:
import com.aspose.slides.*;
public class ClearTableFormatting {
public static void main(String[] args) {
// Create a presentation
Presentation presentation = new Presentation();
// Add a slide
ISlide slide = presentation.getSlides().get_Item(0);
// Add a table to the slide
ITable table = slide.getShapes().addTable(50, 50, 400, 300, 3, 3);
// Clear the table formatting
table.getTableFormat().setFillFormat(new FillFormat());
table.getTableFormat().setOutlineFormat(new LineFormat());
// Save the presentation
presentation.save("ClearTableFormatting.pptx", SaveFormat.Pptx);
}
}
In this example, we create a new presentation and add a table to it. We then reset the fill and outline formats of the table to clear any existing styles. Finally, we save the presentation.
Make sure to adjust the properties of FillFormat
and LineFormat
as needed to achieve the desired default appearance for your table. This approach effectively mimics the “Clear Table” functionality found in PowerPoint’s Table Design ribbon.
@dcherkassky,
We have opened the following new ticket(s) in our internal issue tracking system and will consider implementing that feature according to the terms mentioned in Free Support Policies.
Issue ID(s): SLIDESJAVA-39667
You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.
@dcherkassky,
Aspose.Slides does not provide a single method for clearing table styles, but you can iterate through all table cells and reset each cell’s style. I need some time to prepare a code example for you. I will get back to you as soon as possible.
We also noticed that “Clear Table” also resets the fonts (e.g. font color).
But we have not found an API to reset a font color. Suggestions for that?
Thanks,
DC
@dcherkassky,
Thanks for flagging this. I’ll need to dive into the API to explore how to reset the font color, and I’ll get back to you as soon as I have an update.
@dcherkassky,
Thank you for your patience. Please try using the following code example:
Presentation presentation = new Presentation("sample.pptx");
try {
ISlide slide = presentation.getSlides().get_Item(0);
ITable someTable = (ITable)slide.getShapes().get_Item(0);
someTable.setStylePreset(TableStylePreset.None);
someTable.setTextFormat(new PortionFormat());
someTable.setTextFormat(new ParagraphFormat());
someTable.setTextFormat(new TextFrameFormat());
for (int i = 0 ; i < someTable.getRows().size(); i++)
{
for (ICell cell : someTable.getRows().get_Item(i))
{
for (IParagraph paragraph : cell.getTextFrame().getParagraphs())
{
for (IPortion portion : paragraph.getPortions())
{
IPortionFormat portionFormat = portion.getPortionFormat();
// Font Color
portionFormat.getFillFormat().getSolidFillColor().setColor(Color.BLACK);
}
}
}
}
presentation.save("output.pptx", SaveFormat.Pptx);
} finally {
presentation.dispose();
}
More examples:
PowerPoint Table|Aspose.Slides Documentation
Thanks for the code snippet. One question about it:
Your example assumes the default color is BLACK. But is that always the case? Is that really the same as clearing the color?
Thanks,
DC
Usually, this is true. However, for example, you can choose a color from the presentation theme.
Color themeColor = presentation.getMasterTheme().getColorScheme().getDark1().getColor();
portionFormat.getFillFormat().getSolidFillColor().setColor(themeColor);