Skip to content

Commit

Permalink
perf csv insert (#653)
Browse files Browse the repository at this point in the history
  • Loading branch information
izanhzh authored Aug 16, 2024
1 parent b20ed40 commit 6d81ddc
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/MiniExcel/MiniExcel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,17 @@ public static MiniExcelDataReader GetReader(this Stream stream, bool useHeaderRo
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);
}

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;
{
Expand All @@ -43,6 +46,8 @@ public static void Insert(this Stream stream, object value, string sheetName = "
else
v = value;
}

stream.Seek(0, SeekOrigin.End);
ExcelWriterFactory.GetProvider(stream, v, sheetName, excelType, configuration, false).Insert();
}

Expand Down

0 comments on commit 6d81ddc

Please sign in to comment.