Accord.IO.ExcelReader.GetWorksheetList C# (CSharp) Метод

GetWorksheetList() публичный Метод

Gets the list of worksheets in the spreadsheet.
public GetWorksheetList ( ) : string[]
Результат string[]
        public string[] GetWorksheetList()
        {
            var set = new HashSet<string>();

            using (var connection = new OleDbConnection(strConnection))
            {
                connection.Open();

                var table = connection.GetSchema("Tables");

                for (int i = 0; i < table.Rows.Count; i++)
                {
                    string name = (string)table.Rows[i]["TABLE_NAME"];

                    // removes the trailing $ and other characters appended in the table name
                    while (name.EndsWith("$", StringComparison.Ordinal)
                        || name.EndsWith("$\"", StringComparison.Ordinal)
                        || name.EndsWith("$\'", StringComparison.Ordinal)
                        || name.EndsWith("$\"\'", StringComparison.Ordinal)
                        || name.EndsWith("$\'\"", StringComparison.Ordinal))
                        name = name.Remove(name.Length - 1).Trim('"', '\'');

                    set.Add(name);
                }
            }

            this.worksheets = new List<string>(set).ToArray();

            return worksheets;
        }

Usage Example

Пример #1
0
        private void MenuFileOpen_Click(object sender, EventArgs e)
        {
            if (openFileDialog.ShowDialog(this) == DialogResult.OK)
            {
                string filename = openFileDialog.FileName;
                string extension = Path.GetExtension(filename);
                if (extension == ".xls" || extension == ".xlsx")
                {
                    ExcelReader db = new ExcelReader(filename, true, false);
                    TableSelectDialog t = new TableSelectDialog(db.GetWorksheetList());

                    if (t.ShowDialog(this) == DialogResult.OK)
                    {
                        this.sourceTable = db.GetWorksheet(t.Selection);
                        this.dgvAnalysisSource.DataSource = sourceTable;

                        this.cbTimeName.Items.Clear();
                        this.cbEventName.Items.Clear();
                        this.checkedListBox1.Items.Clear();
                        foreach (DataColumn col in sourceTable.Columns)
                        {
                            this.cbTimeName.Items.Add(col.ColumnName);
                            this.cbEventName.Items.Add(col.ColumnName);
                            this.checkedListBox1.Items.Add(col.ColumnName);
                        }

                        this.cbTimeName.SelectedIndex = 0;
                    }
                }
            }
        }
All Usage Examples Of Accord.IO.ExcelReader::GetWorksheetList