日期:2014-05-18  浏览次数:20471 次

C#通过word模版创建新文档
C# code

 class Report
    {
        private _Application wordApp = null;
        private _Document wordDoc = null;
        public _Application Application
        {
            get
            {
                return wordApp;
            }
            set
            {
                wordApp = value;
            }
        }
        public _Document Document
        {
            get
            {
                return wordDoc;
            }
            set
            {
                wordDoc = value;
            }
        }

        //通过模板创建新文档
        public void CreateNewDocument(string filePath)
        {
            killWinWordProcess();
            wordApp = [color=#FF0000]new ApplicationClass();[/color]
            wordApp.DisplayAlerts = WdAlertLevel.wdAlertsNone;
            wordApp.Visible = false;
            object missing = System.Reflection.Missing.Value;
            object templateName = filePath;
            wordDoc = wordApp.Documents.Open(ref templateName, 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);
        }

我从网上找的一段代码,他说这是他封装好的Report类,我粘上后红色部分提示错误
错误 1 类型“Microsoft.Office.Interop.Word.ApplicationClass”未定义构造函数
错误 2 无法嵌入互操作类型“Microsoft.Office.Interop.Word.ApplicationClass”。请改用适用的接口。

------解决方案--------------------
用第三方的成品吧,自己写这种东西很难把握一些不熟悉的环节

比如:aspose.net里面的word组件