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 :
Small and medium business | Business Central, N...
Answered

Danish letters in text file made by Business Central cloud

(0) ShareShare
ReportReport
Posted on by 555

Hi experts,

I have made an extension for Business Central cloud.

I use the record "CSV Buffer" (temporary) to hold the data, I want to export in a csv file. I write this:

TempCSVBuffer.InsertEntry(LineNo, 1'Header for column 1');

TempCSVBuffer.InsertEntry(LineNo, 2'Header for column 2');
...
    trigger OnPostReport()
    var
        IStream: InStream;
        Filename: Text;
    begin
        if LineNo > 1 then begin
            TempCSVBuffer.SaveDataToBlob(TempBlob, ';');

            TempBlob.CreateInStream(IStream, TEXTENCODING::Windows);
            Filename := 'The file.csv';
            DownloadFromStream(IStream, '''''', Filename);

            //FileManagement.BLOBExportWithEncoding(TempBlob, 'The file.csv', true, TextEncoding::Windows);
        end
        else begin
            Error('...');
        end;
    end;
My language in Business Central and in Windows is Danish.
When I open the file in Notepad and select "Save as", I can see that it is made as an UTF-8 file. The Danish letters looks fine in Notepad.
When I (and our customer) open the file by clicking on it, it starts Excel (without the open/import wizard) and the Danish letters are wrong. For instance 'ø' is changed to 'ø'.
My Excel is set up to use the language Windows uses and in Excel I can see that it is Danish.
What can I do to fix this?
I have the same question (0)
  • Lars Lohndorf-Larsen Profile Picture
    on at

    Hi Morten,

    Maybe this has some good insight (have not watched it myself yet):

    www.hougaard.com/.../

    if not, then if it looks OK in Notepad, what if you manually create a notepad file with æøå, does this also get scrambled in Excel?

    And are you able to experiment with the TextEncoding in your code - I don't know if it is mandatory (or try to not specify it), or if you try with any other values, but this is also a guess from my side. If nothing works, can you attach a .csv file here with a "bad" character?

  • Morten Steengaard Profile Picture
    555 on at

    Hi Lars,

    Thanks for your reply!

    Great video, but off topic.

    When I manually create a new notepad file with æøå, it is saved as UTF-8 and it gets scrambled in Excel. If I manually save it as ANSI using notepad, it looks fine in Excel. How can it be that my default encoding on this Windows 10 is UTF-8? I thought it should be ANSI.

    In my AL-code, I can set the encoding or let the system decide it. I think I have tried everything and as you can see from my code, I try to save it with "Windows" encoding. (That is the same as ANSI.)

  • Lars Lohndorf-Larsen Profile Picture
    on at

    Hi Morten,

    Would you have a small page or something to repro this here?

  • Morten Steengaard Profile Picture
    555 on at

    This page extension makes a quick file. If I in CreateInStream set it to Dos, Windows or UTF-8, the file is always saved as UTF-8 which is the default for Windows 10 in Denmark. But Excel cannot read the csv file(s).

    pageextension 50126 PostedSalesInvoices extends "Posted Sales Invoices"

    {

       layout

       {

       }

       actions

       {

           addafter(AttachAsPDF)

           {

               action("MyAction")

               {

                   ApplicationArea = All;

                   Caption = 'Make file';

                   ToolTip = 'Make file';

                   Image = Statistics;

                   Promoted = true;

                   PromotedCategory = Category7;   // "Udskriv/Send"

                   trigger OnAction()

                   var

                       TempCSVBuffer: Record "CSV Buffer" temporary;

                       Customer: Record Customer;

                       TempBlob: Codeunit "Temp Blob";

                       FileManagement: Codeunit "File Management";

                       LineNo: Integer;

                       MyFileName: Text;

                       IStream: InStream;

                   begin

                       LineNo := 1;

                       TempCSVBuffer.InsertEntry(LineNo, 1, 'æ Customer No.');

                       TempCSVBuffer.InsertEntry(LineNo, 2, 'ø Customer Name');

                       TempCSVBuffer.InsertEntry(LineNo, 3, 'Ã¥ Customer Address');

                       if Customer.FindSet() then begin

                           repeat

                               LineNo += 1;                

                               TempCSVBuffer.InsertEntry(LineNo, 1, Customer."No.");

                               TempCSVBuffer.InsertEntry(LineNo, 2, Customer.Name);

                               TempCSVBuffer.InsertEntry(LineNo, 3, Customer.Address);

                           until Customer.Next() = 0;

                       end;

                       TempCSVBuffer.SaveDataToBlob(TempBlob, ';');

                       TempBlob.CreateInStream(IStream, TEXTENCODING::MSDos);

                       MyFileName := 'My file dos.txt';

                       DownloadFromStream(IStream, '', '', '', MyFileName);

                       //FileManagement.BLOBExport(TempBlob, 'My file blank.csv', true);

                       //FileManagement.BLOBExportWithEncoding(TempBlob, 'My file windows.csv', true, TextEncoding::Windows);

                       //FileManagement.BLOBExportWithEncoding(TempBlob, 'My file UTF-8.csv', true, TextEncoding::UTF8);

                       //FileManagement.BLOBExportWithEncoding(TempBlob, 'My file DOS.csv', true, TextEncoding::MSDos);

                   end;

               }

           }

       }

    }

  • Suggested answer
    Bilal Haider Profile Picture
    414 on at

    I am having the same issue today and have posted in community as well. The only difference from your issue is that I am getting data from a text file and putting it to tempblob and then using stream.

    I have solved this issue by getting the file in UTF format, rather than in ANSI. Its not the best way but it solved the issue.

  • Verified answer
    Morten Steengaard Profile Picture
    555 on at

    Hi Bilal,

    Thanks for your input.

    I "solved" this by making a xlsx file instead of a csv file, when I export from Business Central.

    Best regards,

    Morten

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 > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,468

#2
YUN ZHU Profile Picture

YUN ZHU 923 Super User 2025 Season 2

#3
Sumit Singh Profile Picture

Sumit Singh 607

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans