Free Support Forum - aspose.com

Setting a table font

Is there a way to set the font for a table, table row, and table cell without using the document builder?

Kind Regards,

Gavin

<!–[if gte mso 10]> /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-qformat:yes; mso-style-parent:""; mso-padding-alt:0pt 5.4pt 0pt 5.4pt; mso-para-margin:0pt; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:11.0pt; font-family:"Calibri","sans-serif"; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-fareast-font-family:SimSun; mso-fareast-theme-font:minor-fareast; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-bidi-font-family:Arial; mso-bidi-theme-font:minor-bidi;}

<![endif]–>

Hi Gavin,

Thanks for your request. Sure, you can achieve this. You should simply loop through all Run nodes inside the appropriate Table, Row or Cell node and change the font. Please see Aspose.Words DOM for more information:

http://www.aspose.com/documentation/.net-components/aspose.words-for-.net/object-model-overview.html

Please let us know in case of any issues, we are always glad to help you.

Best regards,

Hi Andrey,

I have code that already sets the fonts in the run nodes when it adds it the paragraphs. However if a cell does not any paragraphs in the cell there is no way to set the font.

To combat this I initially added paragraphs into the cells when there is no paragraphs to be added just so each cell could have the fonts set.

however there is a square marker at the end of each table row which I have no access to set it’s font.

Kind Regards,

Gavin

<!–[if gte mso 10]> /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-qformat:yes; mso-style-parent:""; mso-padding-alt:0pt 5.4pt 0pt 5.4pt; mso-para-margin:0pt; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:11.0pt; font-family:"Calibri","sans-serif"; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-fareast-font-family:SimSun; mso-fareast-theme-font:minor-fareast; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-bidi-font-family:Arial; mso-bidi-theme-font:minor-bidi;}

<![endif]–>

Hi

Thank you for additional information. A cell in table in Ms Word document cannot be absolutely empty. Anyways there is one empty paragraph in the empty cell. If not it will be added upon saving the document (to keep the document valid).

If you would like to set the font of empty paragraph, you should simply set font of the paragraph break:

http://www.aspose.com/documentation/.net-components/aspose.words-for-.net/aspose.words.paragraph.paragraphbreakfont.html

If you are adding table cells dynamically, you can call EnsureMinimum method to add the required empty paragraph into this cell:

http://www.aspose.com/documentation/.net-components/aspose.words-for-.net/aspose.words.tables.cell.ensureminimum.html

Best regards,

Hi Andrey,



As previously indicated I realised that I was unable to place an empty
cell into the document and have thus added a paragraph per cell. However
there is no way to control the row break format.

Kind Regards,

Gavin

<!–[if gte mso 10]> /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-qformat:yes; mso-style-parent:""; mso-padding-alt:0pt 5.4pt 0pt 5.4pt; mso-para-margin:0pt; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:11.0pt; font-family:"Calibri","sans-serif"; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-fareast-font-family:SimSun; mso-fareast-theme-font:minor-fareast; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-bidi-font-family:Arial; mso-bidi-theme-font:minor-bidi;}

<![endif]–>

Hi

Thank you for additional information. There is no way and no need to set font of the end of row because there cannot be any nodes that could contain text. So it would be enough to set font of paragraphs and runs inside table cells.

Best regards,

Hi Gavin,


Thanks for your inquiry.

I think you may be looking for the ParagraphBreakFont. Please see the code below.

<span style=“font-size:10.0pt;font-family:“Courier New”;color:blue;mso-ansi-language:
EN-NZ;mso-fareast-language:ZH-CN;mso-no-proof:yes”>foreach<span style=“font-size:10.0pt;font-family:“Courier New”;mso-ansi-language:EN-NZ;
mso-fareast-language:ZH-CN;mso-no-proof:yes”> (Paragraph
para in table.GetChildNodes(NodeType.Paragraph, true))<o:p></o:p>

para.ParagraphBreakFont.Size = 1;


Thanks,

Hi Adam,

Unfortunately I am unable to use that code because the data provided has the potential to change font sizes. Which means I can’t generically set the paragraphbreakfonts to a standardised size.

However it seems that it does not matter. I just have to remember to set the font size specified for the cell, which i get from the data, and not worry about that paragraph break font character for the row. It seems to not matter what size is set for the row.

Thanks.

Hi Gavin,


Thanks for this additional information.

It’s great things are working for you now. Please feel free to ask any time you have any queries.

Thanks,