Beispiel #1
0
        /// <summary>
        /// 初始化读取流
        /// </summary>
        /// <param name="stream">要读取的流</param>
        /// <param name="dataEncoding">字符编码</param>
        /// <param name="flag">csv 字段分隔符与限定符</param>
        /// <param name="firstRowIsHead">是否将第一行数据做为标题行</param>
        /// <param name="readStreamBufferLength">流读取缓冲大小, 默认为 40960 字节.</param>
        public CsvReadHelper(Stream stream, Encoding dataEncoding, CsvFlag flag, bool firstRowIsHead = true, int readStreamBufferLength = 40960)
        {
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }

            if (dataEncoding == null)
            {
                throw new ArgumentNullException("dataEncoding");
            }

            if (flag == null)
            {
                throw new ArgumentNullException("flag");
            }

            this.CanRead                = true;
            this.ColumnCount            = 0;
            this.TotalRowCount          = 0L;
            this.DataEncoding           = dataEncoding;
            this.Flag                   = flag;
            this.FirstRowIsHead         = firstRowIsHead;
            this.ReadStreamBufferLength = readStreamBufferLength;
            this.CsvStream              = new StreamReader(stream, this.DataEncoding, false, this.ReadStreamBufferLength);
        }
Beispiel #2
0
        /// <summary>
        /// 初始化写入流
        /// </summary>
        /// <param name="stream">要写入的流</param>
        /// <param name="dataEncoding">字符编码</param>
        /// <param name="flag">csv 字段分隔符与限定符</param>
        /// <param name="cancelToken">取消操作的token</param>
        /// <param name="progress">通知事件参数, 每次通返回自上次通知以来写入的行数. 默认为 null, 表示不通知.</param>
        /// <param name="writeProgressSize">当写入多少条数据时应触发进度通知事件, 默认为 1000, 此值应大于 0.</param>
        public CsvWriteHelper(Stream stream, Encoding dataEncoding, CsvFlag flag
                              , CancellationToken cancelToken, IProgress <CsvWriteProgressInfo> progress = null, int writeProgressSize = 1000)
        {
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }

            if (dataEncoding == null)
            {
                throw new ArgumentNullException("dataEncoding");
            }

            if (flag == null)
            {
                throw new ArgumentNullException("flag");
            }

            if (progress != null)
            {
                if (writeProgressSize <= 0)
                {
                    throw new ArgumentException("The property 'writeProgressSize' must be greater than 0");
                }
            }

            this.ColumnCount       = 0;
            this.TotalRowCount     = 0L;
            this.DataEncoding      = dataEncoding;
            this.Flag              = flag;
            this.CancelToken       = cancelToken;
            this.Progress          = progress;
            this.WriteProgressSize = writeProgressSize;
            this.CsvStream         = new StreamWriter(stream, this.DataEncoding);
        }
Beispiel #3
0
 /// <summary>
 /// 使用 Encoding.UTF8 编码初始化读取文件
 /// </summary>
 /// <param name="csvFileName">要读取的文件路径及名称</param>
 /// <param name="flag">csv 字段分隔符与限定符</param>
 /// <param name="firstRowIsHead">是否将第一行数据做为标题行</param>
 /// <param name="readStreamBufferLength">流读取缓冲大小, 默认为 40960 字节.</param>
 public CsvReadHelper(string csvFileName, CsvFlag flag, bool firstRowIsHead = true, int readStreamBufferLength = 40960)
     : this(csvFileName, Encoding.UTF8, flag, firstRowIsHead, readStreamBufferLength)
 {
 }
Beispiel #4
0
 /// <summary>
 /// 初始化读取文件
 /// </summary>
 /// <param name="csvFileName">要读取的文件路径及名称</param>
 /// <param name="dataEncoding">字符编码</param>
 /// <param name="flag">csv 字段分隔符与限定符</param>
 /// <param name="firstRowIsHead">是否将第一行数据做为标题行</param>
 /// <param name="readStreamBufferLength">流读取缓冲大小, 默认为 40960 字节.</param>
 public CsvReadHelper(string csvFileName, Encoding dataEncoding, CsvFlag flag, bool firstRowIsHead = true, int readStreamBufferLength = 40960)
     : this(File.Open(csvFileName, FileMode.Open), dataEncoding, flag, firstRowIsHead, readStreamBufferLength)
 {
 }
Beispiel #5
0
 /// <summary>
 /// 使用 Encoding.UTF8 编码初始化写入文件
 /// </summary>
 /// <param name="csvFileName">csv 文件路径及名称</param>
 /// <param name="flag">csv 字段分隔符与限定符</param>
 /// <param name="cancelToken">取消操作的token</param>
 /// <param name="progress">通知事件参数, 每次通返回自上次通知以来写入的行数. 默认为 null, 表示不通知.</param>
 /// <param name="writeProgressSize">当写入多少条数据时应触发进度通知事件, 默认为 1000, 此值应大于 0.</param>
 public CsvWriteHelper(string csvFileName, CsvFlag flag, CancellationToken cancelToken, IProgress <CsvWriteProgressInfo> progress = null, int writeProgressSize = 1000)
     : this(csvFileName, Encoding.UTF8, flag, cancelToken, progress, writeProgressSize)
 {
 }
Beispiel #6
0
 /// <summary>
 /// 初始化写入文件
 /// </summary>
 /// <param name="csvFileName">csv 文件路径及名称</param>
 /// <param name="dataEncoding">字符编码</param>
 /// <param name="flag">csv 字段分隔符与限定符</param>
 /// <param name="cancelToken">取消操作的token</param>
 /// <param name="progress">通知事件参数, 每次通返回自上次通知以来写入的行数. 默认为 null, 表示不通知.</param>
 /// <param name="writeProgressSize">当写入多少条数据时应触发进度通知事件, 默认为 1000, 此值应大于 0.</param>
 public CsvWriteHelper(string csvFileName, Encoding dataEncoding, CsvFlag flag
                       , CancellationToken cancelToken, IProgress <CsvWriteProgressInfo> progress = null, int writeProgressSize = 1000)
     : this(File.Open(csvFileName, FileMode.Create), dataEncoding, flag, cancelToken, progress, writeProgressSize)
 {
 }