Narzędzia użytkownika

Narzędzia witryny


c-sharp-datagridtocsv
no way to compare when less than two revisions

Różnice

Różnice między wybraną wersją a wersją aktualną.


Poprzednia wersja
c-sharp-datagridtocsv [2018/07/16 11:47] (aktualna) – edycja zewnętrzna 127.0.0.1
Linia 1: Linia 1:
 +===== C Sharp - DataGrid to CSV =====
  
 +Klasa:
 +
 +<file>
 +using System;
 +using System.Text;
 +using System.IO;
 +using System.Windows.Forms;
 +
 +namespace adm
 +{
 +    class exportCsv
 +    {
 +        protected System.Windows.Forms.DataGridView tabela;
 +
 +        public exportCsv(System.Windows.Forms.DataGridView tabelap)
 +        {
 +            tabela = tabelap;
 +        }
 +
 +        public void exportToCSV(string plik)
 +        {
 +                string temp = "";
 +                Encoding e = Encoding.GetEncoding(1250);
 +                FileStream fs = new FileStream(plik, FileMode.Create);
 +                StreamWriter fsZapis = new StreamWriter(fs, e);
 +                for (int x = 0; x < tabela.ColumnCount; x++)
 +                    temp = temp + tabela.Columns[x].HeaderText + ";";
 +                fsZapis.WriteLine(temp);
 +                for (int y = 0; y < tabela.RowCount; y++)
 +                {
 +                    temp = "";
 +                    for (int x = 0; x < tabela.ColumnCount; x++)
 +                        temp = temp + tabela.Rows[y].Cells[x].Value.ToString() + ";";
 +                    fsZapis.WriteLine(temp);
 +                }
 +                fsZapis.Close();
 +        }
 +    }
 +}
 +</file>
 +
 +Zastosowanie:
 +
 +<file>
 +                exportCsv eksportuj = new exportCsv(tabSprzetu);
 +                saveFileDialog1.ShowDialog();
 +                eksportuj.exportToCSV(saveFileDialog1.FileName);
 +</file>
c-sharp-datagridtocsv.txt · ostatnio zmienione: 2018/07/16 11:47 przez 127.0.0.1