Asp.net 合并Word文档(Office Interop&;NET),保留格式
使用Microsoft Office Interop程序集(Office 2007)和ASP.NET 3.5将多个word文档合并在一起时遇到一些困难。我可以合并文档,但缺少一些格式(即字体和图像) 我当前的合并代码如下所示Asp.net 合并Word文档(Office Interop&;NET),保留格式,asp.net,vb.net,ms-word,office-interop,office-2007,Asp.net,Vb.net,Ms Word,Office Interop,Office 2007,使用Microsoft Office Interop程序集(Office 2007)和ASP.NET 3.5将多个word文档合并在一起时遇到一些困难。我可以合并文档,但缺少一些格式(即字体和图像) 我当前的合并代码如下所示 private void CombineDocuments() { object wdPageBreak = 7; object wdStory = 6; object oMissing = System.Reflection
private void CombineDocuments() {
object wdPageBreak = 7;
object wdStory = 6;
object oMissing = System.Reflection.Missing.Value;
object oFalse = false;
object oTrue = true;
string fileDirectory = @"C:\documents\";
Microsoft.Office.Interop.Word.Application WordApp = new Microsoft.Office.Interop.Word.Application();
Microsoft.Office.Interop.Word.Document wDoc = WordApp.Documents.Add(ref oMissing, ref oMissing, ref oMissing, ref oMissing);
string[] wordFiles = Directory.GetFiles(fileDirectory, "*.doc");
for (int i = 0; i < wordFiles.Length; i++) {
string file = wordFiles[i];
wDoc.Application.Selection.Range.InsertFile(file, ref oMissing, ref oMissing, ref oMissing, ref oFalse);
wDoc.Application.Selection.Range.InsertBreak(ref wdPageBreak);
wDoc.Application.Selection.EndKey(ref wdStory, ref oMissing);
}
string combineDocName = Path.Combine(fileDirectory, "Merged Document.doc");
if (File.Exists(combineDocName))
File.Delete(combineDocName);
object combineDocNameObj = combineDocName;
wDoc.SaveAs(ref combineDocNameObj, ref m_WordDocumentType, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
}
private void组合文档(){
对象wdPageBreak=7;
对象wdStory=6;
对象omising=System.Reflection.Missing.Value;
ALSE的对象=false;
object oTrue=true;
字符串fileDirectory=@“C:\documents\”;
Microsoft.Office.Interop.Word.Application WordApp=新的Microsoft.Office.Interop.Word.Application();
Microsoft.Office.Interop.Word.Document wDoc=WordApp.Documents.Add(引用删除、引用删除、引用删除、引用删除);
字符串[]wordFiles=Directory.GetFiles(fileDirectory,*.doc);
for(int i=0;i
我不在乎这是如何实现的。如果有必要,它可以通过PDF输出。我只想保留格式。添加文档时跳过模板名称,这就是ut缺少格式的原因 应该是这样的
string defaultTemplate="your template name with full path";
或
默认模板名称
string defaultTemplate="Normal.dot";
wordApplication.Documents.Add(ref defaultTemplate,............
使用此链接作为参考:永远不要从ASP.NET应用程序使用Office互操作。请参阅Downvoted和voted to close,因为有人会认为这个问题意味着可以从ASP.NET使用Office互操作。