Posted on 01/04/2025 20:28:09
Hi there,
I am trying to accomplish the same, with the following code in a job that exports products to Excel using the ExcelProvider as the destination:
foreach (var column in _mapping.SourceTable.Columns)
{
if (row.ContainsKey(column.Name)) // It could be that the field exists in the source but is not mapped.
{
if (column.Type == typeof(string) && row[column.Name] == DBNull.Value)
{
row[column.Name] = "";
}
}
}
That works fine for string columns (which I am filtering out explicitly). However, I can't get it to work with other types like int or DateTime. When I tried to set it to an empty string, I get this: "Specified cast is not valid". I think that makes sense as at this point, the underlying type is still an int or DateTime.
In the ExcelDestinationWriter I see this:
if (row[columnMapping.SourceColumn.Name] == DBNull.Value)
{
r[columnMapping.DestinationColumn.Name] = "NULL";
}
So when the underlying value is DBNull, the value is set to a string with the text NULL. Would it be an option to move the NULL string into a setting on the Excel provider (defaulting to NULL) so I can set it to an empty string in the settings? That way, I can remove my table script and handle this automatically, for all types, and not just strings and for all jobs in the future?
Please?
Imar