コード例 #1
0
        private void OnExportLog(DataTable dt)
        {
            SaveFileDialog dlg = new SaveFileDialog();

            dlg.Filter = "csv files (*.csv)|*.csv";
            if (dlg.ShowDialog() == DialogResult.OK)
            {
                string            fileName      = dlg.FileName;
                DelegateExportCsv dlgtExportLog = new DelegateExportCsv(AsyExportCsv);
                waitDlg = new WaitDlg();
                dlgtExportLog.BeginInvoke(dt, fileName, CallbackExportlogOK, dlgtExportLog);
                waitDlg.ShowDialog();
            }
        }
コード例 #2
0
ファイル: LogView.cs プロジェクト: wangscript007/WES_Aoyou
        private void OnExportLog(DataTable dt)
        {
            SaveFileDialog dlg = new SaveFileDialog();

            dlg.Filter = "excel files (*.xlsx)|*.xlsx";
            if (dlg.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    string            fileName      = dlg.FileName;
                    string            sheetName     = "Log";
                    DelegateExportLog dlgtExportLog = new DelegateExportLog(AsyExportLog);
                    dlgtExportLog.BeginInvoke(dt, fileName, sheetName, CallbackExportlogOK, dlgtExportLog);
                    waitDlg = new WaitDlg();
                    waitDlg.ShowDialog();
                    //CreateExcelFile(fileName, sheetName);
                    ////string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" +
                    ////"Data Source=" + fileName + ";" +
                    ////"Extended Properties='Excel 8.0; HDR=Yes; IMEX=2'";
                    //string strConn = "Provider=Microsoft.ACE.OLEDB.12.0;" +
                    //"Data Source=" + fileName + ";" +
                    //"Extended Properties='Excel 12.0; HDR=Yes; IMEX=0'";
                    //using (OleDbConnection ole_conn = new OleDbConnection(strConn))
                    //{
                    //    ole_conn.Open();
                    //    using (OleDbCommand ole_cmd = ole_conn.CreateCommand())
                    //    {
                    //        foreach (DataRow dr in dt.Rows)
                    //        {
                    //            string logContent = dr["内容"].ToString();
                    //            logContent = logContent.Substring(0, Math.Min(255, logContent.Count()));
                    //            ole_cmd.CommandText = string.Format(@"insert into [{0}$](日志ID,内容,类别,日志来源,时间)values('{1}','{2}','{3}','{4}','{5}')", sheetName, dr["日志ID"].ToString(), logContent, dr["类别"].ToString(), dr["日志来源"].ToString(), dr["时间"].ToString());
                    //            ole_cmd.ExecuteNonQuery();
                    //        }

                    //        MessageBox.Show("数据导出成功......");
                    //    }
                    //}
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            }
        }