Export very big data set stops at 65535 rows


I exported a grid with 70k+ rows (16.1 MB file) and a grid with 90k+ rows (21.7 MB file). File was successfully exported. But when I tried to open them pops up Microsoft Security Alert - Office File Validation (as the screen shot attached)
After clicking OK on this alert, another warning pops up saying "File Error: data may have been lost".
After dismiss this pop up, file opens. Both file contain only 65535 records.
Since relative source code defines some variable as ushort, I guess that is the source of the error.

file attachments