Free Support Forum - aspose.com

Background Color for Document?

How do I set the background color for the entire Word document? Something.Shading.BackgroundPatternColor…

Also, why is there no DocumentBuilder.TableFormat property? I suppose you could accomplish everything you need to do with RowFormat and CellFormat?

Thanks, Natan.

After playing around with borders and padding, it becomes evident that TableFormat is needed. Applying a border around rows and cells is not equivalent to a table border (this is clear once padding is involved).

So…two questions then:

1) How do I apply a background color to the entire document?

2) How do I apply a border around an entire table? Or any other style?

Thanks.

Hi,

Thank you for considering Aspose.

1) You can use something like this:

NodeCollection nodes = doc.GetChildNodes(NodeType.Paragraph, true);

foreach (Paragraph paragraph in nodes)
{
paragraph.ParagraphFormat.Shading.BackgroundPatternColor = color;
}

2) TableFormat object is not supported because Microsoft Word does not stores tables internally, it stores rows only. Table in the Aspose.Word API is just a container for rows. So at the moment the only way to set a border around a table is iterating through table rows and setting borders for each one separately.

Thank you. My next question has to do with borders.

If an HTML table has a black background and a cell has a white background, the table will appear to have borders since there is default cell padding (essentially allowing the table background to become visible). This was possible in Aspose.Pdf and I’m wondering if I set a cell’s background to black, create a table within that cell and give those cells white backgrounds and some padding, can I achieve the same effect?

Thanks.

I’m afraid to misunderstand you, thus would you be so kind to attach a document containing the table you want to achieve?

I can assure you that the result produced by Aspose.Word programmatically is similar to one you can achieve by creating a document manually in Word.

You inadvertently answered my question. :wink:

I cut and pasted an HTML table and discovered that Word will ignore borders created by background color. Thus, my program should ignore them as well.

On another note, if I understand correctly, a Row object is not created until InsertCell( ) is called. If so, then should I wait to apply style to RowFormat until the first cell is created or all cells in the row are created?

Thanks.

You are right, but you can set the RowFormat properties at any moment until you call DocumentBuilder.EndRow. EndRow detaches RowFormat from the previous row.