C#如何导出一个Excel表格多个sheet页

 我来答
龙祥涛0047
2013-08-24 · TA获得超过188个赞
知道答主
回答量:127
采纳率:0%
帮助的人:134万
展开全部
string ExcelName = "设备列表" + ".xls";//导出的Excel表格名 string sql = "select * from joa_equip_class select * from joa_equip_info select * from joa_equip_parket_class select * from joa_equip_maintenance"; DataSet ds = ComData.jdataset(sql); string[][] ArrName ={ new string[] { "类别大", "类别小", "类别名", "排序", "系统时间", "备注" }, new string[] { "设备编号", "设备名称", "设备型号", "生产厂家", "生产日期", "技术状态", "存放位置", "负责人", "配属单位", "条形码", "有效期", "类别id", "存放位置id", "设备照片" }, new string[] { "类别id大", "类别id小", "存放位置", "货物号", "保管人", "备注", "排序" }, new string[] { "设备名称", "设备编号", "责任单位", "责任人", "维护保养费", "维护保养性质", "详细说明" } }; string[][] ArrDs ={ new string[] { "parent_id", "class_id", "class_name", "order_id", "systime", "remark" }, new string[] { "equip_id", "name", "model", "factory", "production_date", "state", "store", "duty_name", "unit", "bar", "useful_time", "class_id", "parket_id", "photo" }, new string[] { "parent_id", "parket_id", "class_name", "goods_nums", "person", "remark", "order_id" }, new string[] { "equip_name", "equip_id","duty_bum", "duty_name", "money", "kind", "explain" } }; string[] SheetName ={ "类别表", "设备列表" ,"存储位置表","维护保养记录表"}; Equce eq = new Equce(); eq.ToExcel(ds, ArrName, ArrDs, ExcelName, SheetName);//数据DataSet,列名,列数据名,Excel表格名,sheet页名 -------------------------------------------------------------------------------------------------------------------- //导出一个或多个数据表 public void ToExcel(DataSet ds, string[][] ArrName, string[][] ArrDs, string ExcelName, string[] Sheet_Name){AppLibrary.WriteExcel.XlsDocument doc = new AppLibrary.WriteExcel.XlsDocument(); //doc.FileName = "Report.xls"; doc.FileName = HttpUtility.UrlEncode(ExcelName, System.Text.Encoding.UTF8);//防止导出Excel乱码 string SheetName = string.Empty; int k = ds.Tables.Count;//表的个数 for (int i = 0; i < k; i++){//SheetName = "当前是SHEET" + i.ToString(); SheetName = Sheet_Name[i].ToString(); AppLibrary.WriteExcel.Worksheet sheet = doc.Workbook.Worksheets.Add(SheetName); AppLibrary.WriteExcel.Cells cells = sheet.Cells; for (int j = 1; j <= ArrName[i].Length; j++)//加入标题{if (ArrName[i][j - 1] != "") cells.Add(1, j, ArrName[i][j - 1].ToString());}int f = 1;int a = ds.Tables[i].Rows.Count; ; for (int m = 0; m < a; m++){f++;for (int n = 1; n <= ArrDs[i].Length; n++)//循环列{if (ArrDs[i][n - 1] != "") cells.Add(f, n, ds.Tables[i].Rows[m][ArrDs[i][n - 1]].ToString());}}}doc.Send();
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式