/// <summary>
/// 实例化Workbook
/// </summary>
/// <param name="extensionName">扩展名</param>
/// <returns></returns>
public static IWorkbook InstanceWorkbook(string extensionName)
{
IWorkbook workbook;
switch (extensionName)
{
case ".xlsx":
workbook = new NPOI.XSSF.UserModel.XSSFWorkbook();
break;
case ".xls":
workbook = new NPOI.HSSF.UserModel.HSSFWorkbook();
break;
default:
workbook = new NPOI.XSSF.UserModel.XSSFWorkbook();
break;
}
return workbook;
}
/// <summary>
/// Txt转电子表格
/// </summary>
/// <param name="conut"></param>
/// <param name="tuple">Item1:文件路径;Item2:保存文件名</param>
/// <param name="extensionName">保存扩展名</param>
/// <returns></returns>
public static IWorkbook TxtToWorkbook(out int conut, Tuple<string, string> tuple, string extensionName = ".xlsx")
{
var asynccount = 0;
var workbook = InstanceWorkbook(extensionName);
conut = 0;
try
{
var encoding = Encoding.GetEncoding("GB2312");
var sheet =
TXT文件转DataTable和Workbook
最新推荐文章于 2024-02-26 10:04:46 发布
本文详细介绍了如何使用C#编程语言将TXT文件高效地转换成DataTable数据结构,以及进一步将DataTable导出为Workbook格式,涵盖了文件读取、数据解析和Excel操作的关键步骤。
摘要由CSDN通过智能技术生成