I'm exporting a datagrid data to Excel and the exporting function worked fine until I fixed the header row, now an error appears in the export function in this line:
sAux = stringWrite.ToString().Substring(0, stringWrite.ToString().IndexOf("<tr"));
It seems stringWrite is empty and so a warning message appears:
System.ArgumentOutOfRangeException: Length can't be less than zero.
This means that
IndexOf()
returned -1. IOW, it didn't find<tr
. You can't take aSubString(0, -1)
.Declare a variable, and assign the result of
IndexOf()
to that variable, and make sure the substring you want was found: