コード例 #1
0
        private void ExtractExcelData()
        {
            if (SelectedFileInfo != null)
            {
                _reader = new ExcelFileReader(SelectedFileInfo);

                if (_reader.IsFileExists())
                {
                    if (!_reader.IsFileOpen())
                    {
                        List<string> subItems = _reader.GetListSubItems();
                        if (subItems != null)
                        {
                            if (subItems.Count >= 1)
                            {
                                List<IDictionary> data = _reader.GetData(subItems[0]).ToList();
                                if (data.Count() == 0)
                                {
                                    _dataSource = "";
                                    throw new Exception("No rows found in excel file ' " + SelectedFileInfo.Name + " '!");
                                }
                                else
                                    _dataSource = data.ToDataSource();
                            }
                        }
                    }
                    else
                    {
                        throw new Exception("Excel File ' " + SelectedFileInfo.Name + " ' is in use.");
                    }
                }
                else
                {
                    throw new Exception("Excel File ' " + SelectedFileInfo.Name + " ' not found.");
                }
            }
            else
                throw new Exception("Please select an excel file");
        }