乔山办公网我们一直在努力
您的位置:乔山办公网 > excel表格制作 > -dataset导出到excel,adodb导出到excel最快

-dataset导出到excel,adodb导出到excel最快

作者:乔山办公网日期:

返回目录:excel表格制作







有问题再e79fa5e98193e78988e69d83336联系我 using System; using System.Collections.Generic; using System.Text; using System.Data; namespace 导出到word或excel中 { public class ExcelCtr { /// <summary> /// 返回是否导出数据 /// </summary> /// <param name="ds">导出的数据集合</param> /// <param name="tablename">表名</param> /// <param name="lies">表头</param> /// <returns></returns> public bool ECtr(DataSet ds, string tablename, string[] lies) { bool b = false; Excel.Application xlsApp = new Excel.Application(); Excel._Workbook xlsBook = xlsApp.Workbooks.Add(Excel.XlWBATemplate.xlWBATWorksheet); Excel._Worksheet xlsSheet = (Excel._Worksheet)xlsBook.Worksheets[1]; try { xlsSheet.Cells[1, 6] = tablename;//和word一样,行列的索引也是从1开始 int k = 0; foreach (string s in lies) { xlsSheet.Cells[2, k + 5] = s;//添加表头 k++; } int i = 0; for (; i < ds.Tables[0].Rows.Count; i++) { for (int l = 0; l < ds.Tables[0].Columns.Count; l++) { xlsSheet.Cells[i + 3, l + 5] = ds.Tables[0].Rows[i][l].ToString(); } } xlsSheet.Cells[i + 5, 8] = "添加时间:" + DateTime.Now;//cells[ , ]前者表示行,后者表示列 string FileName = xlsApp.GetSaveAsFilename("", "Excel文件 (*.xls), *.xls", 1, "Hello", "Hi").ToString().Trim();//保存格式 if (FileName != "False" && FileName != "") { xlsSheet.SaveAs(FileName, Excel.XlFileFormat.xlExcel9795, "", "", false, false, false, 1, 1, true);//保存的类型,可设置密码 只读 .. b = true; } xlsBook.Saved = true; xlsApp.Workbooks.Close(); xlsApp.Quit(); } catch (Exception) { xlsApp.Workbooks.Close(); xlsApp.Quit(); b = false; throw; } return b; } } }

相关阅读

关键词不能为空
极力推荐

ppt怎么做_excel表格制作_office365_word文档_365办公网