日期:2014-05-17 浏览次数:20577 次
public static string Export(DataSet ds, string file_name, string save_path)
{
if (ds != null)
{
int countR = ds.Tables[0].Rows.Count;//读取数据的行数
int countC = ds.Tables[0].Columns.Count - 1;//读取数据的列数
Microsoft.Office.Interop.Excel.ApplicationClass excelApp = new Microsoft.Office.Interop.Excel.ApplicationClass
();//实例化Excel
Microsoft.Office.Interop.Excel.Workbook wb = excelApp.Application.Workbooks.Add(true);//创建WorkBook
Microsoft.Office.Interop.Excel.Worksheet ws = (Microsoft.Office.Interop.Excel.Worksheet)wb.Worksheets
["Sheet1"];//创建WorkSheet
ws.Name = file_name;//重命名Sheet1
try
{
ws.Cells[1, 2] = file_name;//写表名
ws.Cells[1, 7] = "表示未付款";
ws.Cells[2, 1] = "序列";
for (int i = 0; i < countC; i++)
{
ws.Cells[2, i + 2] = ds.Tables[0].Columns[i].ColumnName;//写表头
}
for (int i = 0; i < countR; i++)