perf csv insert (#653)

This commit is contained in:
Amos 2024-08-16 23:44:51 +08:00 committed by GitHub
parent b20ed40f81
commit 6d81ddc59f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -27,7 +27,7 @@
public static void Insert(string path, object value, string sheetName = "Sheet1", ExcelType excelType = ExcelType.UNKNOWN, IConfiguration configuration = null)
{
if (Path.GetExtension(path).ToLowerInvariant() != ".csv")
throw new NotSupportedException("MiniExcel SaveAs only support csv insert now");
throw new NotSupportedException("MiniExcel only support csv insert now");
using (var stream = new FileStream(path, FileMode.Append, FileAccess.Write, FileShare.Read, 4096, FileOptions.SequentialScan))
Insert(stream, value, sheetName, ExcelTypeHelper.GetExcelType(path, excelType), configuration);
@ -35,6 +35,9 @@
public static void Insert(this Stream stream, object value, string sheetName = "Sheet1", ExcelType excelType = ExcelType.XLSX, IConfiguration configuration = null)
{
if (excelType != ExcelType.CSV)
throw new NotSupportedException("MiniExcel only support csv insert now");
// reuse code
object v = null;
{
@ -43,6 +46,8 @@
else
v = value;
}
stream.Seek(0, SeekOrigin.End);
ExcelWriterFactory.GetProvider(stream, v, sheetName, excelType, configuration, false).Insert();
}