问题描述
你好,
我正在构建一些工作程序,并要求它们导入excel文件以进行内部处理.我这样做没问题.
我现在已经构建并测试了程序.将程序移至2003服务器.我现在在使用excel互操作时收到错误.
我已将互操作文件复制到程序位置(Interop.IWshRuntimeLibrary.dll),此操作没有成功.
我在服务器上安装了.Net 3.5,但也没有帮助.
经过30分钟的梳理,我了解到可能需要在服务器上安装Office才能运行IWSH运行时库.
令我感到困惑的是,我家里的XP机器上没有安装办公室,但是所有这些操作都可以正常进行.
在家里我安装了Visual Studio 2008,我假设它包含IWSH库所需的库,因此允许代码在家里运行而不会出错.
谁能给我带来启示?
Hello,
I am building a few programs for work and require them to import excel files for internal processing. I have no issue doing such.
I have now built and tested the programs. Apon moving the programs to the 2003 server. I am now receiving errors when using the excel interop operations.
I have copied the interop file to the program location (Interop.IWshRuntimeLibrary.dll), this had no success.
I installed .Net 3.5 on the server, which has also not helped.
After pulling my hair out for 30 minutes, I have come to the understanding that I may require office to be installed on the server for the IWSH runtime library to operate.
Whats puzzling me, I do not have office installed on my XP machine at home, yet all these operations work without error.
At home I have Visual Studio 2008 installed, I presume that it contains the libraries required for the IWSH library, therefor allows the code to run at home without error.
Can anyone shed any light for me?
See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.
************** Exception Text **************
System.IO.FileNotFoundException: Could not load file or assembly ''System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'' or one of its dependencies. The system cannot find the file specified.
File name: ''System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089''
at Contact_Manager_Server.UserControls.ExcelFilesourceSelecter.tbFilesource_TextChanged(Object sender, EventArgs e)
at System.Windows.Forms.Control.OnTextChanged(EventArgs e)
at System.Windows.Forms.TextBoxBase.OnTextChanged(EventArgs e)
at System.Windows.Forms.Control.set_Text(String value)
at System.Windows.Forms.TextBoxBase.set_Text(String value)
at System.Windows.Forms.TextBox.set_Text(String value)
at Contact_Manager_Server.UserControls.ExcelFilesourceSelecter.btnBrowseFilesource_Click(Object sender, EventArgs e)
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
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].
</pre>
推荐答案
Results.QueryData = new DataTable();
using (OleDbConnection OleConnection = new OleDbConnection(QueryConfiguration.OleConnectionString))
{
OleConnection.Open();
using (OleDbDataAdapter OleAdapter = new OleDbDataAdapter(QueryConfiguration.SqlStatement, OleConnection))
OleAdapter.Fill(Results.QueryData);
OleConnection.Close();
}
private void tbFilesource_TextChanged(object sender, EventArgs e)
{
if (tbFilesource.Text == "")
{
cbWorkbook.Enabled = false;
}
else
{
cbWorkbook.Enabled = true;
cbWorkbook.Items.Clear();
cbWorkbook.Items.AddRange(
Excelerater.ExcelQueryConiguration.GetWorkbookSpreadsheets(tbFilesource.Text).ToArray());
}
}
这似乎仅是由于GetWorkbookSpreadsheets方法返回一个string []对象而产生的错误,该对象在传递给组合框的AddRange方法时将被转换为ToArray().
更新的工作代码:
This appears to generate the error simply because GetWorkbookSpreadsheets method returns a string[] object which is being converted ToArray() as it is passed to the AddRange method of the combobox.
Updated working code:
private void tbFilesource_TextChanged(object sender, EventArgs e)
{
if (tbFilesource.Text == "")
{
cbWorkbook.Enabled = false;
}
else
{
cbWorkbook.Enabled = true;
cbWorkbook.Items.Clear();
cbWorkbook.Items.AddRange(
Excelerater.ExcelQueryConiguration.GetWorkbookSpreadsheets(tbFilesource.Text));
}
}
如您所见,GetWorkbookSpreadsheets()方法现在未转换为ToArray,现在也不会导致错误.
我认为这是.net框架版本之间的问题.
即使它们报告的是静态环境类的相同版本.
As you can see the GetWorkbookSpreadsheets() method is now not being converted ToArray and now does not cause the error.
I figure this is a problem between .net framework versions.
Even though they report the same versions from the static Environment class.
这篇关于未安装Microsoft Office的Excel Interop的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!