首页 > 代码库 > <add assembly="Microsoft.Office.Tools.Word, Version=10.0.0.0, Culture=neutral, PublicKeyToken=B03F5F

<add assembly="Microsoft.Office.Tools.Word, Version=10.0.0.0, Culture=neutral, PublicKeyToken=B03F5F

Server Error in ‘/‘ Application.

Configuration Error

Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately. 

Parser Error Message: Could not load file or assembly ‘Microsoft.Office.Tools.Word, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a‘ or one of its dependencies. 系统找不到指定的文件。

Source Error: 

Line 55: 				<add assembly="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
Line 56: 				<add assembly="System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
Line 57: 				<add assembly="Microsoft.Office.Tools.Word, Version=10.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
Line 58: 				<add assembly="Microsoft.Office.Interop.Word, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71E9BCE111E9429C"/>
Line 59: 				<add assembly="Microsoft.Vbe.Interop, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71E9BCE111E9429C"/>

Source File: E:\T1Web\web.config    Line: 57 

Assembly Load Trace: The following information can be helpful to determine why the assembly ‘Microsoft.Office.Tools.Word, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a‘ could not be loaded.

WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].


Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.504


2015-1-16 10:48:51

PS:暂时找不解放方案.


但是如果我删除报错的那行结果会怎么样?(webconfig里面把这行,删掉看看,可能就可以正确运行了,如果删掉还是报错的话,就是你缺少dll或者其他)

反馈给我的还是错误


Server Error in ‘/‘ Application.

Configuration Error

Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately. 

Parser Error Message: Could not load file or assembly ‘Microsoft.Office.Interop.Word, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c‘ or one of its dependencies. 系统找不到指定的文件。

Source Error: 

Line 54: 				<add assembly="DevExpress.Web.ASPxThemes.v13.2, Version=13.2.7.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a"/>
Line 55: 				<add assembly="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
Line 56: 				<add assembly="Microsoft.Office.Interop.Word, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71E9BCE111E9429C"/>
Line 57: 				<add assembly="Microsoft.Vbe.Interop, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71E9BCE111E9429C"/>
Line 58: 				<add assembly="office, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71E9BCE111E9429C"/></assemblies>

Source File: E:\T1Web\web.config    Line: 56 

Assembly Load Trace: The following information can be helpful to determine why the assembly ‘Microsoft.Office.Interop.Word, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c‘ could not be loaded.

WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].


Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.504


好吧,贯彻我的思路接着删除报错的那行配置文件.然后我的后台代码就报错了.

现在够详细了,知道那行代码调用出错了.


Server Error in ‘/‘ Application.
--------------------------------------------------------------------------------


Compilation Error 
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. 


Compiler Error Message: CS0234: The type or namespace name ‘Office‘ does not exist in the namespace ‘Microsoft‘ (are you missing an assembly reference?)


Source Error:


 


Line 4:  public class CCWordApp
Line 5:  {
Line 6:      private Microsoft.Office.Interop.Word.ApplicationClass oWordApplic;// a reference to Word application 引用Word应用程序
Line 7:      private Microsoft.Office.Interop.Word.Document oDoc;// a reference to the document 引用文档
Line 8:  
 


Source File: e:\T1Web\App_Code\CCWordApp.cs    Line: 6 






Show Detailed Compiler Output:




C:\WINDOWS\SysWOW64\inetsrv> "C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\csc.exe" /t:library /utf8output /R:"C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\fdb97f61\f8333f36\assembly\dl3\ba6a7995\4bbe8a36_dcf4cf01\DevExpress.Web.ASPxHtmlEditor.v13.2.DLL" /R:"C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Configuration\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll" /R:"C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Runtime.Serialization\v4.0_4.0.0.0__b77a5c561934e089\System.Runtime.Serialization.dll" /R:"C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Core\v4.0_4.0.0.0__b77a5c561934e089\System.Core.dll" /R:"C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\fdb97f61\f8333f36\assembly\dl3\8dc27d62\6bee8f36_dcf4cf01\DevExpress.Utils.v13.2.UI.resources.DLL" /R:"C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\fdb97f61\f8333f36\assembly\dl3\a8ab943b\ebb58e36_dcf4cf01\DevExpress.Printing.v13.2.Core.DLL" /R:"C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Data.DataSetExtensions\v4.0_4.0.0.0__b77a5c561934e089\System.Data.DataSetExtensions.dll" /R:"C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\fdb97f61\f8333f36\assembly\dl3\3032107a\eb448c36_dcf4cf01\DevExpress.XtraReports.v13.2.Extensions.resources.DLL" /R:"C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\fdb97f61\f8333f36\assembly\dl3\86b20fcd\cba38436_dcf4cf01\DevExpress.Web.ASPxThemes.v13.2.DLL" /R:"C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Drawing\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll" /R:"C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Web.WebPages.Deployment\v4.0_1.0.0.0__31bf3856ad364e35\System.Web.WebPages.Deployment.dll" /R:"C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\fdb97f61\f8333f36\assembly\dl3\219f6ba1\fb188536_dcf4cf01\DevExpress.XtraGrid.v13.2.resources.DLL" /R:"C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\fdb97f61\f8333f36\assembly\dl3\c96c3223\6b9b8836_dcf4cf01\DevExpress.Web.v13.2.DLL" /R:"C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\fdb97f61\f8333f36\assembly\dl3\67591196\bbcf8b36_dcf4cf01\DevExpress.XtraPrinting.v13.2.resources.DLL" /R:"C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\fdb97f61\f8333f36\assembly\dl3\4ed06aaf\9b818b36_dcf4cf01\DevExpress.XtraCharts.v13.2.resources.DLL" /R:"C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\fdb97f61\f8333f36\assembly\dl3\3fc622ee\8b788636_dcf4cf01\DevExpress.Utils.v13.2.resources.DLL" /R:"C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.ServiceModel.Web\v4.0_4.0.0.0__31bf3856ad364e35\System.ServiceModel.Web.dll" /R:"C:\WINDOWS\Microsoft.Net\assembly\GAC_32\System.Data\v4.0_4.0.0.0__b77a5c561934e089\System.Data.dll" /R:"C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\Microsoft.CSharp\v4.0_4.0.0.0__b03f5f7f11d50a3a\Microsoft.CSharp.dll" /R:"C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Web.Services\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Web.Services.dll" /R:"C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\fdb97f61\f8333f36\assembly\dl3\ac46d821\db1d8c36_dcf4cf01\DevExpress.XtraTreeList.v13.2.resources.DLL" /R:"C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\fdb97f61\f8333f36\assembly\dl3\b2f48bec\2bca7b36_dcf4cf01\DevExpress.Web.ASPxHtmlEditor.v13.2.resources.DLL" /R:"C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\fdb97f61\f8333f36\assembly\dl3\4718ffb4\5b038636_dcf4cf01\DevExpress.DataAccess.v13.2.resources.DLL" /R:"C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\mscorlib.dll" /R:"C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Web.ApplicationServices\v4.0_4.0.0.0__31bf3856ad364e35\System.Web.ApplicationServices.dll" /R:"C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.ComponentModel.DataAnnotations\v4.0_4.0.0.0__31bf3856ad364e35\System.ComponentModel.DataAnnotations.dll" /R:"C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Web.DynamicData\v4.0_4.0.0.0__31bf3856ad364e35\System.Web.DynamicData.dll" /R:"C:\WINDOWS\Microsoft.Net\assembly\GAC_32\System.EnterpriseServices\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.EnterpriseServices.dll" /R:"C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Xml.Linq\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.Linq.dll" /R:"C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\fdb97f61\f8333f36\assembly\dl3\a766ce63\dbac8936_dcf4cf01\DevExpress.Data.v13.2.resources.DLL" /R:"C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\fdb97f61\f8333f36\assembly\dl3\945ced59\7ba48d36_dcf4cf01\DevExpress.Data.v13.2.DLL" /R:"C:\WINDOWS\assembly\GAC_MSIL\Microsoft.ReportViewer.Common\9.0.0.0__b03f5f7f11d50a3a\Microsoft.ReportViewer.Common.dll" /R:"C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\fdb97f61\f8333f36\assembly\dl3\c72258e3\6b0c8b36_dcf4cf01\DevExpress.Printing.v13.2.Core.resources.DLL" /R:"C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.ServiceModel\v4.0_4.0.0.0__b77a5c561934e089\System.ServiceModel.dll" /R:"C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\fdb97f61\f8333f36\assembly\dl3\4b6a04fe\8be98836_dcf4cf01\DevExpress.DataAccess.v13.2.UI.resources.DLL" /R:"C:\WINDOWS\assembly\GAC_MSIL\Microsoft.ReportViewer.ProcessingObjectModel\9.0.0.0__b03f5f7f11d50a3a\Microsoft.ReportViewer.ProcessingObjectModel.dll" /R:"C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Windows.Forms\v4.0_4.0.0.0__b77a5c561934e089\System.Windows.Forms.dll" /R:"C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\fdb97f61\f8333f36\assembly\dl3\8c30e287\72726957_ca2bd001\App_Licenses.DLL" /R:"C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\fdb97f61\f8333f36\assembly\dl3\76f1f0e7\ebd38936_dcf4cf01\DevExpress.XtraReports.v13.2.Web.resources.DLL" /R:"C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System\v4.0_4.0.0.0__b77a5c561934e089\System.dll" /R:"C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\fdb97f61\f8333f36\assembly\dl3\5d19a33c\7b159036_dcf4cf01\DevExpress.Web.ASPxSpellChecker.v13.2.resources.DLL" /R:"C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\fdb97f61\f8333f36\assembly\dl3\c1aeec2f\bb5e8936_dcf4cf01\DevExpress.XtraNavBar.v13.2.resources.DLL" /R:"C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\fdb97f61\f8333f36\assembly\dl3\90d8b77e\4bdc8536_dcf4cf01\Microsoft.Vbe.Interop.DLL" /R:"C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Web.Extensions\v4.0_4.0.0.0__31bf3856ad364e35\System.Web.Extensions.dll" /R:"C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.ServiceModel.Activities\v4.0_4.0.0.0__31bf3856ad364e35\System.ServiceModel.Activities.dll" /R:"C:\WINDOWS\Microsoft.Net\assembly\GAC_32\System.Web\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Web.dll" /R:"C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\fdb97f61\f8333f36\assembly\dl3\bf2ca8fc\0b408536_dcf4cf01\DevExpress.Web.ASPxScheduler.v13.2.resources.DLL" /R:"C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\fdb97f61\f8333f36\assembly\dl3\8f49a32c\8bcb8d36_dcf4cf01\DevExpress.Web.ASPxTreeList.v13.2.resources.DLL" /R:"C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\fdb97f61\f8333f36\assembly\dl3\0b5faf33\fb6b8c36_dcf4cf01\DevExpress.XtraReports.v13.2.resources.DLL" /R:"C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.IdentityModel\v4.0_4.0.0.0__b77a5c561934e089\System.IdentityModel.dll" /R:"C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.ServiceModel.Activation\v4.0_4.0.0.0__31bf3856ad364e35\System.ServiceModel.Activation.dll" /R:"C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Activities\v4.0_4.0.0.0__31bf3856ad364e35\System.Activities.dll" /R:"C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\fdb97f61\f8333f36\assembly\dl3\f8bec368\8b3c9036_dcf4cf01\DevExpress.Web.v13.2.resources.DLL" /R:"C:\WINDOWS\assembly\GAC_MSIL\Microsoft.ReportViewer.WebForms\9.0.0.0__b03f5f7f11d50a3a\Microsoft.ReportViewer.WebForms.dll" /R:"C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\fdb97f61\f8333f36\assembly\dl3\312172aa\0b7c7b36_dcf4cf01\DevExpress.XtraCharts.v13.2.Wizard.resources.DLL" /R:"C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Xml\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.dll" /R:"C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\fdb97f61\f8333f36\assembly\dl3\307b3a48\9b108936_dcf4cf01\DevExpress.XtraEditors.v13.2.resources.DLL" /R:"C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.WorkflowServices\v4.0_4.0.0.0__31bf3856ad364e35\System.WorkflowServices.dll" /R:"C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\fdb97f61\f8333f36\assembly\dl3\b4ad0387\2b8e8536_dcf4cf01\DevExpress.XtraBars.v13.2.resources.DLL" /out:"C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\fdb97f61\f8333f36\App_Code.fs1kyxl-.dll" /D:DEBUG /debug+ /optimize- /w:4 /nowarn:1659;1699;1701 /warnaserror-  "C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\fdb97f61\f8333f36\App_Code.fs1kyxl-.0.cs" "C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\fdb97f61\f8333f36\App_Code.fs1kyxl-.1.cs" "C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\fdb97f61\f8333f36\App_Code.fs1kyxl-.2.cs" "C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\fdb97f61\f8333f36\App_Code.fs1kyxl-.3.cs" "C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\fdb97f61\f8333f36\App_Code.fs1kyxl-.4.cs" "C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\fdb97f61\f8333f36\App_Code.fs1kyxl-.5.cs" "C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\fdb97f61\f8333f36\App_Code.fs1kyxl-.6.cs" "C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\fdb97f61\f8333f36\App_Code.fs1kyxl-.7.cs"




Microsoft (R) Visual C# 2010 Compiler version 4.0.30319.1
Copyright (C) Microsoft Corporation. All rights reserved.


e:\T1Web\App_Code\CCWordApp.cs(6,23): error CS0234: The type or namespace name ‘Office‘ does not exist in the namespace ‘Microsoft‘ (are you missing an assembly reference?)
e:\T1Web\App_Code\CCWordApp.cs(7,23): error CS0234: The type or namespace name ‘Office‘ does not exist in the namespace ‘Microsoft‘ (are you missing an assembly reference?)


 






Show Complete Compilation Source:




Line 1:    using System;
Line 2:    using System.ComponentModel;
Line 3:    
Line 4:    public class CCWordApp
Line 5:    {
Line 6:        private Microsoft.Office.Interop.Word.ApplicationClass oWordApplic;// a reference to Word application 引用Word应用程序
Line 7:        private Microsoft.Office.Interop.Word.Document oDoc;// a reference to the document 引用文档
Line 8:    
Line 9:    
Line 10:       public CCWordApp()
Line 11:       {
Line 12:           // activate the interface with the COM object of Microsoft Word
Line 13:           //激活与Microsoft Word的COM对象的接口
Line 14:           oWordApplic = new Microsoft.Office.Interop.Word.ApplicationClass();
Line 15:       }
Line 16:   
Line 17:       /// <summary>
Line 18:       /// 插入图片
Line 19:       /// </summary>
Line 20:       /// <param name="picPath"></param>
Line 21:       public void InsertPicture(string picPath)
Line 22:       {
Line 23:           object missing = System.Reflection.Missing.Value;
Line 24:           oWordApplic.Selection.InlineShapes.AddPicture(picPath, ref missing, ref missing, ref missing);
Line 25:       }
Line 26:   
Line 27:       // Open a file (the file must exists) and activate it  打开一个文件(该文件必须存在),并激活它
Line 28:       public void Open(string strFileName)
Line 29:       {
Line 30:           object fileName = strFileName;
Line 31:           object readOnly = false;
Line 32:           object isVisible = true;
Line 33:           object missing = System.Reflection.Missing.Value;
Line 34:   
Line 35:           oDoc = oWordApplic.Documents.Open(ref fileName, ref missing, ref readOnly,
Line 36:               ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,
Line 37:               ref missing, ref missing, ref isVisible, ref missing, ref missing, ref missing);
Line 38:   
Line 39:           oDoc.Activate();
Line 40:       }
Line 41:   
Line 42:   
Line 43:       // Open a new document打开一个新文档
Line 44:       public void Open()
Line 45:       {
Line 46:           object missing = System.Reflection.Missing.Value;
Line 47:           oDoc = oWordApplic.Documents.Add(ref missing, ref missing, ref missing, ref missing);
Line 48:   
Line 49:           oDoc.Activate();
Line 50:       }
Line 51:   
Line 52:   
Line 53:   
Line 54:   
Line 55:       public void Quit()
Line 56:       {
Line 57:           object missing = System.Reflection.Missing.Value;
Line 58:           oWordApplic.Application.Quit(ref missing, ref missing, ref missing);
Line 59:       }
Line 60:   
Line 61:       public void Save()
Line 62:       {
Line 63:           oDoc.Save();
Line 64:       }
Line 65:   
Line 66:       public void SaveAs(string strFileName)
Line 67:       {
Line 68:           object missing = System.Reflection.Missing.Value;
Line 69:           object fileName = strFileName;
Line 70:   
Line 71:           oDoc.SaveAs(ref fileName, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,
Line 72:               ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);
Line 73:       }
Line 74:   
Line 75:       // Save the document in HTML format 以HTML格式保存文档
Line 76:       public void SaveAsHtml(string strFileName)
Line 77:       {
Line 78:           object missing = System.Reflection.Missing.Value;
Line 79:           object fileName = strFileName;
Line 80:           object Format = (int)Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatHTML;
Line 81:           oDoc.SaveAs(ref fileName, ref Format, ref missing, ref missing, ref missing, ref missing, ref missing,
Line 82:               ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);
Line 83:       }
Line 84:   
Line 85:   
Line 86:   
Line 87:       public void InsertText(string strText)
Line 88:       {
Line 89:           oWordApplic.Selection.TypeText(strText);
Line 90:       }
Line 91:   
Line 92:       public void InsertLineBreak()
Line 93:       {
Line 94:           oWordApplic.Selection.TypeParagraph();
Line 95:       }
Line 96:       public void InsertLineBreak(int nline)
Line 97:       {
Line 98:           for (int i = 0; i < nline; i++)
Line 99:               oWordApplic.Selection.TypeParagraph();
Line 100:      }
Line 101:  
Line 102:  
Line 103:      // Change the paragraph alignement 更改段落对齐键相
Line 104:      public void SetAlignment(string strType)
Line 105:      {
Line 106:          switch (strType)
Line 107:          {
Line 108:              case "Center":
Line 109:                  oWordApplic.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;
Line 110:                  break;
Line 111:              case "Left":
Line 112:                  oWordApplic.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft;
Line 113:                  break;
Line 114:              case "Right":
Line 115:                  oWordApplic.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphRight;
Line 116:                  break;
Line 117:              case "Justify":
Line 118:                  oWordApplic.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphJustify;
Line 119:                  break;
Line 120:          }
Line 121:  
Line 122:      }
Line 123:  
Line 124:  
Line 125:      // if you use thif function to change the font you should call it again with 如果您使用此功能来改变字体,你应该再次调用它 
Line 126:      // no parameter in order to set the font without a particular format 为了不带参数设置字体没有特定的格式
Line 127:      public void SetFont(string strType)
Line 128:      {
Line 129:          switch (strType)
Line 130:          {
Line 131:              case "Bold":
Line 132:                  oWordApplic.Selection.Font.Bold = 1;
Line 133:                  break;
Line 134:              case "Italic":
Line 135:                  oWordApplic.Selection.Font.Italic = 1;
Line 136:                  break;
Line 137:              case "Underlined":
Line 138:                  oWordApplic.Selection.Font.Subscript = 0;
Line 139:                  break;
Line 140:          }
Line 141:  
Line 142:      }
Line 143:  
Line 144:      // disable all the style  禁用所有的风格
Line 145:      public void SetFont()
Line 146:      {
Line 147:          oWordApplic.Selection.Font.Bold = 0;
Line 148:          oWordApplic.Selection.Font.Italic = 0;
Line 149:          oWordApplic.Selection.Font.Subscript = 0;
Line 150:  
Line 151:      }
Line 152:  
Line 153:      public void SetFontName(string strType)
Line 154:      {
Line 155:          oWordApplic.Selection.Font.Name = strType;
Line 156:  
Line 157:      }
Line 158:  
Line 159:      public void SetFontSize(int nSize)
Line 160:      {
Line 161:          oWordApplic.Selection.Font.Size = nSize;
Line 162:  
Line 163:      }
Line 164:  
Line 165:      public void InsertPagebreak()
Line 166:      {
Line 167:          // VB : Selection.InsertBreak Type:=wdPageBreak
Line 168:          object pBreak = (int)Microsoft.Office.Interop.Word.WdBreakType.wdPageBreak;
Line 169:          oWordApplic.Selection.InsertBreak(ref pBreak);
Line 170:      }
Line 171:  
Line 172:      // Go to a predefined bookmark, if the bookmark doesn‘t exists the application will raise an error 
Line 173:      //去到一个预先定义的书签,如果书签不存在应用程序将引发错误
Line 174:      public void GotoBookMark(string strBookMarkName)
Line 175:      {
Line 176:          // VB :  Selection.GoTo What:=wdGoToBookmark, Name:="nome"
Line 177:          object missing = System.Reflection.Missing.Value;
Line 178:  
Line 179:          object Bookmark = (int)Microsoft.Office.Interop.Word.WdGoToItem.wdGoToBookmark;
Line 180:          object NameBookMark = strBookMarkName;
Line 181:          oWordApplic.Selection.GoTo(ref Bookmark, ref missing, ref missing, ref NameBookMark);
Line 182:      }
Line 183:  
Line 184:      public void GoToTheEnd()
Line 185:      {
Line 186:          // VB :  Selection.EndKey Unit:=wdStory
Line 187:          object missing = System.Reflection.Missing.Value;
Line 188:          object unit;
Line 189:          unit = Microsoft.Office.Interop.Word.WdUnits.wdStory;
Line 190:          oWordApplic.Selection.EndKey(ref unit, ref missing);
Line 191:  
Line 192:      }
Line 193:      public void GoToTheBeginning()
Line 194:      {
Line 195:          // VB : Selection.HomeKey Unit:=wdStory
Line 196:          object missing = System.Reflection.Missing.Value;
Line 197:          object unit;
Line 198:          unit = Microsoft.Office.Interop.Word.WdUnits.wdStory;
Line 199:          oWordApplic.Selection.HomeKey(ref unit, ref missing);
Line 200:  
Line 201:      }
Line 202:  
Line 203:      public void GoToTheTable(int ntable)
Line 204:      {
Line 205:          // Selection.GoTo What:=wdGoToTable, Which:=wdGoToFirst, Count:=1, Name:=""
Line 206:          //    Selection.Find.ClearFormatting
Line 207:          //    With Selection.Find
Line 208:          //        .Text = ""
Line 209:          //        .Replacement.Text = ""
Line 210:          //        .Forward = True
Line 211:          //        .Wrap = wdFindContinue
Line 212:          //        .Format = False
Line 213:          //        .MatchCase = False
Line 214:          //        .MatchWholeWord = False
Line 215:          //        .MatchWildcards = False
Line 216:          //        .MatchSoundsLike = False
Line 217:          //        .MatchAllWordForms = False
Line 218:          //    End With
Line 219:  
Line 220:          object missing = System.Reflection.Missing.Value;
Line 221:          object what;
Line 222:          what = Microsoft.Office.Interop.Word.WdUnits.wdTable;
Line 223:          object which;
Line 224:          which = Microsoft.Office.Interop.Word.WdGoToDirection.wdGoToFirst;
Line 225:          object count;
Line 226:          count = 1;
Line 227:          oWordApplic.Selection.GoTo(ref what, ref which, ref count, ref missing);
Line 228:          oWordApplic.Selection.Find.ClearFormatting();
Line 229:  
Line 230:          oWordApplic.Selection.Text = "";
Line 231:  
Line 232:  
Line 233:      }
Line 234:  
Line 235:      public void GoToRightCell()
Line 236:      {
Line 237:          // Selection.MoveRight Unit:=wdCell
Line 238:  
Line 239:          object missing = System.Reflection.Missing.Value;
Line 240:          object direction;
Line 241:          direction = Microsoft.Office.Interop.Word.WdUnits.wdCell;
Line 242:          oWordApplic.Selection.MoveRight(ref direction, ref missing, ref missing);
Line 243:      }
Line 244:  
Line 245:      public void GoToLeftCell()
Line 246:      {
Line 247:          // Selection.MoveRight Unit:=wdCell
Line 248:  
Line 249:          object missing = System.Reflection.Missing.Value;
Line 250:          object direction;
Line 251:          direction = Microsoft.Office.Interop.Word.WdUnits.wdCell;
Line 252:          oWordApplic.Selection.MoveLeft(ref direction, ref missing, ref missing);
Line 253:      }
Line 254:  
Line 255:      public void GoToDownCell()
Line 256:      {
Line 257:          // Selection.MoveRight Unit:=wdCell
Line 258:  
Line 259:          object missing = System.Reflection.Missing.Value;
Line 260:          object direction;
Line 261:          direction = Microsoft.Office.Interop.Word.WdUnits.wdLine;
Line 262:          oWordApplic.Selection.MoveDown(ref direction, ref missing, ref missing);
Line 263:      }
Line 264:  
Line 265:      public void GoToUpCell()
Line 266:      {
Line 267:          // Selection.MoveRight Unit:=wdCell
Line 268:  
Line 269:          object missing = System.Reflection.Missing.Value;
Line 270:          object direction;
Line 271:          direction = Microsoft.Office.Interop.Word.WdUnits.wdLine;
Line 272:          oWordApplic.Selection.MoveUp(ref direction, ref missing, ref missing);
Line 273:      }
Line 274:  
Line 275:  
Line 276:      // this function doesn‘t work 这个功能不起作用
Line 277:      public void InsertPageNumber(string strType, bool bHeader)
Line 278:      {
Line 279:          object missing = System.Reflection.Missing.Value;
Line 280:          object alignment;
Line 281:          object bFirstPage = false;
Line 282:          object bF = true;
Line 283:          //if (bHeader == true)
Line 284:          //WordApplic.Selection.HeaderFooter.PageNumbers.ShowFirstPageNumber = bF;
Line 285:          switch (strType)
Line 286:          {
Line 287:              case "Center":
Line 288:                  alignment = Microsoft.Office.Interop.Word.WdPageNumberAlignment.wdAlignPageNumberCenter;
Line 289:                  //WordApplic.Selection.HeaderFooter.PageNumbers.Add(ref alignment,ref bFirstPage);
Line 290:                  //Word.Selection objSelection = WordApplic.pSelection;
Line 291:  
Line 292:                  //oWordApplic.Selection.HeaderFooter.PageNumbers.Item(1).Alignment = Microsoft.Office.Interop.Word.WdPageNumberAlignment.wdAlignPageNumberCenter;
Line 293:                  break;
Line 294:              case "Right":
Line 295:                  alignment = Microsoft.Office.Interop.Word.WdPageNumberAlignment.wdAlignPageNumberRight;
Line 296:                  //oWordApplic.Selection.HeaderFooter.PageNumbers.Item(1).Alignment = Microsoft.Office.Interop.Word.WdPageNumberAlignment.wdAlignPageNumberRight;
Line 297:                  break;
Line 298:              case "Left":
Line 299:                  alignment = Microsoft.Office.Interop.Word.WdPageNumberAlignment.wdAlignPageNumberLeft;
Line 300:                  oWordApplic.Selection.HeaderFooter.PageNumbers.Add(ref alignment, ref bFirstPage);
Line 301:                  break;
Line 302:          }
Line 303:  
Line 304:      }
Line 305:  
Line 306:  
Line 307:  }
Line 308:  //object units = WdUnits.wdCharacter;
Line 309:  //object last=doc.Characters.Count;
Line 310:  //doc.Range(ref first, ref last).Delete(ref units, ref last)
 








--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.504 


既然是调用WORD组件时出错了.那么只要对比出需要什么样的组件如何安装就好了.

服务器上是(WIN2003 X64 IIS6.0  OFFICE2003)

我本机是WIN7 X64 IIS6.1 OFFICE2007

我先将office2007 全部功能安装到服务器上先 重启测试(这个比较烦恼 服务器不止我一个项目还要选个夜深人静的时候才能测试.)

<add assembly="Microsoft.Office.Tools.Word, Version=10.0.0.0, Culture=neutral, PublicKeyToken=B03F5F