Fix write sql to excel with matrix