问题描述
- 请教C#,Form窗口的一个Button,调用Excel导出表格时出错
-
一个调用Excel导出表的操作,出错。请熟悉excel调用的高手指教。相关代码:
private void button1_Click(object sender, EventArgs e)
{
saveFileDialog1.AddExtension = true;//对话框自动在文件名中添加扩展名
saveFileDialog1.FileName = name+"与"+name1+"担保信息";//设置对话框初始目录
saveFileDialog1.Filter = "excel files(*.xls)|*.xls";
saveFileDialog1.FilterIndex = 0;
saveFileDialog1.ShowDialog();//弹出对话框
// MessageBox.Show(filename);
if (filename != null)
ExcelExport.CreateExcel(dt, filename);
}在电脑A上正常运行。在电脑B上出现如下提示。其中,电脑A未安装WPS。电脑B安装WPS后又安装了微软Office2003,xls文件默认仍以Excel打开。
以下是错误提示:
System.IO.FileNotFoundException: Could not load file or assembly 'office, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' or one of its dependencies. 系统找不到指定的文件。
File name: 'office, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'
at DBQ.ExcelExport.CreateExcel(DataTable dt, String fileName)
at DBQ.district_find_inf.button1_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 HKLMSoftwareMicrosoftFusion!EnableLog to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLMSoftwareMicrosoftFusion!EnableLog].