Ejemplo n.º 1
0
        private void BtnExport_Click(object sender, EventArgs e)
        {
            string start = Convert.ToDateTime(dtpStart.Text.Trim()).ToString("yyyyMMddHHmm");
            string end   = Convert.ToDateTime(dtpEnd.Text.Trim()).ToString("yyyyMMddHHmm");

            SaveFileDialog sfd = new SaveFileDialog();

            sfd.Filter           = "XLS文件(*.xls)|*.xls|所有文件|*.*";//设置保存文件的类型
            sfd.InitialDirectory = "D:\\";
            //sfd.FileName = DateTime.Now.ToString("yyyyMMddHHmmss") + "测量数据表";
            //sfd.FileName = DateTime.Now.ToString("yyyyMMddHHmmss");
            sfd.FileName     = start + "-" + end;
            sfd.DefaultExt   = "xls";
            sfd.AddExtension = true;
            if (Dgv.Rows.Count > 65535)
            {
                MessageBox.Show("报表导出失败!,原因是表格行数超过65535", "报表导出");
                return;
            }
            if (sfd.ShowDialog() == DialogResult.OK)
            {
                if (NiceExcelSaveAndRead.SaveToExcelNew(sfd.FileName, this.Dgv))
                {
                    LogHelper.WriteLog($" {CommonMethods.objAdmins.LoginName}导出数据报表");
                    MessageBox.Show("报表导出成功!", "报表导出");
                }

                else
                {
                    LogHelper.WriteLog($" {CommonMethods.objAdmins.LoginName}导出数据失败");
                    MessageBox.Show("报表导出失败!", "报表导出");
                }
            }
        }
Ejemplo n.º 2
0
        private void btn_Export_Click(object sender, EventArgs e)
        {
            SaveFileDialog sfd = new SaveFileDialog();

            sfd.Filter       = "XLS文件(*.xls)|*.xls|所有文件|*.*";//设置保存文件的类型
            sfd.FileName     = "历史日志导出Excel";
            sfd.DefaultExt   = "xls";
            sfd.AddExtension = true;
            if (sfd.ShowDialog() == DialogResult.OK)
            {
                if (NiceExcelSaveAndRead.SaveToExcelNew(sfd.FileName, this.dgv_Log))
                {
                    MessageBox.Show("报警历史日志导出成功!", "日志导出");
                    LogHelper.WriteLog(CommonMethods.objAdmins.LoginName + "导出报警日志");
                }

                else
                {
                    MessageBox.Show("历史日志导出失败!", "日志导出");
                    LogHelper.WriteLog("FrmAlarm按钮btn_Export导出故障记录失败");
                }
            }
        }