We have tried your code. However, we did not get the expected output. Please refer to ‘expectedOutput.docx’ in the attachment which contains the same content from the source docx but with the desired styles applied from the template. Please note the styles applied for each node type in the output docx file. We require those custom styles to be applied to the respective node types.
ex: The images in the source file are formed with word shape drawings. But we need it to be as an image in the output file.toAspose.zip (490.2 KB)
Thanks for your response. I made changes with the code you suggested but i did not get the desired result. To make it simple, AsposeSupport.zip (849.9 KB)
I am attaching a simple input docx(example1) , java program and output docx(example1). Can you please check why the below things are not working
hyperlinks in the paragraph is not shown in the output docx
Group Shape is not showing up in the output docx file.
The last line in the output docx dont have space between them[Printed in USAs and C78-739361-00 07/17 ]
4)The first page in the output docx is unnecessarily created.
In your case, you do not need to iterate over each node and insert it into new document. You can use Document.AppendDocument method to append your input document to template document.
You can also copy the styles from template document to input document as suggested in my previous post.
Clear the formatting of Paragraph and Run nodes and apply styles according to your requirement.
Thanks for you response.
My requirement is that i have to apply few custom styles for each element(paragraph,table, groupshapes, images etc) in the source document. For that reason, in the attached java code i traversing all the nodes in the source document applying custom style and then adding/appending to the destination document. Can you please tell me where i have to change the code to achieve the following
hyperlinks in the paragraph is not shown in the output docx
Group Shape is not showing up in the output docx file.
The last line in the output docx dont have space between them[Printed in USAs and C78-739361-00 07/17 ]
4)The first page in the output docx is unnecessarily created.
You can use Document.ImportNode method to import a node from another document to the current document. Following code example shows how to import nodes from one document to another. This code example also clears the formatting of paragraph and imports styles from template document to destination document.
Thanks for your response. I updated the code and attached the input and output docx generated along with java file.
These are few things i observed,
There was a problem with table style but i managed to give the styling using a for-loop. Please look into my code in the java file
I noticed there is no gap between the last two words in the last paragraph/line. Can you please see why there is no gap between like input docx file
Printed in USAs C78-739361-00 07/17
You are setting style of first paragraph of table’s cell. You need to iterate over all paragraphs of table’s cell and apply the style.
We have tested the scenario using the latest version of Aspose.Words for Java 19.12 with shared code example and have not found the issue. So, please use Aspose.Words for Java 19.12. We have attached the output document with this post for your kind reference. 19.12.zip (151.7 KB)
We recently purchased the product (Aspose.Words for Java V19.11) on Dec 13th , 2019. Is there any workaround for the fix. Can i use 19.12 version jar in maven and still use 19.11 version licence key.
Thanks for your response.
How to convert a 2/3 column layout of a docx file to a 1 column layout? i would like to convert the attached docx file to 1 column layout ? All the pages in the docx file should have only 1 column. sample.zip (3.7 MB)
Hi Tahir,
The table style is not getting applied even though i added the line
doc.setAutomaticallyUpdateSyles(true);AsposeSupport.zip (1.6 MB)
Also noticed that the even and odd are not working because of the merged rows and cells.
I attached input docx, output docx, template file and java file.
Please suggest.
Could you please ZIP and attach your simplified input and expected output documents? We will investigate the issue and provide you more information on it.
The expected table look[styling] should be same as the table in the template[DataSheetTemplate2019.dotx] that i attached in the zip.
Please notice the following
Table header background color
The table header cell have a style[Cellhead1, Chart_subhead]
The table body cells have style[Chart_body],
If the table body cell has list then the style is [CellBullet].
The input file[software-system-bulletin.docx] is present in the input folder. After i ran the attached java code[DocxConversion.java] the output file is saved in the output folder.
Basically, the content in the output file should be same as input file but the output file should have styles that are there in the template file[DataSheetTemplate2019.dotx]
We suggest you please copy the styles from the specified template to a document using Document.CopyStylesFromTemplate method. In your case, we need to clear the font formatting of Paragraph, Run and Table nodes.
Please check the following code example Hope this helps you.
Document srcDoc = new Document(MyDir + "software-system-bulletin.docx");
for(Paragraph paragraph : (Iterable<Paragraph>)srcDoc.getChildNodes(NodeType.PARAGRAPH, true))
{
paragraph.getParagraphBreakFont().clearFormatting();
paragraph.getParagraphFormat().clearFormatting();
for (Run run : paragraph.getRuns())
{
run.getFont().clearFormatting();
}
}
srcDoc.copyStylesFromTemplate(MyDir + "DataSheetTemplate2019.dotx");
for(Table table : (Iterable<Table>)srcDoc.getChildNodes(NodeType.TABLE, true))
{
for(Paragraph paragraph : (Iterable<Paragraph>)table.getFirstRow().getChildNodes(NodeType.PARAGRAPH, true))
{
paragraph.getParagraphFormat().setStyleName("Cellhead1");
}
//Use the same approach to set paragraph's style for remaining rows
for(Cell cell : (Iterable<Cell>)table.getChildNodes(NodeType.CELL, true))
{
cell.getCellFormat().clearFormatting();
}
table.setStyleName("Table Style");
}
srcDoc.setAutomaticallyUpdateSyles(true);
srcDoc.save(MyDir + "20.1.docx");