function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Rajesh SFDCRajesh SFDC 

how to get visualfoce page as excel format to mail attachment in apex

here my code given below:
public Class GenerateCSV 
{
   public PageReference SendEmail() 
      {
            Messaging.EmailFileAttachment attachment = new Messaging.EmailFileAttachment();
            attachment.setFileName('Report.pdf');
             PageReference csvPage = Page.GenerateCSV;  
            Blob csvBlob = csvPage.getContent();
            attachment.setBody(csvBlob);
            //attachment.setContentType('pdf');
            attachment.setContentType('application/vnd.ms-excel');
            Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage();
            message.setFileAttachments(new Messaging.EmailFileAttachment[] { attachment } );
            message.setSubject('Report');
            message.setPlainTextBody('The report is attached.');
            message.setToAddresses( new String[] { 'rajesh87sfdc@gmail.com' } );
            Messaging.sendEmail( new Messaging.SingleEmailMessage[] { message } );
            Return null;
            
         }
}

here i am getting only blank excel in mails