FastExcel 是PCHMI内置的Excel快速写入工具。
核心特点:内存缓冲、延迟合并保存、原子写入防文件损坏、断电自动恢复临时文件、文件占用自动重试。
适合PLC上位机高频日志、生产记录持续追加写入Excel场景。
保存与资源释放由PCHMI内部自动完成,业务代码无需手动调用任何保存相关方法。
@"D:\DB\MYEXCEL.xlsx";文件夹不存在组件会自动创建。"Sheet1",不存在会自动新建工作表。| 方法名称 | 作用说明 |
|---|---|
| FastExcel.Insert(单行) | 追加写入一行数据,写入内存,内部自动定时存盘 |
| FastExcel.Insert(批量多行) | 一次性追加写入多行数据 |
FastExcel.Insert(@"D:\DB\MYEXCEL.xlsx", "Sheet1", new string[] { "A", "B", "C" }, new string[] { "1", "2", "3" });
string[] header = new string[] { "时间", "工位号", "状态", "产量" };
FastExcel.Insert(@"D:\DB\生产日志.xlsx", "生产记录", header, new string[] { DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), "01", "运行", "100" });
using System.Collections.Generic;
string[] header = new string[] { "编号", "名称", "数值" };
List<string[]> rowList = new List<string[]>(){new string[]{"1","产品A","120"},new string[]{"2","产品B","230"},new string[]{"3","产品C","450"}};
FastExcel.Insert(@"D:\DB\批量数据.xlsx", "Sheet1", header, rowList);