错误:方法'SaveAs'没有重载需要'11'参数 [英] Error: No overload for method 'SaveAs' takes '11' arguments
本文介绍了错误:方法'SaveAs'没有重载需要'11'参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在Excel工作表中下载datagridview记录...
i使用了下面的代码...但我在该方法中遇到错误()
请帮助我......
i wanna download datagridview records in excel sheet...
i have used belowing code...but i got error in that save method()
Pls any help me......
Microsoft.Office.Interop.Excel._Application app = new Microsoft.Office.Interop.Excel.Application();
// creating Excel Application
Microsoft.Office.Interop.Excel._Workbook workbook = app.Workbooks.Add(Type.Missing);
//Microsoft.Office.Interop.Excel._Application app = new Microsoft.Office.Interop.Excel.Application();
Microsoft.Office.Interop.Excel.Worksheet objSheet = new Microsoft.Office.Interop.Excel.Worksheet();
Microsoft.Office.Interop.Excel.Workbook objWorkBook = null;
//// creating new WorkBook within Excel application
//Microsoft.Office.Interop.Excel._Workbook workbook = app.Workbooks.Add(Type.Missing);
// see the excel sheet behind the program
app.Visible = true;
// get the reference of first sheet. By default its name is Sheet1.
// store its reference to worksheet
objSheet = objWorkBook.Sheets["Sheet1"] as Microsoft.Office.Interop.Excel.Worksheet;
objSheet = objWorkBook.ActiveSheet as Microsoft.Office.Interop.Excel.Worksheet;
// changing the name of active sheet
objSheet.Name = "Exported from gridview";
// storing header part in Excel
for (int i = 1; i < dataGridView1.Columns.Count + 1; i++)
{
objSheet.Cells[1, i] = dataGridView1.Columns[i - 1].HeaderText;
}
// storing Each row and column value to excel sheet
for (int i = 0; i < dataGridView1.Rows.Count - 1; i++)
{
for (int j = 0; j < dataGridView1.Columns.Count; j++)
{
objSheet.Cells[i + 2, j + 1] = dataGridView1.Rows[i].Cells[j].Value.ToString();
}
}
// save the application
workbook.SaveAs("c:\\output.xls", Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlExclusive, Type.Missing, Type.Missing, Type.Missing, Type.Missing) ;
推荐答案
文档说明你需要12
参数正在传递''only''11
),请参阅 MSDN [ ^ ]。
The documentation states it takes12
arguments while you are passing ''only''11
), see MSDN[^].
这篇关于错误:方法'SaveAs'没有重载需要'11'参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文