| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1131 人关注过本帖
标题:C # word 问题
取消只看楼主 加入收藏
mocelot
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2008-3-29
收藏
 问题点数:0 回复次数:2 
C # word 问题
我在三个word文档(test1.doc,test2.doc,test3.doc)里面分别放了三道题目( 题目1, 题目2, 题

目3),我想把这三个文件里面的题目放到一个output.doc,我想得到的效果是:
(1)
 题目1  
(2)
题目2
(3)
题目3
但是我程序输出的是

题目1
题目2
题目3
(1)
(2)
(3)

我的代码在下面

 public static void MergeDocoument()
    {
        object oEndOfDoc = "\\endofdoc"; /* \endofdoc is a predefined bookmark */
        string strTemplateName = HttpContext.Current.Server.MapPath("output.doc");

        object falseValue = false;
        object missing = System.Reflection.Missing.Value;
        object TemplateFileName = strTemplateName;
        Word.Application wordApp = new Word.ApplicationClass();

        Word.Document wordDoc = wordApp.Documents.Add(ref   missing, ref   missing, ref   

missing, ref   missing);
        wordDoc.Activate();

      
        string strFileName=null;

        for (int i = 1; i <= 3; i++)
        {
            Word.Paragraph oPara2;
            object oRng = wordDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
            oPara2 = wordDoc.Content.Paragraphs.Add(ref oRng);
            oPara2.Range.Text = "(" + i.ToString() + ")";
            oPara2.Format.SpaceAfter = 6;
            oPara2.Range.InsertParagraphAfter();


            strFileName = HttpContext.Current.Server.MapPath("test"+i.ToString()+".doc");
            wordApp.Selection.InsertFile(strFileName, ref   missing, ref   falseValue, ref   

falseValue, ref   falseValue);

            wordDoc.SaveAs(ref   TemplateFileName, ref   missing, ref   missing, ref   

missing, ref   missing, ref   missing, ref   missing, ref   missing, ref   missing, ref   

missing, ref   missing, ref   missing, ref   missing, ref   missing, ref   missing, ref   

missing);

           
            
        }
        wordDoc.Close(ref   missing, ref   missing, ref   missing);
        wordApp.Quit(ref   missing, ref   missing, ref   missing);
    }
搜索更多相关主题的帖子: word 
2008-08-05 20:35
mocelot
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2008-3-29
收藏
得分:0 
回复:c_henry

(1),(2),(3)是编号啦,是文本
2008-08-06 09:28
mocelot
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2008-3-29
收藏
得分:0 
问题解决!

代码在下面

public static void MergeDocoument()
    {
        object oEndOfDoc = "\\endofdoc"; /* \endofdoc is a predefined bookmark */
        string strTemplateName = HttpContext.Current.Server.MapPath("output.doc");

        object falseValue = false;
        object missing = System.Reflection.Missing.Value;
        object TemplateFileName = strTemplateName;
        Word.Application wordApp = new Word.ApplicationClass();

        Word.Document wordDoc = wordApp.Documents.Add(ref   missing, ref   missing, ref   

missing, ref   missing);
        wordDoc.Activate();

      
        string strFileName=null;

        for (int i = 1; i <= 3; i++)
        {
            Word.Paragraph oPara2;
            object oRng = wordDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
            oPara2 = wordDoc.Content.Paragraphs.Add(ref oRng);
            oPara2.Range.Text = "(" + i.ToString() + ")";
            oPara2.Format.SpaceAfter = 6;
            oPara2.Range.InsertParagraphAfter();


            strFileName = HttpContext.Current.Server.MapPath("test"+i.ToString()+".doc");
            wordDoc.Bookmarks.get_Item(ref oEndOfDoc).Range.InsertFile(strFileName, ref   missing, ref   falseValue, ref   falseValue, ref   falseValue);

            wordDoc.SaveAs(ref   TemplateFileName, ref   missing, ref   missing, ref   

missing, ref   missing, ref   missing, ref   missing, ref   missing, ref   missing, ref   

missing, ref   missing, ref   missing, ref   missing, ref   missing, ref   missing, ref   

missing);

           
            
        }
        wordDoc.Close(ref   missing, ref   missing, ref   missing);
        wordApp.Quit(ref   missing, ref   missing, ref   missing);
    }
2008-08-06 11:16
快速回复:C # word 问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.021519 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved