web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics NAV (Archived)

Saving as Excel File with filter

(0) ShareShare
ReportReport
Posted on by 5,136

I had this method working whereby I am sending a specific report as a PDF attachment to an email I am sending.  However, I had a request from our user that asked for Excel version instead.  So I thought it's no biggy.  Rather that sending 'SAVEASPDF', I just changed it to 'SAVEASEXCEL'.  Note that prior to sending the report as pdf/excel, I am filtering the source data (need to filter the document date).  I do this using recordref and fieldref.  Like I said, everything worked when sending report as PDF.  See below code snippet:
OpenOrderRangeFile := TempFilename + 'OrderingReport_'+FORMAT(StartDate,0,'<Month,2>_<Day,2>_<Year4>')+'_'+FORMAT(EndDate,0,'<Month,2>_<Day,2>_<Year4>')+'.xls' ;
FieldRefVar := RecRef.FIELD(99);  //Document Date
FieldRefVar.SETRANGE(StartDate,EndDate);

IF RecRef.COUNT > 0 THEN
    BEGIN
        bAttached := TRUE;
        VarRecRef := RecRef;
        //REPORT.SAVEASPDF(50097,OpenOrderRangeFile,VarRecRef);
        REPORT.SAVEASEXCEL(50097,OpenOrderTodayFile,VarRecRef);     //save as excel
        MailInt.AddAttachment(OpenOrderRangeFile);      //for attachment
    END
ELSE

Now, when I changed to SAVEASEXCEL, I get below err message:

Attachment c:\temp\OrderingReport_10_01_2014_10_14_2014.xls does not exist or can not be accessed from the program.

This is because the Excel file was not created.

Thoughts anyone?

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Suresh Kulla Profile Picture
    50,243 Super User 2025 Season 2 on at
    TempFile.TEXTMODE(FALSE);
    TempFile.WRITEMODE(TRUE);
    OpenOrderRangeFile := TempFilename + 'OrderingReport_'+FORMAT(StartDate,0,'<Month,2>_<Day,2>_<Year4>')+'_'+FORMAT(EndDate,0,'<Month,2>_<Day,2>_<Year4>')+'.xls' ;
    TempFile.CREATE(OpenOrderRangeFile);
    TempFile.CLOSE;
    


    Please create the file first using above code then execute SAVEASEXCEL.

  • mbr Profile Picture
    5,136 on at

    thank you Suresh.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics NAV (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans