示例#1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="AfileName"></param>
        /// <returns></returns>
        public Boolean OpenCsvFile(String AfileName)
        {
            // We don't need to read the whole file for this because we will only display the first 5 lines
            bool hasBOM, isAmbiguousUTF;

            if (TTextFile.AutoDetectTextEncodingAndOpenFile(AfileName, out FFileContent, out FCurrentEncoding,
                                                            out hasBOM, out isAmbiguousUTF, out FRawBytes) == false)
            {
                return(false);
            }

            TTextFileEncoding.SetComboBoxProperties(cmbTextEncoding, hasBOM, isAmbiguousUTF, FCurrentEncoding);
            DisplayGrid();
            return(true);
        }
示例#2
0
        /// <summary>
        /// convert a CSV file to an XmlDocument.
        /// the first line is expected to contain the column names/captions, in quotes.
        /// from the header line, the separator can be determined, if the parameter ASeparator is empty
        /// </summary>
        /// <param name="ACSVFilename">The filename</param>
        /// <param name="AFallbackEncoding">The file encoding will be automatically determined, but if a fallback is specified that does not match
        /// the encoding that was determined, it will be used.  Usually this paramter can be null.</param>
        /// <param name="ASeparator">A column separator</param>
        public static XmlDocument ParseCSVFile2Xml(string ACSVFilename, string ASeparator = null, Encoding AFallbackEncoding = null)
        {
            string   fileContent;
            Encoding fileEncoding;
            bool     hasBOM, isAmbiguous;

            byte[] rawBytes;

            if (TTextFile.AutoDetectTextEncodingAndOpenFile(ACSVFilename, out fileContent, out fileEncoding,
                                                            out hasBOM, out isAmbiguous, out rawBytes))
            {
                if ((AFallbackEncoding != null) && !fileEncoding.Equals(AFallbackEncoding))
                {
                    fileContent = AFallbackEncoding.GetString(rawBytes);
                }

                return(ParseCSVContent2Xml(fileContent, ASeparator));
            }

            // Either we could not open the file or it is empty
            return(ParseCSV2Xml(new List <string>(), ASeparator));
        }