title: How to Export an Excel file (.xlsx) format using SQL Server
body: <p>Actually i looking to export an excel(.xlsx) file format. Below is my query which is used to send .csv file format using <strong>sp_send_dbmail</strong></p>
  
  <pre><code> EXEC msdb.dbo.sp_send_dbmail
  @profile_name = 'eMail Notification',
  @recipients = 'abc@gmail.com',  
  @query = 'use [dbname] select im.FullName as EmployeeName, im.MemberIC as NRIC 
           from tblIndividualMst im           
           where im.RecStatus = ''A''
           and (im.DateOfResign &gt;= getdate() or im.DateOfResign is null)' ,
  @subject = 'Test',
  @attach_query_result_as_file = 1 ,
  @query_attachment_filename = 'test.csv',
  @query_result_separator=',',@query_result_width =32767,
  @query_result_no_padding=1;
  </code></pre>
  
  <p>So while i tried to modifiy the file format from "test.csv" to "test.xlsx", all the data's messing up in test.xlsx. So how can i modify my query to get correct .xlsx file format.</p>
  
  <p>Any help appreciated. Thanks!!! </p>