日期:2014-05-18 浏览次数:21034 次
try { if (dgvw_ycl.Rows.Count == 1) { return; } Microsoft.Office.Interop.Excel.Application Excel = new Microsoft.Office.Interop.Excel.Application(); Excel.Visible = false; Workbook Excel_Book = Excel.Application.Workbooks.Add(true); Worksheet Excel_Sheet = (Worksheet)Excel.ActiveSheet; for (int i = 0; i < dgvw_ycl.Columns.Count; i++) { Excel.Cells[1, i + 1] = dgvw_ycl.Columns[i].HeaderText; } for (int i = 0; i < dgvw_ycl.Rows.Count - 1; i++) { for (int j = 0; j < dgvw_ycl.Columns.Count; j++) { if (dgvw_ycl[j, i].ValueType == typeof(string)) { Excel.Cells[i + 2, j + 1] = "'" + dgvw_ycl[j, i].Value.ToString(); } else { Excel.Cells[i + 2, j + 1] = dgvw_ycl[j, i].Value.ToString(); } } } Excel.DisplayAlerts = false; Excel.AlertBeforeOverwriting = false; Excel.Application.Save(); Excel.Quit(); Excel = null; } catch (Exception ee) { MessageBox.Show(ee.Message, "错误!"); }
------解决方案--------------------
这个问题直接在网商搜。 思路明确了 就好做。
------解决方案--------------------
------解决方案--------------------
参考