WPF场景下查询数据并使用NPOI生成EXCEL表格

Posted use-npoi

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了WPF场景下查询数据并使用NPOI生成EXCEL表格相关的知识,希望对你有一定的参考价值。

 WPF场景下后台生成DataGrid列的代码:

  1. /// <summary>
            /// 通用的出勤表头设置
            /// </summary>
            /// <param name="dgView">DataGrid实例</param>
            /// <param name="dataTable">源数据表</param>
            private void SetDataGridHearedOfAttendance(DataGrid dgView, DataTable dataTable)
                {
                dgView.ItemsSource = dataTable.DefaultView;
                dgView.Columns.Clear();
    
                TBCountMessage.Text = "" + SDate + "" + Edate + "   " +
                    "期间的出勤统计信息为: 正常出勤天数为:  "+rePortDp.NomalAttendancedays +"  天,半天数为:  "+rePortDp.HalfdayAttendancedays +"  个,加班时长为:  "+rePortDp.Workovertime+"  小时";
    
                DataGridTextColumn dategridcolumn = new DataGridTextColumn();
                dategridcolumn.Header = "出勤日期";
                dategridcolumn.Width = 180;
                dategridcolumn.Binding = new Binding("AttendanceDate");
                dategridcolumn.Binding.StringFormat = "yyyy年MM月dd日";
                dgView.Columns.Add(dategridcolumn);
    
                DataGridTextColumn DGTCattendancestatus = new DataGridTextColumn();
                DGTCattendancestatus.Header = "出勤状态";
                DGTCattendancestatus.Width = 120;
                DGTCattendancestatus.Binding = new Binding("AttendanceStatus");
                dgView.Columns.Add(DGTCattendancestatus);
    
    
                DataGridTextColumn DGTCattendanceHelper = new DataGridTextColumn();
                DGTCattendanceHelper.Header = "帮忙对象";
                DGTCattendanceHelper.Width = 120;
                DGTCattendanceHelper.Binding = new Binding("Helper");
                dgView.Columns.Add(DGTCattendanceHelper);
    
    
                DataGridTextColumn DGTCworkovertime = new DataGridTextColumn();
                DGTCworkovertime.Header = "加班时长";
                DGTCworkovertime.Width = 105;
                DGTCworkovertime.Binding = new Binding("WorkOfTime");
                DGTCworkovertime.Binding.StringFormat="0.0";
                dgView.Columns.Add(DGTCworkovertime);
    
                DataGridTextColumn DGTCattendanceremark = new DataGridTextColumn();
                DGTCattendanceremark.Header = "出勤备注";
                DGTCattendanceremark.Width = 300;
                DGTCattendanceremark.Binding = new Binding("AttendanceRemark");
                dgView.Columns.Add(DGTCattendanceremark);
                SetBtnSaveIsEnable(dgView);
    
    
               
    }

以上是关于WPF场景下查询数据并使用NPOI生成EXCEL表格的主要内容,如果未能解决你的问题,请参考以下文章

使用NPOI读取Excel数据并写入SQLite

NPOI导出excel使用

使用NPOI操作Excel

基于NPOI导出Excel

NPOI 读取Excel 表数据 数据里面带日期时的处理方法

JS异步上传Excel 并使用NPOI进行读写操作