[英]How to sort in table, data from csv file to textbox?
當我從 csv 文件中讀取數據並將其寫入我的文本框時,我得到以下結果:
26/04/2021 16:08:50;4248,461;4676,146;6283,319;2136,178;8924,607;8419,497;0;1,349;0;0;1,915;0;1,819;2,386 ;236,5;229,4;237,9;8,17;6,12;7,75; 26/04/2021 16:08:51;4248,461;4676,146;6283,32;2136,178;8924,607;8419,498;0;1,374;0;0;1,912;0;1,825;2,363 ;236,6;229,3;237,9;8,16;6,23;7,77; 26/04/2021 16:08:52;4248,461;4676,146;6283,32;2136,178;8924,607;8419,498;0;1,344;0;0;1,91;0;1,812 ;2,379;236,6;229,4;238;8,15;6,1;7,72; 26/04/2021 16:08:53;4248,461;4676,146;6283,321;2136,178;8924,607;8419,499;0;1,374;0;0;1,898;0;1,808;2,332 ;236,5;229,3;237,9;8,1;6,23;7,7; 2021 年 4 月 26 日 16:08:54;4248,461;4676,146;6283,322;2136,178;8924,607;8419,5;0;1,385;0;0;1,899;0;1,813;2,327 ;236,6;229,4;238;8,1;6,27;7,72; 26/04/2021 16:08:55;4248,461;4676,146;6283,322;2136,178;8924,607;8419,5;0;1,397;0;0;1,9;0;1,774 ;2,277;236,8;229,3;238;8,1;6,32;7,56;
這不清楚和可讀
如何將這些數據放在我的 TextBox 中一個很好的排序表中?
我在 de 文本框中打印數據的代碼是:
'''private void Button_Click(object sender, RoutedEventArgs e) { string text = File.ReadAllText(@"C:\Users\DellInspirion15\OneDrive\Documenten\SavedDataDigitaleTeller.csv", Encoding.UTF8); TxtBxDataLogger.Text = 文本; }'''
我將數據放入數據表中。 數據為 21 列,第一列為日期。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.IO;
using System.Globalization;
namespace ConsoleApplication
{
public class Program
{
const string FILENAME = @"c:\temp\test.txt";
const int COLUMNS = 21;
public static void Main(string[] args)
{
string input = File.ReadAllText(FILENAME);
string[] rows = input.Split(new char[] { ';', '|'}).ToArray();
DataTable dt = new DataTable();
int rowCount = 0;
int colCount = 0;
Boolean headerRow = true;
DataRow newRow = null;
CultureInfo info = CultureInfo.GetCultureInfo("fr-BE");
foreach (string row in rows)
{
string line = row.Trim();
if (line.Length > 0)
{
colCount = rowCount % COLUMNS;
if (headerRow)
{
switch (colCount)
{
case 0:
dt.Columns.Add(line, typeof(DateTime));
break;
default:
dt.Columns.Add(line, typeof(decimal));
break;
}
if (colCount == COLUMNS - 1)
headerRow = false;
}
else
{
if (colCount == 0)
{
newRow = dt.Rows.Add();
colCount = 0;
newRow[colCount] = DateTime.Parse(line, info);
}
else
{
newRow[colCount] = decimal.Parse(line, info);
}
}
rowCount++;
}
}
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.