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

Free Support Forum - aspose.com

Is it possible to style all tables with a different style (not the default)

Hi,


I’m using Aspose to read a template file, insert some text / tables (with insertHtml) and then saving the document.

Right now I’m having a problem with the formatting of tables. The “normal” style in the template file has some left indentation and the table text also got that indentation which means it looks very bad.

Is there any way to specify the style to apply to all the tables in Word (I researched and it seems to be not possible), for example some “table text” style or something…

The 2nd choice is: - Is it possible to apply a custom style “Normal Table custom” to all tables in Aspose? How can we achieve this? (I already traverse all my tables to center them, so maybe that’s not hard to do…)

Hi

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

Thanks for your inquiry. If I understood you correctly, you need to apply custom style to all paragraphs inside tables. If so, you can easily achieve this using Aspose.Words. For instance, see the following code:

// Open document.

Document doc = new Document("C:\\Temp\\in.doc");

// Get all tables.

Node[] tables = doc.getChildNodes(NodeType.TABLE, true).toArray();

for(Node node : tables)

{

Table table = (Table)node;

// Get all paragraphs in the table.

Node[] paragraphs = table.getChildNodes(NodeType.PARAGRAPH, true).toArray();

for(Node p : paragraphs)

{

Paragraph paragraph = (Paragraph)p;

// Reset paragraph's style.

paragraph.getParagraphFormat().setStyleName("myStyle");

}

}

// Save output.

doc.save("C:\\Temp\\out.doc");

Hope this helps.

Best regards,