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...
Unanswered

Export an Excel file that contains a certain layout and design

(1) ShareShare
ReportReport
Posted on by 95

Hello,

I am exporting an Excel to make a price comparison of certain offers and I have encountered two problems:

1) Creating the Excel from the beginning using the Excel Buffer table, it is not possible to format the cells (except bold, italic and underlined).

2) Seeing that problem 1 seems complex, I have created a template on the server that has a default layout associated with it. Well, I use the Excel Buffer table to fill in the data but the format of the cells that are written is lost... and that's where I need help. Do you know how I can solve this problem? I show you two images of a small simplified test so you can see what happens as well as the associated code:

1881.Before.PNG        4061.After.PNG

codeunit 50013 "Files Mgt2"
{
    trigger OnRun()
    begin

    end;

    procedure ExportQuotesToExcel(var Quote: Record "Purchase Header")
    var
        TempExcelBuf: Record "Excel Buffer" temporary;
    begin
        InitExcel(TempExcelBuf);
        FillExcelBuffer(TempExcelBuf, Quote);
        TempExcelBuf.CloseBook();
        TempExcelBuf.SetFriendlyFilename('test');
        TempExcelBuf.OpenExcel();
    end;

    local procedure InitExcel(var TempExcelBuf: Record "Excel Buffer" temporary)
    var
        InStr: InStream;
        Files: File;
    begin
        Files.Open('C:\Users\Public\Comparador ofertas compra.xlsx');
        Files.CreateInStream(InStr);

        TempExcelBuf.UpdateBookStream(InStr, 'Precios', false);
    end;

    local procedure FillExcelBuffer(var TempExcelBuf: Record "Excel Buffer" temporary; var Quote: Record "Purchase Header")
    var
        TempExcelBufSheet: Record "Excel Buffer" temporary;
    begin
        TempExcelBufSheet.EnterCell(TempExcelBufSheet, 2, 1, 'test', true, false, false);
        TempExcelBuf.WriteAllToCurrentSheet(TempExcelBufSheet);
    end;


}


The version of BC we use is 16.1 (we know that there are new Excel features currently available, but we are not migrating for now).

Thank you so much.

I have the same question (0)
  • Nitin Verma Profile Picture
    21,788 Moderator on at

    Hi,

    You can refer the standard report to get help, and check how this report is exporting data into excel.

    report 29 "Export Acc. Sched. to Excel"

  • MiguelRospa Profile Picture
    95 on at

    Thank you very much for your interest! Unfortunately, my problem has not been resolved, since the report you indicate also deletes the design that I have set (it loses the background color, which is what interests me). You can see it in the image:

    pastedimage1677144073593v1.png

    pastedimage1677144123939v2.png

    Actually the report ends up using the same code as the EnterCell function of the Excel Buffer table. I hope someone can help me because the problem does not look good...

  • Amit Profile Picture
    2,561 on at

    Hi,

    Refer the below link for information

    https://erpconsultors.com/export-to-excel-report-in-business-central/

    Regards

    Amit Sharma

    www.erpconsultors.com

    linkedin.com/in/amit-sharma-94542440/

    Press Yes if info is useful

  • MiguelRospa Profile Picture
    95 on at

    Hi, thanks for answering, but the code that appears on that page is related to problem number 1 that I put in the post, which can only be put in bold, italics and underlined. If the cell could be colored, it would be worth it as a solution, but I think it is not possible. As a result I am looking for the solution to alternative number 2, which would be to use a design established in a template, but the problem is that the format of the cells is lost when writing over them.

  • Inge M. Bruvik Profile Picture
    1,161 Moderator on at

    Why cant you create a report that you define a Excel layout for?

    Then the report gives you all the raw data in Excel you can do the formatting and upload that layout so it can be reused when you run the same report again?

    learn.microsoft.com/.../ui-excel-report-layouts

  • Steven Renders Profile Picture
    5,682 Moderator on at

    I don't recommend to use the Excel Buffer, it seems way to complex to achieve a simple Excel layout.

    Instead create a report, with a normal dataset and then add an Excel layout to it.

    Here are some examples/tutorials:

    thinkaboutit.be/.../

    thinkaboutit.be/.../

  • MiguelRospa Profile Picture
    95 on at

    Thank you very much for answering Inge. In the version we are using (16.1) the options described in the link you have provided me do not appear. For example, I can't choose the "Send to > Microsoft Excel Document (data only)" option in the task 1 steps and I can't "Set Format Options to Excel" during the task 2 steps either.

  • MiguelRospa Profile Picture
    95 on at

    Thank you very much for answering Steven but I will answer the same as Inge, our version is 16.1 and in that version the features that you expose in the links are not available. Actually using Excel Buffer is not complicated, what is incredible is that it only allows you to format cells in bold, italics and underlined. And the other option that I explained at the beginning of the post does not work either because in addition to not being able to format with Excel Buffer, the format of the cells that are written from a template hosted on the server is changed.

    It does not seem that this has a solution without migrating from version...

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!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 1,960 Super User 2026 Season 1

#2
YUN ZHU Profile Picture

YUN ZHU 1,084 Super User 2026 Season 1

#3
Dhiren Nagar Profile Picture

Dhiren Nagar 1,047 Super User 2026 Season 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans