使用Aspose.words 把一個檔案中的Section完整拷貝到另一個檔案,包括頁眉和頁腳?
string strFile = @"C:\Xp\aaaaaa.doc";
Document originalDoc = new Document(strFile);
string strCurrentPath = System.IO.Directory.GetCurrentDirectory() + "\\";
//
int sectCount = originalDoc.Sections.Count;
for (int sectIndex = 0; sectIndex < sectCount; sectIndex++)
{
Document mainDoc = new Document();
mainDoc.FirstSection.Body.RemoveAllChildren();
//NodeImporter importer = new NodeImporter(originalDoc, mainDoc, ImportFormatMode.KeepSourceFormatting);
Aspose.Words.Section srcSection = originalDoc.Sections[sectIndex];
//Node dstSection = originalDoc.ImportNode(srcSection, true, ImportFormatMode.KeepSourceFormatting);
//mainDoc.AppendChild(dstSection);
int nodeCount = srcSection.Body.ChildNodes.Count;
NodeImporter importer = new NodeImporter(originalDoc, mainDoc, ImportFormatMode.KeepSourceFormatting);
for (int nodeIndex = 0; nodeIndex < nodeCount; nodeIndex++)
{
Node srcNode = srcSection.Body.ChildNodes[nodeIndex];
Node newNode = importer.ImportNode(srcNode, true);
mainDoc.FirstSection.Body.AppendChild(newNode);
}
mainDoc.Save(strCurrentPath + (sectIndex + 1).ToString() + ".doc", Aspose.Words.SaveFormat.Doc);
}
MessageBox.Show("處理完成");
上面的代碼現在內容可以復制過去了,但是頁面和頁腳都沒有復制過去,請問有沒有什么辦法可以處理。
uj5u.com熱心網友回復:
怎么也沒人過來啊。uj5u.com熱心網友回復:
我用了你的方法,是連帶頁眉頁腳都可以import過來的哦uj5u.com熱心網友回復:
頁眉頁腳在section中,而不是在Body中,與Body并列的。你的代碼是復制Body中的node,當然復制不了HeaderFooter了,因為HeaderFooter不在Body中uj5u.com熱心網友回復:
你是要完整的轉移section,為什么要寫那么多代碼,我自己用java寫很快啊;目前我找不到為什么樣式改變的原因而已,但是內容都是拿得到的uj5u.com熱心網友回復:
你還要問嗎。。。轉載請註明出處,本文鏈接:https://www.uj5u.com/net/6820.html
標籤:C#
