Dear Team
Aspose_page_replace_error_page_05_will be removed.png (29.7 KB)
Used the below code for replace the exist table , which removing the entire data also ,
Find the attached documents and screenshot for the reference
string Filepath = "D:\\pdf_sample\\";
Aspose.Words.Document docExecute = new Aspose.Words.Document(Filepath + "Aspose_page_replace_error_page_05_only.docx");
Aspose.Words.Document docparents = new Aspose.Words.Document(Filepath + "Aspose_page_replace_error_page_05_Allpages.docx");
foreach (Aspose.Words.Tables.Table tabl in docparents.GetChildNodes(Aspose.Words.NodeType.Table, true).Where(x => x.GetAncestor(Aspose.Words.NodeType.HeaderFooter) == null))
{
Aspose.Words.Tables.Table tableB = docExecute.Sections[0].Body.Tables[0];
Aspose.Words.ImportFormatOptions ifo = new Aspose.Words.ImportFormatOptions()
{ KeepSourceNumbering = true };
Aspose.Words.NodeImporter importer = new Aspose.Words.NodeImporter(docExecute, docparents, Aspose.Words.ImportFormatMode.KeepSourceFormatting, ifo);
Aspose.Words.Tables.Table newTable = (Aspose.Words.Tables.Table)importer.ImportNode(tableB, true);
Aspose.Words.Section tablesSection = (Aspose.Words.Section)tabl.GetAncestor(Aspose.Words.NodeType.Section);
tablesSection.Body.InsertAfter(newTable, tabl);
tabl.Remove();
break;
}
Aspose.zip (203.6 KB)
@MiniValgenesis can you please be more specific about what do you want to achieve. Do you want to remove the footnote?
Dear team,
the footnote is getting removed, which should not happen.
@MiniValgenesis
I am afraid, this is not quite right. Footnote is actually inside the table’s content, so when you remove content of the table, the footnote is also removed. For example see how the document internal structure looks:
FYI @eduardo.canal
1 Like
Dear team
Attaching the file ( page 3 ) values not loading correctly Aspose_page_replace_error_page_05_Allpages.docx (40.6 KB)
Dear team
Attaching the details here
Executable.docx file is the replacing file
Allpage.docx contains the original file
where the output.docx ( footnote is removed) which should not removed
string Filepath = "C:\\ ASpose\\";
Aspose.Words.Document docExecute = new Aspose.Words.Document(Filepath + "Executable.docx");
Aspose.Words.Document docparents = new Aspose.Words.Document(Filepath + "Allpage.docx");
int isection = 10;
int ProcessTable = 11;
foreach (Aspose.Words.Tables.Table tabl in docparents.GetChildNodes(Aspose.Words.NodeType.Table, true).Where(x => x.GetAncestor(Aspose.Words.NodeType.HeaderFooter) == null))
{
if (ProcessTable - 1 == isection)
{
Aspose.Words.Tables.Table tableB = docExecute.Sections[0].Body.Tables[0];
Aspose.Words.ImportFormatOptions ifo = new Aspose.Words.ImportFormatOptions() { KeepSourceNumbering = true };
Aspose.Words.NodeImporter importer = new Aspose.Words.NodeImporter(docExecute, docparents, Aspose.Words.ImportFormatMode.KeepSourceFormatting, ifo);
Aspose.Words.Tables.Table newTable = (Aspose.Words.Tables.Table)importer.ImportNode(tableB, true);
Aspose.Words.Section tablesSection = (Aspose.Words.Section)tabl.GetAncestor(Aspose.Words.NodeType.Section);
tablesSection.Body.InsertAfter(newTable, tabl);
tabl.Remove();
break;
}
}
docparents.Save(Filepath + "output.docx");
Error.zip (130.0 KB)
@MiniValgenesis In your code you replace the table in Allpage.docx
document with the table from Executable.docx
. The table in the original Allpage.docx
document has footnote with content:
But the table in Executable.docx
have an empty footnote:
So when you remove the original table with non-empty footnote and replace it with table with an empty footnote, this is expected that you see an empty footnote in your output document.
Dear team
yes the Executable pages not converted, before that 2 more steps are included here
string Filepath = "C:\\ ASpose\\";
Step:1 (converting Allpages.doc to doc_to_html.html file)
Aspose.Words.License license = new Aspose.Words.License();
license.SetLicense(licpath);
Aspose.Words.Document docExecute = new Aspose.Words.Document(Filepath + "Allpage.docx");
docExecute.Save(Filepath + "doc_to_html.Html");
Step:2( Converting doc_to_html.Html to Excutable.docx)
Aspose.Words.License license = new Aspose.Words.License();
license.SetLicense(licpath);
Aspose.Words.Document doc = new Aspose.Words.Document(Filepath + "doc_to_html.Html");
doc.Save(Filepath + "Executable.docx", Aspose.Words.SaveFormat.Docx);
Step:3 then again continue the below steps, here only the 3page should be replaced , which already shared
Aspose.Words.License license = new Aspose.Words.License();
license.SetLicense(licpath);
Aspose.Words.Document docExecute = new Aspose.Words.Document(Filepath + "Executable.docx");
Aspose.Words.Document docparents = new Aspose.Words.Document(Filepath + "Allpage.docx");
int isection = 10;
int ProcessTable = 11;
foreach (Aspose.Words.Tables.Table tabl in docparents.GetChildNodes(Aspose.Words.NodeType.Table, true).Where(x => x.GetAncestor(Aspose.Words.NodeType.HeaderFooter) == null))
{
if (ProcessTable - 1 == isection)
{
Aspose.Words.Tables.Table tableB = docExecute.Sections[0].Body.Tables[0];
Aspose.Words.ImportFormatOptions ifo = new Aspose.Words.ImportFormatOptions() { KeepSourceNumbering = true };
Aspose.Words.NodeImporter importer = new Aspose.Words.NodeImporter(docExecute, docparents, Aspose.Words.ImportFormatMode.KeepSourceFormatting, ifo);
Aspose.Words.Tables.Table newTable = (Aspose.Words.Tables.Table)importer.ImportNode(tableB, true);
Aspose.Words.Section tablesSection = (Aspose.Words.Section)tabl.GetAncestor(Aspose.Words.NodeType.Section);
tablesSection.Body.InsertAfter(newTable, tabl);
tabl.Remove();
break;
}
}
docparents.Save(Filepath + "output.docx");
@MiniValgenesis So the problem is that footnote is lost after DOCX->HTML->DOCX roundtrip (first two steps), right?
I have tested the scenario on my side using the latest 23.4 version of Aspose.Words and cannot reproduce this problem. Here is the code I have used for testing:
Document doc = new Document(@"C:\Temp\Allpage.docx");
doc.Save(@"C:\Temp\tmp.html");
doc = new Document(@"C:\Temp\tmp.html");
doc.Save(@"C:\Temp\out.docx");
The footnotes are properly preserved in the output document.
As I can see you are using old 21.12 version of Aspose.Words, so I would suggest you to update your version to the latest.
Dear Team ,
Thanks for the update , the version is now updated to latest 23.4,
After following the above steps, in page3(Executable.docx), delete the table , which delete the footnote content also.
@MiniValgenesis Could you please create a simple console application that will demonstrate the problem? Unfortunately, it is not quite clear what the problem is. As I mentioned earlier, the footnote is inside the table, once you remove the table, all its children including footnote are also removed.
Dear alexey,
This has been checked via console application only
In previous, step1,step2 has been given.
problem is that footnote is lost after DOCX->HTML->DOCX roundtrip (first two step)
you can check the document after converted from html to docx
in converted document the footnote is moving inside the table.( while converting html to word)
Refer page3 after the html conversion
Steps to reproduce
After html to word conversion.
open document and goto page3.
now delete the table , where the footnote is moving inside the table after conversion.
Hope the above steps are clear ?
@MiniValgenesis I already checked this using code like this:
// Convert source document to HTML
Document doc = new Document(@"C:\Temp\in.docx");
doc.Save(@"C:\Temp\tmp.html");
// Convert the document back to DOCX
Document doc1 = new Document(@"C:\Temp\tmp.html");
doc1.Save(@"C:\Temp\out.docx");
Footnote is inside the table in both source DOCX and output DOCX documents. Please see the attached files:
docs.zip (52.6 KB)