• 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);//读取容器元素对象
    }

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

    传参数给如下2个方法:

    commaTextIo.inFieldDelimiter(' ');
    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([]);

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

    传参数给如下2个方法:

    commaTextIo.outRecordDelimiter(' ');
    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;
        }
  • 相关阅读:
    JavaScript学习笔记(六)----内置对象Global 和Math
    JavaScript学习笔记(五)--- String类型
    线性筛素数
    线性筛欧拉函数
    POJ 3090 Visble Lattice Points
    1091 合唱队形(最长上升子序列模板)
    P1018 乘积最大
    P1020 导弹拦截(弱数据)
    P2757 导弹的召唤(数据加强)
    P1313 计算系数
  • 原文地址:https://www.cnblogs.com/alfred-cn/p/13097583.html
Copyright © 2020-2023  润新知