ERT-781 Faster implementation of CSV_EXPORT

The MSVC compiler chokes on this, the `int i` must be declared outside the loop.