示例#1
0
        private async void Button2_Click(object sender, EventArgs e)
        {
            OleDb.GetSheetsNames(excel);
            var table = await Task.Run(() => OleDb.ReadData(excel, txtnmlst.Text));

            dataGridView1.DataSource = excel.Data;

            for (var i = 0; i < dataGridView1.Columns.Count; i++)
            {
                dataGridView1.Columns[i].HeaderCell.Style.BackColor = Color.Gray;
                dataGridView1.Columns[i].HeaderCell.Style.ForeColor = Color.DarkGray;
            }
            for (var i = 0; i < dataGridView1.RowCount; i++)
            {
                dataGridView1.Rows[i].HeaderCell.Value = i.ToString();
            }

            lstColNames.Items.Clear();
            foreach (DataColumn col in excel.Data.Columns)
            {
                lstColNames.Items.Add(col.ColumnName);
            }
            GC.Collect();
            GC.WaitForPendingFinalizers();
        }