Free Support Forum - aspose.com

Slide-Insert Table data-First row in table is coming in font bold

Hi Team,


We are using aspose slide for creating and inserting of table content. But the first row is coming in Bold. No where we are setting this as Bold in the code.

Iam attching the generated pptx for your reference & code snippet

Below is the code snippet:

public static void insertTableForTOC(final SlideEx slide, final Element tableShapeElement, final String shapeID) {
final ShapeEx tableShape = PPTUtil.findShape(slide, shapeID);
final float xCoord = tableShape.getX();
final float yCoord = tableShape.getY();
final NodeList rowNodeList = tableShapeElement.getElementsByTagName(PPTUtil.TABLE_ROW);
final int rowCnt = rowNodeList.getLength();
final Element tempRowEle = (Element) rowNodeList.item(0);
final NodeList tempCellNodeList = tempRowEle.getElementsByTagName(PPTUtil.TABLE_CELL);
double[] dblCols = new double[tempCellNodeList.getLength()];
double[] dblRows = new double[rowCnt];
for (int i = 0; i < dblRows.length; i++) {
dblRows[i] = 10;
}
for (int i = 0; i < dblCols.length; i++) {
dblCols[i] = 10;
}
tableShape.getSlide().getShapes().remove(tableShape);
final int id = slide.getShapes().addTable(xCoord, yCoord, dblCols, dblRows);
final TableEx table =(TableEx) slide.getShapes().get_Item(id);
table.setX(xCoord);
table.setY(yCoord);
table.setName(shapeID);
RowEx row=table.getRows().get_Item(0);
row.setMinimalHeight(10);
for(int rCnt = 0; rCnt < rowCnt; rCnt++){
row=table.getRows().get_Item(rCnt);
row.setMinimalHeight(10);
final Element rowEle = (Element) rowNodeList.item(rCnt);
final NodeList rowCellNodeList = rowEle.getElementsByTagName(PPTUtil.TABLE_CELL);
for (int i = 0; i < rowCellNodeList.getLength(); i++) {
final CellEx cell=row.get_Item(i);
final ColumnEx col = table.getColumns().get_Item(i);
if(i==0){
col.setWidth((float)PPTUtil.inchesToPixels(7.55));
}else{
col.setWidth((float)PPTUtil.inchesToPixels(2.33));
}
if(rowCellNodeList.item(i).getFirstChild() != null){
String cellText = rowCellNodeList.item(i).getFirstChild().getNodeValue();
cellText = cellText.trim();
cell.getTextFrame().getParagraphs().get_Item(0).getPortions().get_Item(0).setText(cellText);
cell.getTextFrame().getParagraphs().get_Item(0).getPortions().get_Item(0).setFontHeight(10);
cell.getFillFormat().setFillType(FillTypeEx.Solid);
cell.getFillFormat().getSolidFillColor().setColor(Color.WHITE);
cell.getTextFrame().getParagraphs().get_Item(0).getPortions().get_Item(0).getFillFormat().setFillType(FillTypeEx.Solid);
cell.getTextFrame().getParagraphs().get_Item(0).getPortions().get_Item(0).getFillFormat().getSolidFillColor().setColor(Color.GRAY);
}else{
cell.getTextFrame().setText("");
}
}
}
}

Hi Kranthi,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for sharing the sample file and code.

First of all, it is the default behavior of MS PowerPoint as well that when you add a new table, the first row i.e. the header row has bold font. However, MS PowerPoint does provide an option to enable or disable the header row which is not supported at the moment in Aspose.Slides for Java. A new feature request has been registered in our issue tracking system with issue id: SLIDESJAVA-34360. As a work around, you can set the font of the cells as non bold by adding the following line of code where you are formatting the cells:

cell.getTextFrame().getParagraphs().get_Item(0).getPortions().get_Item(0).setFontBold((byte)0);

The above line will make the font non bold in all the cells of the table. Please feel free to contact support in case you need any further assistance.

Thanks & Regards,

The issues you have found earlier (filed as SLIDESJAVA-34360) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.