Hi,
I am using aspose word.In my document there is one existing table with two rows.in document itself i applied table font as book antiq and font color but when i writing data to table through java code font is getting changed and color is not applied.
Also i tried through aspose table methods to set color its not working.
So please help me on two things:
1)how to apply font to existing table column data.
2)how to apply color to existing table column data.
Following is my code:-
//Existing table on myDocument.doc
Table table = (Table)bean.getMyDoc().getChild(NodeType.TABLE, 0, true);
Row row1=table.getFirstRow();
Row row2=table.getLastRow();
CellCollection cell=row1.getCells();
cell.get(0).getFirstParagraph().appendChild(new Run(getMyDoc(),“Name”);
cell.get(1).getFirstParagraph().appendChild(new Run(getMyDoc(), “Address”);
cell.get(2).getFirstParagraph().appendChild(new Run(getMyDoc(), “Phone”);
cell.get(3).getCellFormat().getShading().setForegroundPatternColor(Color.BLUE);
cell.get(3).getFirstParagraph().appendChild(new Run(getMyDoc(), “Email”);
Thanks,
Chandrashekar.
Hi,
Thanks for reply. I am attching zip which conatins
1)Input word file
2)output word file
3)Expected word file
4)Java code file
So my expected output is apply font and color to text in table column from input file and saved this to another output file.if you observe this, In input file i have table font Bk antq and for last email column is fore color is blue but after generating out put file font is Verdana and color is not changed.
Note:-
1)In code i am using Color class from java.awt.Color packge(to table)
2)And Font is aplied BK antiq in input file itself(in table itself) that is not coded.
I hope you understand this.please provide me code to do this.
I think there is something to do with Run class or tell me other way to set the text in table column expect using Run class.
Thanks,
Chandra.
Hi Chandra,
Thanks for the additional information. Please use the following code:
Document doc = new Document(getMyDir() + “OutPut using aspose.docx”);
Table table = (Table)doc.getChild(NodeType.TABLE, 0, true);
for (Row row : table.getRows()){
for(Cell cell : row.getCells()){
for(Run run : (Iterable<Run>) cell.getChildNodes(NodeType.RUN, true)){
run.getFont().setName(“Book Antiqua”);
if (cell.isLastCell())
run.getFont().setColor(Color.BLUE);
}
}
}
doc.save(getMyDir() + “15.6.0.docx”);
I hope, this helps.
Best regards,
Hi Friend,
Your reply is really helpful for me.
Thanks you very much.
Regards,
Chandra.