コード例 #1
0
        public void CreateFile(string fileName,
                               CSVFormat format    = null,
                               bool bHasHeaderLine = false)
        {
            List <CSVFormat> formats = new List <CSVFormat>();

            formats.Add(format);

            CreateFile(fileName, formats, bHasHeaderLine);
        }
コード例 #2
0
        public void SetFormat(int index,
                              CSVFormat format,
                              bool bHasHeaderLine = false)
        {
            while (Formats.Count() < index + 1)
            {
                Formats.Add(new CSVFormat());
            }

            Formats[index] = format;
        }
コード例 #3
0
        public void WriteLine(Dictionary <string, string> fieldValues)
        {
            if (_currentFormat >= 0)
            {
                CSVFormat format = Formats[_currentFormat];

                string recordLine = "";
                for (int i = 0; i < format.Fields.Count(); i++)
                {
                    if (i != 0)
                    {
                        recordLine += format.DataFieldSeparator;
                    }

                    CSVField field = format.Fields[i];

                    string fieldValue = fieldValues[field.FieldName];
                    string delim      = "";

                    switch (format.DataFieldDelimiterUsage)
                    {
                    case CSVDelimiterUsage.All:
                        delim = format.DataFieldDelimiter;
                        break;

                    case CSVDelimiterUsage.StringsOnly:
                        if (field.FieldType == CSVFieldType.String)
                        {
                            delim = format.DataFieldDelimiter;
                        }
                        break;

                    case CSVDelimiterUsage.StringsAndDates:
                        if (field.FieldType == CSVFieldType.String ||
                            field.FieldType == CSVFieldType.DateTime)
                        {
                            delim = format.DataFieldDelimiter;
                        }
                        break;
                    }
                    recordLine += delim + fieldValues[format.Fields[i].FieldName] + delim;
                }
                sw.WriteLine(recordLine);
            }
        }
コード例 #4
0
        public void WriteHeaderLine()
        {
            if (_currentFormat >= 0)
            {
                CSVFormat format = Formats[_currentFormat];

                string headerLine = "";
                for (int i = 0; i < format.Fields.Count(); i++)
                {
                    if (i != 0)
                    {
                        headerLine += format.HeaderFieldSeparator;
                    }

                    headerLine += format.HeaderFieldDelimiter + format.Fields[i].FieldName + format.HeaderFieldDelimiter;
                }
                sw.WriteLine(headerLine);
            }
        }
コード例 #5
0
 public void AddFormat(CSVFormat format,
                       bool bHasHeaderLine = false)
 {
     SetFormat(Formats.Count(), format, bHasHeaderLine);
 }