76 lines
2.8 KiB
C#
76 lines
2.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace PEP_Tool
|
|
{
|
|
public static class Export
|
|
{/*System.Windows.Controls.DataGrid*/
|
|
public static void ExportCSV(System.Data.DataView list)
|
|
{
|
|
var l = list.ToTable();
|
|
string[] arr = new string[l.Rows.Count];
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
MainWindow.main.BarIsIndeterminate = false;
|
|
MainWindow.main.BarVisibility = System.Windows.Visibility.Visible;
|
|
MainWindow.main.BarMax = l.Rows.Count;
|
|
|
|
sb.AppendLine($"Name;Vorname;Datum;Abteilung;Zuweisung;Bemerkung;" + Environment.NewLine);
|
|
|
|
int count = 0;
|
|
foreach (System.Data.DataRow user in l.Rows)
|
|
{
|
|
count++;
|
|
sb.AppendLine($"{user.ItemArray[1]};{user.ItemArray[2]};{user.ItemArray[4].ToString().Split(' ')[0]};{user.ItemArray[3]};{user.ItemArray[9]};{user.ItemArray[10]};");
|
|
MainWindow.main.BarValue = count;
|
|
}
|
|
|
|
//StringBuilder sb = new StringBuilder();
|
|
|
|
//IEnumerable<string> columnNames = l.Columns.Cast<System.Data.DataColumn>().
|
|
// Select(column => column.ColumnName);
|
|
//sb.AppendLine(string.Join(",", columnNames));
|
|
|
|
//foreach (System.Data.DataRow row in l.Rows)
|
|
//{
|
|
// IEnumerable<string> fields = row.ItemArray.Select(field => field.ToString());
|
|
// sb.AppendLine(string.Join(",", fields));
|
|
//}
|
|
|
|
//object[,] data = list.PrepareData();
|
|
//StringBuilder builder = new StringBuilder(Convert.ToString((char)65279));
|
|
|
|
//for (int k = 0; k < data.GetLength(0); k++)
|
|
//{
|
|
// List<string> tempList = new List<string>();
|
|
// for (int l = 0; l < data.GetLength(1); l++)
|
|
// tempList.Add(data[k, l].ToString());
|
|
// builder.Append(string.Join(",", tempList)).Append(Environment.NewLine);
|
|
//}
|
|
|
|
MainWindow.main.BarIsIndeterminate = true;
|
|
MainWindow.main.BarVisibility = System.Windows.Visibility.Collapsed;
|
|
|
|
|
|
Microsoft.Win32.SaveFileDialog dialog = new Microsoft.Win32.SaveFileDialog();
|
|
dialog.AddExtension = true;
|
|
dialog.DefaultExt = "csv";
|
|
dialog.Filter = "Excel Arbeitsblatt CSV|*.csv";
|
|
dialog.OverwritePrompt = true;
|
|
dialog.RestoreDirectory = true;
|
|
dialog.Title = "Liste exportieren";
|
|
|
|
dialog.ShowDialog();
|
|
|
|
|
|
if (dialog.FileName != "")
|
|
System.IO.File.WriteAllText(dialog.FileName, sb.ToString(), Encoding.UTF8);
|
|
}
|
|
|
|
|
|
}
|
|
}
|