using GemBox.ExcelLite;//引用文件 //GemBox.ExcelLite.dll (已上传到email中)
SaveFileDialog savf = new SaveFileDialog();
savf.Filter = "*.xls|.xls";
savf.ShowDialog();
ExcelFile excelFile = new ExcelFile();
ExcelWorksheet sheet = excelFile.Worksheets.Add("WolfSpider");
int columns = dataGridViewAllTaskList.Columns.Count;// dataGridView1.Columns.Count;
int rows = dataGridViewAllTaskList.Rows.Count;
for (int j = 0; j < columns; j++)
{
sheet.Cells[0, j].Value = dataGridViewAllTaskList.Columns[j].HeaderText;
}
for (int i = 1; i <= rows; i++)
{
for (int j = 0; j < columns; j++)
{
sheet.Cells[i, j].Value = dataGridViewAllTaskList[j, i - 1].Value;
}
}
excelFile.SaveXls(savf.FileName);
MessageBox.Show("文件已经保持到" + savf.FileName + "中");