26、列表插件,引出Excel原创
24人赞赏了该文章
1.1万次浏览
编辑于2020年07月07日 18:32:31
业务场景:仿标准产品,引出EXCEL功能;
1、打开VS,新建一个类库,具体可以参考21.1 ,1-4步
1.1、本节新增引用
Kingdee.BOS.ServiceHelper
2、
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data; using Kingdee.BOS.App.Data; using Kingdee.BOS.Util; using Kingdee.BOS.Core.List.PlugIn; using Kingdee.BOS.Core.List; using Kingdee.BOS.Core.DynamicForm; using Kingdee.BOS.Core; using Kingdee.BOS.ServiceHelper.Excel; using System.ComponentModel; namespace Kingdee.Bos.Excel { [Description("引出Excel")] [Kingdee.BOS.Util.HotUpdate] public class ClassExcel:AbstractListPlugIn { string sql; DataSet ds; DataTable dt; public override void BarItemClick(BOS.Core.DynamicForm.PlugIn.Args.BarItemClickEventArgs e) { base.BarItemClick(e); //当点击按钮 if(e.BarItemKey.Equals("YDIE_tbTest")) { //选择哪几行 ListSelectedRowCollection selectRows = this.ListView.SelectedRowsInfo; //把获取的主键赋值给一个数组 string[] ID = selectRows.GetPrimaryKeyValues(); //设置一个空值 string FID = ""; //没有选择单据,提示 //如果空值的长度等于0 if(ID.Length ==0) { this.View.ShowMessage("请选择单据", MessageBoxType.Notice); return; } //如果选择了单据 else { for(int i=0;i<ID.Length;i++) { FID = FID + ID[i].ToString() + ","; } } //查询出FID里面的,单据编号 sql = "/*dialect*/select FBillNo as '单据编号' from T_SAL_OUTSTOCK where fid in(" + FID.Substring(0,FID.Length -1) + ")"; //执行sql ds = DBUtils.ExecuteDataSet(this.Context, sql); //把单据编号放到dt表里面 dt = ds.Tables[0]; //金蝶对Excel操作 string fileName = string.Format("{0},{1}.xls", "销售出库单", DateTime.Now.ToString("hhmmssffffff")); //获取路径 string filePath = PathUtils.GetPhysicalPath(KeyConst.TEMPFILEPATH, fileName); //获取服务器Url地址,把文件传到服务器上面,然后下载 string fileUrl = PathUtils.GetServerPath(KeyConst.TEMPFILEPATH, fileName); using (ExcelOperation excelHelper = new ExcelOperation(this.View)) { excelHelper.BeginExport(); //数据内容 dt,单据编号 excelHelper.ExportToFile(dt); //路径,保存为excel文件 excelHelper.EndExport(filePath, SaveFileType.XLS); } //打开文件下载界面 DynamicFormShowParameter showParameter = new DynamicFormShowParameter(); showParameter.FormId = "BOS_FileDownload"; showParameter.OpenStyle.ShowType = ShowType.Modal; showParameter.CustomComplexParams.Add("url", fileUrl); //显示 this.View.ShowForm(showParameter); } } } }
3、重新生成dll
4、重新打开销售出库单列表,点按钮,下载excel,点下载,打开excel
------------------------------------------------------------------------------------
5、没有表头,添加
select '单据编号' union all
sql = "/*dialect*/select '单据编号' union all select FBillNo as '单据编号' from T_SAL_OUTSTOCK where fid in (" + FID.Substring(0, FID.Length - 1) + ")";
6、 重新生成dll
7、重新打开销售出库单列表,点按钮,下载excel,点下载,打开excel
总目录链接
https://vip.kingdee.com/article/64993872014591232
Kingdee.Bos.Test26.zip(15.94KB)