private void btnImport_Click(object sender, EventArgs e) { try { OpenFileDialog o = new OpenFileDialog(); o.ShowDialog(); string sFile = o.FileName; if (radio发票.Checked) { gridControl回款.Visible = false; gridControl发票.Visible = true; TH.BaseClass.ClsExcel clsExcel = TH.BaseClass.ClsExcel.Instance(); string sSQL = @" select * from [发票$] "; DataTable dt = clsExcel.ExcelToDT(sFile, sSQL, true); for (int i = 0; i < dt.Columns.Count; i++) { dt.Columns[i].ColumnName = dt.Columns[i].ColumnName.ToString().Trim(); } gridControl发票.DataSource = dt; gridView发票.BestFitColumns(); } if (radio回款.Checked) { gridControl发票.Visible = false; gridControl回款.Visible = true; TH.BaseClass.ClsExcel clsExcel = TH.BaseClass.ClsExcel.Instance(); string sSQL = @" select * from [回款$] "; DataTable dt = clsExcel.ExcelToDT(sFile, sSQL, true); for (int i = 0; i < dt.Columns.Count; i++) { dt.Columns[i].ColumnName = dt.Columns[i].ColumnName.ToString().Trim(); } gridControl回款.DataSource = dt; gridView回款.BestFitColumns(); } } catch (Exception ee) { MessageBox.Show("加载数据失败:" + ee.Message); } }
private void btnLoadExcel_Click(object sender, EventArgs e) { try { OpenFileDialog o = new OpenFileDialog(); o.ShowDialog(); chkAll.Checked = false; string sFile = o.FileName; TH.BaseClass.ClsExcel clsExcel = TH.BaseClass.ClsExcel.Instance(); string sSQL = @" select * from [Sheet1$] "; DataTable dt = clsExcel.ExcelToDT(sFile, sSQL, true); DataColumn dc = new DataColumn(); dc.ColumnName = "choose"; dc.DataType = System.Type.GetType("System.Boolean"); dc.DefaultValue = false; dt.Columns.Add(dc); dc = new DataColumn(); dc.ColumnName = "已使用"; dc.DataType = System.Type.GetType("System.Boolean"); dc.DefaultValue = false; dt.Columns.Add(dc); for (int i = 0; i < dt.Columns.Count; i++) { dt.Columns[i].ColumnName = dt.Columns[i].ColumnName.ToString().Trim(); } gridControl1.DataSource = dt; gridView1.BestFitColumns(); b编辑 = false; } catch (Exception ee) { MessageBox.Show("加载数据失败:" + ee.Message); } }