Skip to content

Commit d845ee4

Browse files
jiangyi1985Ivan Jiang
andauthored
WriteEmptyStringAsNull implementation (#725)
Co-authored-by: Ivan Jiang <[email protected]>
1 parent 8136154 commit d845ee4

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

src/MiniExcel/OpenXml/ExcelOpenXmlSheetWriter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ private void WriteCell(MiniExcelStreamWriter writer, int rowIndex, int cellIndex
338338
}
339339

340340
var columnReference = ExcelOpenXmlUtils.ConvertXyToCell(cellIndex, rowIndex);
341-
var valueIsNull = value is null || value is DBNull;
341+
var valueIsNull = value is null || value is DBNull || (_configuration.WriteEmptyStringAsNull && value is String && value == string.Empty);
342342

343343
if (_configuration.EnableWriteNullValueCell && valueIsNull)
344344
{

src/MiniExcel/OpenXml/OpenXmlConfiguration.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public class OpenXmlConfiguration : Configuration
1313
public bool EnableConvertByteArray { get; set; } = true;
1414
public bool IgnoreTemplateParameterMissing { get; set; } = true;
1515
public bool EnableWriteNullValueCell { get; set; } = true;
16+
public bool WriteEmptyStringAsNull { get; set; } = false;
1617
public bool EnableSharedStringCache { get; set; } = true;
1718
public long SharedStringCacheSize { get; set; } = 5 * 1024 * 1024;
1819
public DynamicExcelSheet[] DynamicSheets { get; set; }

0 commit comments

Comments
 (0)