Bạn có thể gởi file txt mẫu.
Dưới đây là code đọc từ file txt
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace TextToDataTable
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
DataTable table = new DataTable();
table.Columns.Add("STORE NO", typeof(string));
table.Columns.Add("SALES ORD. NO.", typeof(string));
table.Columns.Add("SELL ART. NO.", typeof(string));
table.Columns.Add("ART. DESCR.", typeof(string));
table.Columns.Add("QTY (MU)", typeof(string));
string data = File.ReadAllText("text.txt");
MatchCollection matchList = Regex.Matches(data, @"==(.+?)bccde", RegexOptions.Singleline);
var list = matchList.Cast<Match>().Select(match => match.Value).ToList();
foreach (string s in list)
{
string[] row = Regex.Split(s, @"\r\n");
row = row.Where(x => x != " ").ToArray();
string[] arr = Regex.Split(row[1], " ");
arr = arr.Where(x => x != "").ToArray();
table.Rows.Add(arr[0], arr[1], arr[2], arr[3], arr[4]);
}
dataGridView1.DataSource = table;
}
}
}