问题描述
我正在为Business Central创建一个报告,一个采购订单报告。扩展了“采购订单”页面,以添加工作描述,这是一个Blob数据类型。我已经将blob字段添加到了我的报表扩展程序中,现在我像将其在页面中看到的那样,将Blob转换为Text。示例:“这是测试工作说明”。我相信我必须先使用InStream,然后再阅读。有人可以提供示例代码来帮助我将其作为文本添加到我的报告中吗?
解决方法
您可以在Microsoft文档上找到很好的示例: Write,WriteText,Read,and ReadText Method Behavior for Line Endings and Zero Terminators
但是我认为这是您所需要的:
procedure GetWorkDescription (PurchHeader: Record "Purchase Header")WorkDescription: Text
var
MyInStream: InStream;
begin
Clear(WorkDescription);
PurchHeader.Calcfields("Work Description");
If PurchHeader."Work Description".HasValue() then begin
PurchHeader."Work Description".CreateInStream(MyInStream);
MyInStream.Read(WorkDescription);
end;
end;
,
这个例子非常好用!我只是想添加到它。在我的Purchase标头中,添加了以下代码:
column(WorkDescription; GetWorkDescription())
{
}
然后在末尾添加的OnPreReport()中:
WorkDescription: Text;
然后在最后添加了过程:
procedure GetWorkDescription(): Text
var
TypeHelper: Codeunit "Type Helper";
InStream: InStream;
begin
"Purchase Header".CalcFields("Purchase Header"."Work Description");
"Purchase Header".Work Description".CreateInStream(InStream,TEXTENCODING::UTF8);
exit(TypeHelper.ReadAsTextWithSeparator(InStream,TypeHelper.LFSeparator));
end;
借助您的示例代码,我能够生成实际的文本!