方便好用的类模板,传入dataset 就可以生成EXCEL。要添加引用Microsoft.Office.Interop.Excel.dll
class ToExcel
{
// excelName为保存的EXCEL名称
public void ToExl(DataSet ds, string excelName)
{
int tablecount = ds.Tables.Count;
if (tablecount <= 0) return ;
int index = 0;
Microsoft.Office.Interop.Excel.Application xlApp = null;
Microsoft.Office.Interop.Excel.Workbook xlBook = null;
Microsoft.Office.Interop.Excel.Worksheet xlSheet = null;
int rowIndex = 1;
int colIndex = 0;
object missing = Missing.Value;
try
{
xlApp = new Microsoft.Office.