本文介绍了使用EFP PLUS从SQL导出到Excel的名称表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我将sql存储过程中的数据导出到一个工作簿中的单独工作表上。代码工作,但我的工作表名称在excel文件选项卡上被称为'sheet1','sheet2'等 i想在excel上拥有我自己的工作表名称文件标签例如sheet1是名字'BenCount',sheet2'工资'他们有意义等我的代码: 我尝试过:I am exporting data from a sql stored procedure to excel on seperate sheets in one workbook . the code works however my sheet names are called 'sheet1' , 'sheet2' etc. on the excel file tabi would like to have my own sheet names on the excel file tab e.g. sheet1 be name 'BenCount', sheet2 'Wages'so that they make sense etc. my code:What I have tried: SqlConnection connex = new SqlConnection(); SqlCommand command = new SqlCommand("spTest", con) { CommandType = System.Data.CommandType.StoredProcedure }; SqlDataAdapter sda = new SqlDataAdapter(); command.Connection = con; sda.SelectCommand = command; command.CommandTimeout = 600; DataSet ds = new DataSet(); sda = new SqlDataAdapter("spTest", con); sda.Fill(ds);//Set Name of DataTables. ds.Tables[0].TableName = "Bencount"; ds.Tables[1].TableName = "Wages"; ds.Tables[3].TableName = "BeneficiariestobeExctracted"; ds.Tables[4].TableName = "benificiarieswithnoAccNo"; ds.Tables[5].TableName = "account number>11 characters/wages<100"; ds.Tables[6].TableName = "beneficiary appear on more than project"; ds.Tables[7].TableName = "Duplications by account number"; ds.Tables[8].TableName = "Check Missing Beneficiaries"; if (ds.Tables.Count > 0) { MemoryStream ms = new MemoryStream(); int i = 1; using (ExcelPackage package = new ExcelPackage(ms)) { foreach (DataTable table in ds.Tables) { ExcelWorksheet worksheet = package.Workbook.Worksheets.Add(table.TableName); worksheet.Cells["A2"].LoadFromDataTable(table, true); } Response.Clear(); package.SaveAs(Response.OutputStream); Response.AddHeader("content-disposition", "attachchment; filename=Example.xls"); Response.Charset = ""; Response.ContentType = "application/vnd.xls"; Response.End(); } } }}推荐答案 如何更改工作表Excel电子表格中的C#名称 - 堆栈溢出 [ ^ ]您好我用if语句重命名每张表Hi i used an if statement to rename the each sheetif (worksheet.Name == "sheet1") { worksheet.Name = "Bencount"; }. 感谢您的建议:)thanks for the advice :) 这篇关于使用EFP PLUS从SQL导出到Excel的名称表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-05 06:22