Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/ExcelDataReader.Tests/ExcelCsvReaderTest.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Data;
using System.Text;

namespace ExcelDataReader.Tests;
Expand Down Expand Up @@ -594,4 +595,20 @@ public void Issue614_BackslashEscapedQuote()

Assert.That(row, Is.EqualTo(new object[] { "John", "Doe", "120 any st.", "\"Anytown\", WW", "08123" }));
}

[Test]
public void FillMergedCellsValueDoesNotCrashOnCsv()
{
using var excelReader = ExcelReaderFactory.CreateCsvReader(Configuration.GetTestWorkbook(Path.Combine("csv", "comma_in_quotes.csv")));
DataSet result = excelReader.AsDataSet(new ExcelDataSetConfiguration
{
ConfigureDataTable = _ => new ExcelDataTableConfiguration
{
FillMergedCellsValue = true
}
});

Assert.That(result, Is.Not.Null);
Assert.That(result.Tables[0].Rows.Count, Is.EqualTo(2));
}
}
18 changes: 18 additions & 0 deletions src/ExcelDataReader.Tests/ExcelTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1097,6 +1097,24 @@ public void AsDataSetTestFillEmptyCellsInMergedRangeUseHeaderRow()
Assert.That(result.Tables[0].Rows[5][1], Is.EqualTo("Merge Cell 4"));
Assert.That(result.Tables[0].Rows[5][2], Is.EqualTo("Merge Cell 4"));
}

[Test]
public void AsDataSetFillMergedCellsValueWithNoMergeCells()
{
using IExcelDataReader excelReader = OpenReader("10x10");
DataSet result = excelReader.AsDataSet(new ExcelDataSetConfiguration
{
ConfigureDataTable = _ => new ExcelDataTableConfiguration
{
UseHeaderRow = true,
FillMergedCellsValue = true
}
});

Assert.That(result, Is.Not.Null);
Assert.That(result.Tables[0].Rows.Count, Is.EqualTo(9));
Assert.That(result.Tables[0].Columns.Count, Is.EqualTo(10));
}

protected IExcelDataReader OpenReader(string name)
{
Expand Down
3 changes: 1 addition & 2 deletions src/ExcelDataReader/Core/BinaryFormat/XlsWorksheet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -650,8 +650,7 @@ private void ReadWorksheetGlobals()
Workbook.AddNumberFormat(biffFormat.Key, biffFormat.Value.GetValue(Encoding));
}

if (mergeCells.Count > 0)
MergeCells = mergeCells.ToArray();
MergeCells = mergeCells.ToArray();

if (!SinglePassMode)
{
Expand Down
2 changes: 1 addition & 1 deletion src/ExcelDataReader/Core/CsvFormat/CsvWorksheet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public CsvWorksheet(Stream stream, Encoding fallbackEncoding, char[] autodetectS

public HeaderFooter HeaderFooter => null;

public CellRange[] MergeCells => null;
public CellRange[] MergeCells => [];

public int FieldCount { get; }

Expand Down
2 changes: 1 addition & 1 deletion src/ExcelDataReader/IExcelDataReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public interface IExcelDataReader : IDataReader
HeaderFooter HeaderFooter { get; }

/// <summary>
/// Gets the list of merged cell ranges.
/// Gets the list of merged cell ranges, or an empty array if there are none.
/// </summary>
CellRange[] MergeCells { get; }

Expand Down
Loading