//保存的Excel public bool SaveExcel(DataGridView girdView, bool isShowExcle) { if (girdView.Rows.Count == 0) //判断数据是否等于0 return false; //创建 Excel 对象 Excel.Application excel = new Microsoft.Office.Interop.Excel.Application(); excel.Application.Workbooks.Add(true); excel.Visible = isShowExcle; //生成字段名称(列名) for (int i = 0; i < dataGridView1.ColumnCount - 1; i++) { excel.Cells[1, i + 1] = girdView.Columns[i].HeaderText; } //填充数据 for (int i = 0; i < girdView.RowCount - 1; i++) { for (int j = 0; j < girdView.ColumnCount; j++) { //判断类型是否是字符串 if (girdView[j, i].ValueType == typeof(string)) excel.Cells[i + 2, j + 1] = "'" + girdView[j, i].Value.ToString(); else excel.Cells[i + 2, j + 1] = girdView[j, i].Value; } } return true; }完善上一种方式: