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

Free Support Forum - aspose.com

Apply color and font name for table row data which is already in document

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 Chandrashekar,


Thanks for your inquiry. To ensure a timely and accurate response, please attach the following resources here for testing:

  • Your input Word document
  • Aspose.Words generated output document which shows the undesired behavior
  • Your expected document which shows the correct output. Please create this document using Microsoft Word application.
  • Please create a standalone Java application (source code without compilation errors) that helps us reproduce your problem on our end and attach it here for testing.

As soon as you get these pieces of information ready, we’ll start investigation into your issue and provide you more information. Thanks for your cooperation.

PS: To attach these resources, please zip them and Click ‘Reply’ button that will bring you to the ‘reply page’ and there at the bottom you can include any attachments with that post by clicking the ‘Add/Update’ button.

Best regards,

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.