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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Answered

InStream from an Excel generated with Excel Buffer

(2) ShareShare
ReportReport
Posted on by 137
Hi everyone,
 
I am working in a Business Central SaaS environment and I am generating an Excel file using the standard temporary record “Excel Buffer” to build the content entirely in memory. The Excel creation works correctly and the file is generated as expected. However, after generating it, I need to send or attach this Excel file, which means I need to obtain an InStream for the generated content, for example to attach it to an EmailMessage.
 
The issue I am facing is that I have not found any direct way to obtain an InStream from the Excel that is produced by the Excel Buffer in this SaaS scenario. At the moment, the only approach I have found is to export the Excel to a physical file and then import that file again in order to get the InStream, but this seems inefficient.
 
My question is: is there any way to directly convert or access the Excel generated by the Excel Buffer as an InStream, without having to export and re-import the file? I would be very interested in any patterns, built-in capabilities, or best practices that you might be using in a Business Central SaaS environment to handle this scenario cleanly.
 
Thank you in advance for any guidance or suggestions you can share.
 
Best regards.
I have the same question (0)
  • Suggested answer
    AH-22121126-0 Profile Picture
    42 on at
    You can use the codeunit "Temp Blob" and create both an InStream and OutStream from it. Then write to the OutStream with "Excel Buffer", and attach the InStream. Something like this:
     
        local procedure Example()
        var
            ExcelBuffer: Record "Excel Buffer";
            TempBlob: Codeunit "Temp Blob";
            OutStream: OutStream;
            InStream: InStream;
        begin
            TempBlob.CreateOutStream(OutStream);
            TempBlob.CreateInStream(InStream);
     
            // Populate ExcelBuffer with data
     
            ExcelBuffer.SaveToStream(OutStream, false);
     
            // Use InStream to attach to email
        end;
  • Suggested answer
    YUN ZHU Profile Picture
    99,360 Super User 2026 Season 1 on at
    Hi, Try the SaveToStream method in table 370 "Excel Buffer".
     
    Thanks
    ZHU
  • Suggested answer
    OussamaSabbouh Profile Picture
    13,323 Super User 2026 Season 1 on at
    Hello,
    In Business Central SaaS, you don’t need to export and re-import the Excel file to get an InStream. After generating the workbook with Excel Buffer, you can call SaveToStream to write the Excel content directly into an OutStream (typically backed by Temp Blob), then create an InStream from that Temp Blob and pass it to things like EmailMessage.AddAttachment. In short: Excel Buffer → SaveToStream → Temp Blob OutStream → Temp Blob InStream → attach/send, which keeps everything in memory and avoids filesystem workarounds. Microsoft documentation explicitly shows SaveToStream for streaming Excel output to further AL processing, and streams with Temp Blob are the standard SaaS pattern for handling files in memory.
     
    Regards,
    Oussama Sabbouh
  • Verified answer
    PL-28101044-0 Profile Picture
    137 on at
    Hi,
     
    Thank you all very much for your help. The suggestions you shared worked perfectly in my Business Central SaaS environment, and I really appreciate the time you took to respond.

    I am leaving below the example I built based on your guidance, in case it can help someone else facing the same situation. Hopefully it will be useful to others as well.
     

    Thanks again for your support!

    Best regards

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 1,717 Super User 2026 Season 1

#2
YUN ZHU Profile Picture

YUN ZHU 995 Super User 2026 Season 1

#3
Khushbu Rajvi. Profile Picture

Khushbu Rajvi. 628 Super User 2026 Season 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans