Skip to content

ToDataTable throwing exception #1163

@grosch-intl

Description

@grosch-intl

I need to compare two spreadsheets in separate workbooks. The columns are in different orders though, so I thought I'd create a data table for each and then compare based on column header name. I tried the below code, but it's throwing an InvalidOperationException saying "Value cannot be null, row: 8, col: 56"

That cell is in fact blank, which is perfectly fine. It's also not the first cell on that line that is blank, so I'm not sure why it is bailing.

public DataTable Get(string path) {
	using var package = new ExcelPackage(new FileInfo(@"....xlsx"));
	var ws = package.Workbook.Worksheets[0];
	var table = ws.Tables[0];

	var opt = ToDataTableOptions.Create(x => {
		x.ExcelErrorParsingStrategy = ExcelErrorParsingStrategy.HandleExcelErrorsAsBlankCells;
		x.FirstRowIsColumnNames = true;
	});
	
	return table.ToDataTable(opt);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions