IM尝试使用Visual Studio 2010中的C#,问题是它正在采取永远保存,导出的datagridview擅长的WinForms应用程序(的.xls),到目前为止,我有4220行和20列。有没有更快的方法来做到这一点。注意:我正在从保存的excel文件填充datagridview。我感谢您的帮助....我保存的代码如下:大的datagridview导出到Excel
private void btnSave_Click(object sender, EventArgs e)
{
Excel.Application xlApp;
Excel.Workbook xlWorkBook;
Excel.Worksheet xlWorkSheet;
object misValue = System.Reflection.Missing.Value;
xlApp = new Excel.Application();
xlWorkBook = xlApp.Workbooks.Add(misValue);
xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
// Get the Header from dataGridView
for (int h = 1; h < dataGridView1.Columns.Count + 1; h++)
{
xlWorkSheet.Cells[1, h] = dataGridView1.Columns[h - 1].HeaderText;
}
// Get the Cell Values
for (int i = 0; i < dataGridView1.Rows.Count - 1; i++)
{
for (int j = 0; j < dataGridView1.Columns.Count; j++)
{
DataGridViewCell cell = dataGridView1[j, i];
xlWorkSheet.Cells[i + 2, j + 1] = cell.Value;
}
}
//xlWorkBook.SaveCopyAs("\\FORM TEST.xlsx");
xlWorkBook.SaveAs("\\GB STOCK.xls", Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);
xlWorkBook.Close(true, misValue, misValue);
xlApp.Quit();
xlApp = null;
xlWorkBook = null;
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
}