I have a requirement to write report the excel sheet with a style but
I am facing the error Tablename is not valid Parameter name: Name while trying to load the data table in an excel sheet using epplus with styles like below
if (_ds.Tables[i].Rows.Count > 0)
{
_resultworkSheet.Cells["A1"].LoadFromDataTable(_ds.Tables[i], true, OfficeOpenXml.Table.TableStyles.Medium9);
}
If I try to write the data table to excel sheet without table styles like below I am not facing any error
if (_ds.Tables[i].Rows.Count > 0)
{
_resultworkSheet.Cells["A1"].LoadFromDataTable(_ds.Tables[i], true);
}
I am confused what could be causing the error while trying to load the excel sheet with styles anyone please shed a light on this to clear the error
I've never used the method your using, I do it like this
SelectedTable = Worksheet.Tables.Add(Range, tableName);
SelectedTable.TableStyle = _defaultTableStyle;
So if you grab the returned data and then set the style:
var data = _resultworkSheet.Cells["A1"].LoadFromDataTable(_ds.Tables[i], true);
data.TableStyle = OfficeOpenXml.Table.TableStyles.Medium9;
It's not one liner, but if it works:D
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.