Create a loop inside the excel application scope and break the data in chunks of 20000 and use append range
to get data in chunks of 20000 use dt.AsEnumerable.Skip(Cint(20000*counter)).Take(20000)
Create a counter variable and assign it to the index variable in for loop… in the for loop in Argument use Enumerable.Range(0,Cint(Dt.Rowcount/20000)+1).ToArray
use append range with the above given chunks formula
I tried with the 98147 rows of data but it is copying only 20,000 rows and the remaining data is not copied into respective Sheet, I followed the same code as you shared.
I did as it is what you shared in the code, in the for if condition,
In then section I have given write range and for else I am using the append range,
I just change the data table name of your code Anil.