MinExcel 高效的读写(大致1000M的.csv文件可以压缩为1M).csv文件利用Sunny图形化交互
项目案例1:书籍管理
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.Threading.Tasks;
using System.Windows.Forms;
using MiniExcelLibs;
using Sunny;
using Sunny.UI;
//qq2248437101
namespace CSV
{
public partial class Form1 : UIForm
{
public Form1()
{
InitializeComponent();
}
string path = @"D:\测试文档.xlsx";
private void Form1_Load(object sender, EventArgs e)
{
}
private IEnumerable<Dictionary<string,object>> GetOrders(List<Test> test)
{
foreach(var item in test)
{
var newCompanyPreapareds = new Dictionary<string, object>();
newCompanyPreapareds.Add("id", item.ID);
newCompanyPreapareds.Add("书名", item.bookName);
newCompanyPreapareds.Add("类型", item.bookTitle);
newCompanyPreapareds.Add("作者", item.bookwir);
newCompanyPreapareds.Add("日期", item.Time);
yield return newCompanyPreapareds;
}
}
private void uiButton2_Click(object sender, EventArgs e)
{
var rows = MiniExcel.Query<Test>(path).ToList();
Test test = new Test();
test.ID = 1;
test.bookName = "哈利波特";
test.bookTitle = "工科";
test.bookwir = "李华";
test.Time = "2024422";
rows.Add(test);
MiniExcel.SaveAs(@"D:\测试文档全部导出.xlsx",rows);
MiniExcel.SaveAs(@"D:\测试文档重写导出.xlsx",GetOrders(rows));
MessageBox.Show("导出成功");
}
private void uiButton1_Click(object sender, EventArgs e)
{
var rows = MiniExcel.Query<Test>(path).ToList();
uiDataGridView1.DataSource = rows;
}
private void uiDataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
}
}
public class Test
{
public int ID { get; set; }
public string bookName { get; set; }
public string bookTitle { get; set; }
public string bookwir { get; set; }
public string Time { get; set; }
}
项目案例2:性能
目前有一个 2w行数据的.csv文件 在只进行读写改查的情况下 内存占用率大大节省了 %60