C#向Excel中导入数据时报错 : 其他信息: 异常来自 HRESULT:0x800A03EC?
objectNothing=System.Reflection.Missing.Value;varapp=newExcel.Application();//这里报出HRE...
object Nothing = System.Reflection.Missing.Value;
var app = new Excel.Application(); //这里报出HRESULT:0x800A03EC错误
app.Visible = false;
Excel.Workbook mybook = app.Workbooks.Open(excelName, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing);
Excel.Worksheet mysheet = (Excel.Worksheet)mybook.Worksheets[1];
mysheet.Activate();
//获取激活工作表最大行数
int maxrow = mysheet.UsedRange.Rows.Count + 1;
mysheet.Cells[maxrow, 1] = filename;
mysheet.Cells[maxrow, 2] = findString;
mysheet.Cells[maxrow, 3] = replaceString;
mybook.Save();
mybook.Close(false, Type.Missing, Type.Missing);
mybook = null;
//quit excel app
app.Quit(); 展开
var app = new Excel.Application(); //这里报出HRESULT:0x800A03EC错误
app.Visible = false;
Excel.Workbook mybook = app.Workbooks.Open(excelName, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing);
Excel.Worksheet mysheet = (Excel.Worksheet)mybook.Worksheets[1];
mysheet.Activate();
//获取激活工作表最大行数
int maxrow = mysheet.UsedRange.Rows.Count + 1;
mysheet.Cells[maxrow, 1] = filename;
mysheet.Cells[maxrow, 2] = findString;
mysheet.Cells[maxrow, 3] = replaceString;
mybook.Save();
mybook.Close(false, Type.Missing, Type.Missing);
mybook = null;
//quit excel app
app.Quit(); 展开
2019-12-04
展开全部
用 EPPlus 插件吧,导出excel很简单的。
using (ExcelPackage package = new ExcelPackage())
{
ExcelWorksheet sheet = package.Workbook.Worksheets.Add("Summary");
sheet.Cells[1, 1].Value = "1";
sheet.Cells[1, 2].Value = "2";
sheet.Cells[1, 3].Value = "3";
sheet.Cells[1, 4].Value = "4";
sheet.Cells[1, 5].Value = "5";
sheet.Cells[1, 6].Value = "6";
using (Stream stream = new FileStream(AppDomain.CurrentDomain.BaseDirectory + "\\Test.xlsx", FileMode.Create))
{
package.SaveAs(stream);
}
}
MessageBox.Show("搞定!");
using (ExcelPackage package = new ExcelPackage())
{
ExcelWorksheet sheet = package.Workbook.Worksheets.Add("Summary");
sheet.Cells[1, 1].Value = "1";
sheet.Cells[1, 2].Value = "2";
sheet.Cells[1, 3].Value = "3";
sheet.Cells[1, 4].Value = "4";
sheet.Cells[1, 5].Value = "5";
sheet.Cells[1, 6].Value = "6";
using (Stream stream = new FileStream(AppDomain.CurrentDomain.BaseDirectory + "\\Test.xlsx", FileMode.Create))
{
package.SaveAs(stream);
}
}
MessageBox.Show("搞定!");
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询