在裸机中运行导出Excel出错,提示"检索com类工厂中CLSID为{略}的组件时失败,原因出现以下错误:80040154(略)",并且在其逻辑系统中运行打包进去的Excel.exe也是不行,请问有什么办法可以解决它呢??可以给出具体点的解决方案吗??
解决方案 »
- C#关于委托的问题。 C#的代码真心难搞,搞了一天没搞出来。
- 使用OleDbDataAdapter和OleDbCommandBuilder更新Access表的问题
- 救命啊,我快抓狂了。。。c# 返回参数存储过程 不能执行啊
- 正则?
- 把flash文件存在数据库里,怎么让它在axShockwaveFlash1控件上显示
- RangeValidator怎么不起作用了
- stephenZL接分,答应了解决问题后600分
- DropDownList 菜鸟问题
- 哪位大神看看下面这段代码有什么问题?代码没有错误,运行时出现问题,本人菜鸟勿喷!
- 控件的Dock问题?很简单,会的一点就给分!!!在线等
- System.Drawing.Image实例对象如何转换成sbyte[], 反之,一个sbyte[]如何转变成一个Image对象
- C#如何传值给textbox(MySql数据库)
另外,就算是你安装了EXCEL,也不能保证在数据量非常大的情况下不出问题。所以直接写EXCEL文件是根本解决之道。
{
MessageBox.Show("没有数据可供导出", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;
}
EnableBtn();
string filepath = "";
int excelpos = 0;
sFDExcel.Filter = "Excel表格|*.xls";
sFDExcel.ShowDialog();
if (sFDExcel.FileName.Equals(""))
{
return;
}
else
{
filepath = sFDExcel.FileName;
if (File.Exists(filepath))
{
File.Delete(filepath);
}
}
object miss = Type.Missing;
Excel.Application exap = new Excel.Application();
Excel.Workbook workbook = exap.Workbooks.Add(true);
Excel.Sheets shts = workbook.Sheets;
try
{
Excel.Worksheet sht = (Excel.Worksheet)shts.Add(miss, workbook.Sheets[workbook.Sheets.Count], 1, miss);
sht.Name = "库存信息";
((Excel.Range)sht.Cells[1, 3]).Value2 = "类型";
((Excel.Range)sht.Cells[1, 1]).Value2 = "编号";
((Excel.Range)sht.Cells[1, 2]).Value2 = "名称";
((Excel.Range)sht.Cells[1, 4]).Value2 = "数量";
((Excel.Range)sht.Cells[1, 5]).Value2 = "售价";
((Excel.Range)sht.Cells[1, 6]).Value2 = "备注";
excelpos = 1;
foreach (DataGridViewRow dr in DGV.Rows)
{
excelpos = excelpos + 1;
((Excel.Range)sht.Cells[excelpos, 3]).Value2 = dr.Cells["ClsName"].Value.ToString();
((Excel.Range)sht.Cells[excelpos, 1]).Value2 = dr.Cells["Barcode"].Value.ToString();
((Excel.Range)sht.Cells[excelpos, 2]).Value2 = dr.Cells["GodName"].Value.ToString();
((Excel.Range)sht.Cells[excelpos, 4]).Value2 = dr.Cells["NowAmt"].Value.ToString();
((Excel.Range)sht.Cells[excelpos, 5]).Value2 = dr.Cells["SelPrice"].Value.ToString();
((Excel.Range)sht.Cells[excelpos, 6]).Value2 = dr.Cells["StcNote"].Value.ToString();
System.Windows.Forms.Application.DoEvents();
}
MessageBox.Show("你已经成功导出Excel", " 提示信息", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, " 提示信息", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
finally
{
workbook.SaveCopyAs(filepath);
workbook.Saved = true;
//workbook.Save();
//exap.Save(filepath);
exap.Quit();
EnableBtn();
}
不是这样写到Excel文件吗??
http://topic.csdn.net/u/20071129/15/9d1878af-89a8-441a-8681-88a5b46e684f.html
代码我BLOG里有相关资料。