Skip to content

Commit

Permalink
WriteEmptyStringAsNull implementation (#725)
Browse files Browse the repository at this point in the history
Co-authored-by: Ivan Jiang <[email protected]>
  • Loading branch information
jiangyi1985 and Ivan Jiang authored Feb 12, 2025
1 parent 8136154 commit d845ee4
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/MiniExcel/OpenXml/ExcelOpenXmlSheetWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ private void WriteCell(MiniExcelStreamWriter writer, int rowIndex, int cellIndex
}

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

Check warning on line 341 in src/MiniExcel/OpenXml/ExcelOpenXmlSheetWriter.cs

View workflow job for this annotation

GitHub Actions / build

Possible unintended reference comparison; to get a value comparison, cast the left hand side to type 'string'

Check warning on line 341 in src/MiniExcel/OpenXml/ExcelOpenXmlSheetWriter.cs

View workflow job for this annotation

GitHub Actions / build

Possible unintended reference comparison; to get a value comparison, cast the left hand side to type 'string'

Check warning on line 341 in src/MiniExcel/OpenXml/ExcelOpenXmlSheetWriter.cs

View workflow job for this annotation

GitHub Actions / build

Possible unintended reference comparison; to get a value comparison, cast the left hand side to type 'string'

if (_configuration.EnableWriteNullValueCell && valueIsNull)
{
Expand Down
1 change: 1 addition & 0 deletions src/MiniExcel/OpenXml/OpenXmlConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class OpenXmlConfiguration : Configuration
public bool EnableConvertByteArray { get; set; } = true;
public bool IgnoreTemplateParameterMissing { get; set; } = true;
public bool EnableWriteNullValueCell { get; set; } = true;
public bool WriteEmptyStringAsNull { get; set; } = false;
public bool EnableSharedStringCache { get; set; } = true;
public long SharedStringCacheSize { get; set; } = 5 * 1024 * 1024;
public DynamicExcelSheet[] DynamicSheets { get; set; }
Expand Down

0 comments on commit d845ee4

Please sign in to comment.