c# 导出Excel 怎么设置格式!
导出代码为!!
public bool SaveToExcel(System.Data.DataTable table, string fileName)
{
if (table.Rows.Count == 0)
{
return false;
}
Microsoft.Office.Interop.Excel.Application excel = new ApplicationClass();
int rowindex = 1;
int colindex = 0;
Workbook work = excel.Workbooks.Add(true); ;
foreach (DataColumn col in table.Columns)
{
colindex++;
excel.Cells[1, colindex] = col.ColumnName;
}
foreach (DataRow row in table.Rows)
{
rowindex++;
colindex = 0;
foreach (DataColumn col in table.Columns)
{
colindex++;
excel.Cells[rowindex, colindex] = row[col.ColumnName].ToString();
}
}
excel.Visible = false;
excel.ActiveWorkbook.SaveAs(fileName, XlFileFormat.xlExcel8, null, null, false, false, XlSaveAsAccessMode.xlNoChange, null, null, null, null, null);
excel.Quit();
excel = null;
GC.Collect();
MessageBox.Show("已保存!");
return true;
}
求助怎么设置格式
小弟我的CellEndEdit事件处理程序如何被调用了两次啊