我的winform程序从datagrid导出到excel老是出错,请高手指点!在线等!
private string ExportToExcel(string filename)
{
System.Threading.Thread thisThread = System.Threading.Thread.CurrentThread;
System.Globalization.CultureInfo originalCulture = thisThread.CurrentCulture;
object objOpt = System.Reflection.Missing.Value;
try
{
object obj = System.Reflection.Missing.Value;
Microsoft.Office.Interop.Excel.Application app = new Microsoft.Office.Interop.Excel.Application();
app.Visible = true;
Workbooks workbooks = app.Workbooks;
_Workbook workbook = workbooks.Add(XlWBATemplate.xlWBATWorksheet);
Sheets sheets = workbook.Worksheets;
_Worksheet worksheet = (_Worksheet)sheets.get_Item(1);
int ridx = 1;
int cidx = 0;
for (int i = 0; i < dataGridView1.ColumnCount; i++)
{
worksheet.Cells[0, i] = dataGridView1.Columns[i].HeaderText;
}
if (dataGridView1.RowCount > 0)
{