private void toolStripButton1_Click(object sender, EventArgs e)
        {
            DataTable dt = new DataTable();

            foreach (DataGridViewColumn col in DGV.Columns)
            {
                dt.Columns.Add(col.HeaderText);
            }

            foreach (DataGridViewRow row in DGV.Rows)
            {
                DataRow dRow = dt.NewRow();
                foreach (DataGridViewCell cell in row.Cells)
                {
                    dRow[cell.ColumnIndex] = cell.Value;
                }
                dt.Rows.Add(dRow);
            }
            SaveFileDialog saveFileDialog1 = new SaveFileDialog();

            saveFileDialog1.AddExtension = true;
            saveFileDialog1.DefaultExt   = "xlsx";
            saveFileDialog1.Filter       = "*.xlsx|*.*";

            if (saveFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                Excel.ExcelUtlity obj = new Excel.ExcelUtlity();
                obj.WriteDataTableToExcel(dt, "Excel Report", saveFileDialog1.FileName, "Details");
            }
        }
Exemple #2
0
        public void ExportToExcel()
        {
            var chartTitle = currentChartDto.ChartTitle;
            var obj        = new Excel.ExcelUtlity();

            var labels = currentChartDto.Labels;
            var values = currentChartDto.Values;

            var list = new List <ExportClass>();

            foreach (var seriesHandler in values)
            {
                var it = 0;
                var seriesHandlerCounts       = seriesHandler.Counts;
                var seriesHandlerDoubleCounts = seriesHandler.DoubleCounts;
                if (seriesHandlerCounts != null)
                {
                    foreach (var seriesHandlerCount in seriesHandlerCounts)
                    {
                        list.Add(new ExportClass
                        {
                            Serie  = seriesHandler.SerieTitle,
                            Item   = labels.ElementAt(it),
                            Nombre = seriesHandlerCount
                        });
                        it++;
                    }
                }
                else if (seriesHandlerDoubleCounts != null)
                {
                    foreach (var seriesHandlerDoubleCount in seriesHandlerDoubleCounts)
                    {
                        list.Add(new ExportClass
                        {
                            Serie  = seriesHandler.SerieTitle,
                            Item   = labels.ElementAt(it),
                            Nombre = seriesHandlerDoubleCount
                        });
                        it++;
                    }
                }
            }

            var dt             = ConvertToDataTable(list);
            var myDocumentPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);

            obj.WriteDataTableToExcel(dt, "MOTS", $"{myDocumentPath}\\MOTS_Export.xlsx", chartTitle);
        }
        private void GenerateExcelMOBySysID(string sysid)
        {
            try
            {
                npgsqlConnection = new NpgsqlConnection(CONNECTION_STRING);
                npgsqlConnection.Open();

                DataTable dataTable = new DataTable();

                string requete = requeteSmsMO.Replace("%WEEK%", _week.ToString()).Replace("%YEAR%", _year.ToString());
                requete = requete.Replace("%id_sms_mo%", idSmsMoMin).Replace("%SYSID%", sysid);

                dataTable.Columns.Add("sysid", typeof(String));
                dataTable.Columns.Add("id_sms_mo", typeof(String));
                dataTable.Columns.Add("sms", typeof(String));
                dataTable.Columns.Add("msisdn", typeof(String));
                dataTable.Columns.Add("shortcode", typeof(String));
                dataTable.Columns.Add("codser", typeof(String));
                dataTable.Columns.Add("status", typeof(String));
                dataTable.Columns.Add("entry_date", typeof(String));
                dataTable.Columns.Add("login", typeof(String));

                NpgsqlCommand    npgsqlCommand = new NpgsqlCommand(requete, npgsqlConnection);
                NpgsqlDataReader dr            = npgsqlCommand.ExecuteReader();

                while (dr.Read())
                {
                    dataTable.Rows.Add(dr[0].ToString(), dr[1].ToString(), dr[2].ToString(), dr[3].ToString(), dr[4].ToString(), dr[5].ToString(), GetStatutMO(dr[6].ToString()), dr[7].ToString(), dr[8].ToString());
                }

                dr.Close();
                npgsqlConnection.Close();

                Excel.ExcelUtlity obj = new Excel.ExcelUtlity();

                string title    = "STAT SYSID " + sysid + " -Y" + _year.ToString() + " - W" + _week.ToString();
                string fileName = "Content_MO_Y" + _year.ToString() + "_W" + GetWeek(_week) + "_S-" + sysid + ".xlsx";

                obj.WriteDataTableToExcel(dataTable, title, PARAM_PATH_EXCEL + fileName, "");
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        private void iconButtonUpdateData_Click(object sender, EventArgs e)
        {
            var folderBrowserDialog1 = new FolderBrowserDialog();
            // Show the FolderBrowserDialog.
            DialogResult result = folderBrowserDialog1.ShowDialog();

            if (result == DialogResult.OK)
            {
                labelTime.Visible = true;

                string command = "select * from " + "historysearch order by id DESC";
                Database.load(command);
                DataView          view       = new DataView(Database.loadData);
                DataTable         selected   = view.ToTable(false, "Word", "Meaning", "TimeSearch", "Bookmark", "Translate");
                Excel.ExcelUtlity obj        = new Excel.ExcelUtlity();
                string            folderName = folderBrowserDialog1.SelectedPath;
                obj.WriteDataTableToExcel(selected, "Saved Translated Data", folderName + "TranslatedList.xlsx", "TranslatedList");

                MessageBox.Show("Folder was created");
            }
        }
Exemple #5
0
        private void btnExpSocios_Click(object sender, EventArgs e)
        {
            SaveFileDialog sfd = new SaveFileDialog();

            sfd.InitialDirectory = "c:\\";
            sfd.Filter           = "Archivos de excel (*.xlsx)|*.xlsx";
            sfd.FilterIndex      = 1;
            sfd.RestoreDirectory = true;

            if (sfd.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    Excel.ExcelUtlity obj = new Excel.ExcelUtlity();
                    obj.WriteDataTableToExcel((DataTable)dgvListaSocios.DataSource, "Socios", sfd.FileName, "Socios");
                    MessageBox.Show(this, "Archivo de excel creado en la ubicación [" + sfd.FileName + "]", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(this, "Error del Sistema: " + ex.Message, "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            DataTable dt = new DataTable();
            foreach (DataGridViewColumn col in DGV.Columns)
            {
                dt.Columns.Add(col.HeaderText);
            }

            foreach (DataGridViewRow row in DGV.Rows)
            {
                DataRow dRow = dt.NewRow();
                foreach (DataGridViewCell cell in row.Cells)
                {
                    var s = cell.Value;
                    if (s == null)
                    {
                        goto Finish;

                    }

                    if (Regex.IsMatch(s.ToString(), @"[=]") && s !=null )
                    {

                   string[] operands = Regex.Split(s.ToString(), @"\D+");
                   string[] operands2 = Regex.Split(s.ToString(), @"\d+");
                   string ar = "";
                   foreach (string value in operands)
                   {
                       //
                       // Parse the value to get the number.
                       //
                       int number1;
                       if (int.TryParse(value, out number1))
                       {
                           int er = Convert.ToInt32(value) + 1;

                          // MessageBox.Show(er.ToString());
                           ar += Convert.ToString(er)+",";

                       }
                   }
                   string[] operan3 = Regex.Split(ar, @"\D+");
                   string[] arr = new string[operan3.Length];
                   string ar2 = "";
                   for (int i = 0, j = 0; i < operan3.Length; i++, j++)
                   {
                      // arr[i] = operands2[i] + operan3[j];
                       ar2 += Convert.ToString(operands2[i] + operan3[j]);
                   }

                   s = ar2;

                    }
                Finish :
                    dRow[cell.ColumnIndex] = s;
                }
                dt.Rows.Add(dRow);
            }
            SaveFileDialog saveFileDialog1 = new SaveFileDialog();

            saveFileDialog1.AddExtension = true;
            saveFileDialog1.DefaultExt = "xls";
            saveFileDialog1.Filter = "*.xls|*.*";

                if (saveFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    Excel.ExcelUtlity obj = new Excel.ExcelUtlity();
                    obj.WriteDataTableToExcel(dt, "Excel Report", saveFileDialog1.FileName, "Details");
                }
        }
 private void btnExportExcel_Click(object sender, EventArgs e)
 {
     try {
     SaveFileDialog saveFileDialog1 = new SaveFileDialog();
     saveFileDialog1.AddExtension = true;
     saveFileDialog1.DefaultExt = "xlsx";
     saveFileDialog1.Filter = "*.xlsx|*.*";
     if(saveFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
     {
      //   DataTable dt = new DataTable("ExcelTable");
         Excel.ExcelUtlity obj = new Excel.ExcelUtlity();
         DataView dv = new DataView(Global.Instance.OrdetTable);
         dv.RowFilter = "status =  'Traded'";
         dv.ToTable("ExcelTable");
         DataTable dt = dv.ToTable("ExcelTable");
         obj.WriteDataTableToExcel(dt, "Excel Report", saveFileDialog1.FileName, "Details");
        }
     }
     catch (Exception ex)
     {
         //MessageBox.Show("Order Book -  Funtion Name-  btnExportExcel_Click  " + ex.Message);
     }
 }
        private void btnExportExcel_Click(object sender, EventArgs e)
        {
            try {
                Global.Instance.TradeTracker.WriteXml(Application.StartupPath + Path.DirectorySeparatorChar + System.DateTime.Now.Date.ToString("dddd, MMMM d, yyyy") + "tradetrack.xml");
            SaveFileDialog saveFileDialog1 = new SaveFileDialog();
            saveFileDialog1.AddExtension = true;
            saveFileDialog1.DefaultExt = "xlsx";
            saveFileDialog1.Filter = "*.xlsx|*.*";
            if(saveFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
             //   DataTable dt = new DataTable("ExcelTable");
                Excel.ExcelUtlity obj = new Excel.ExcelUtlity();
                DataView dv = new DataView(Global.Instance.OrdetTable);
                dv.RowFilter = "status =  'Traded'";
                dv.ToTable("ExcelTable");
                DataTable dt = dv.ToTable("ExcelTable");
                obj.WriteDataTableToExcel(dt, "Excel Report", saveFileDialog1.FileName, "Details");

            }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Order Book -  Funtion Name-  btnExportExcel_Click  " + ex.Message);
            }
        }