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;
}
}
}
}