Ejemplo n.º 1
0
        /// <summary>
        /// Read the contents of the Settings worksheet in the specified Excel file into a DataTable.
        /// Excel files up to Excel 2000 and SpreadsheetML XML 2000 files are both supported.
        /// </summary>
        /// <param name="inputFile">Path to the XLS or XML file</param>
        /// <returns></returns>
        internal static DataTable ReadSettingsFromExcelFile(string inputFiles)
        {
            DataTable datatable = null;

            string[] inputlist = inputFiles.Split(";".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);

            foreach (string inputFile in inputlist)
            {
                if (!File.Exists(inputFile))
                {
                    throw new FileNotFoundException("The specified input file " + inputFile + " does not exist.", inputFile);
                }
                DataTable dt            = null;
                string    fileExtension = Path.GetExtension(inputFile);

                if (string.Compare(fileExtension, ".xls", true) == 0 || string.Compare(fileExtension, ".xlsx", true) == 0)
                {
                    dt = ExcelBinarySettingsFileReader.ReadSettingsFromXls(inputFile);
                }
                else
                {
                    dt = SpreadsheetMlSettingsFileReader.ReadSettingsFromSpreadsheetMl(inputFile);
                }

                if (datatable == null)
                {
                    datatable = dt;
                }
                else
                {
                    if (dt != null)
                    {
                        //remove fist 5 rows
                        for (int i = 0; i < dt.Rows.Count; i++)
                        {
                            if (i > HeaderRowsCount)
                            {
                                datatable.ImportRow(dt.Rows[i]);
                            }
                        }
                    }
                }
            }

            return(datatable);
        }
        /// <summary>
        /// Read the contents of the Settings worksheet in the specified Excel file into a DataTable.
        /// Excel files up to Excel 2000 and SpreadsheetML XML 2000 files are both supported.
        /// </summary>
        /// <param name="inputFile">Path to the XLS or XML file</param>
        /// <returns></returns>
        internal static DataTable ReadSettingsFromExcelFile(string inputFile)
        {
            if (!File.Exists(inputFile))
            {
                throw new FileNotFoundException("The specified input file " + inputFile + " does not exist.", inputFile);
            }

            DataTable dt            = null;
            string    fileExtension = Path.GetExtension(inputFile);

            if (string.Compare(fileExtension, ".xls", true) == 0 || string.Compare(fileExtension, ".xlsx", true) == 0)
            {
                dt = ExcelBinarySettingsFileReader.ReadSettingsFromXls(inputFile);
            }
            else
            {
                dt = SpreadsheetMlSettingsFileReader.ReadSettingsFromSpreadsheetMl(inputFile);
            }

            return(dt);
        }