D365做文件导入导出CSV

1.在环境中,大家可以参考类LedgerConsolidate;

2.流文件的导入;

CommaTextStreamIo       commaTextIo;

container                           trans;

str                                      value;

commaTextIo = CommaTextStreamIo::constructForRead(File::UseFileFromURL(_filename));

 while (!commaTextIo.status())
{
       trans= commaTextIo.read();//读取行记录,用容器接收
       value = conpeek(trans,1);//读取容器元素对象
}

默认列分隔符为'\,'逗号,行分隔符为'\r\n'换行符号,如果有不通,需要特别指定。

传参数给如下2个方法:

commaTextIo.inFieldDelimiter('\r\n');
commaTextIo.inRecordDelimiter('\|');

这里的filename是指通过文件上传工具File upload control获取 到的文件名,非绝对路径地址。

对于上传控件大家可以参考官方文档:

https://docs.microsoft.com/en-us/dynamics365/fin-ops-core/dev-itpro/user-interface/file-upload-control

3.流文件导出;

commaTextIo = CommaTextStreamIo::constructForWrite();

commaTextIo.writeExp([]);

默认列分隔符为'\,'逗号,行分隔符为'\r\n'换行符号,如果有不通,需要特别指定。

传参数给如下2个方法:

commaTextIo.outRecordDelimiter('\r\n');
commaTextIo.outFieldDelimiter('\|');

4.声明流文件;

private int codepage()
 {
        #Localcodepage
        return #cp_1252;
}
public static StreamIo newFile(int _codepage, StreamType _type = StreamType::AsciiIo)
    {
        StreamIo fileIo;
        switch (_type)
        {
            case StreamType::AsciiIo:
                fileIo = TextStreamIo::constructForWrite(_codepage);
                break;
            case StreamType::CommaIo:
                fileIo = CommaTextStreamIo::constructForWrite(_codepage);
                break;
            default:
                throw error ("@SYS62665");
        }
        return fileIo;
    }
posted @ 2020-06-12 09:28  Alfred_CN  阅读(526)  评论(0编辑  收藏  举报