Fix for #1018 "'Export To CSV' for Reports not working"

Rebased version of #1019