public void mouseCommand() { ExcelValue ev = new ExcelValue(); ExcelCell ec = new ExcelCell(); ec.ColumnIndex = col; ec.RowIndex = row; ec.Value = Value; staticCol = col; staticRow = row; StaticCellValue = Value; showInd = col + " : " + row; showValue = Value.ToString(); //ExcleViewModel evm = new ExcleViewModel(); MainWindow.evm.E(staticCol,staticRow,StaticCellValue); MainWindow.evm.indexValue = showInd; MainWindow.evm.showValue = Value; //MessageBox.Show("click works " + showInd); }
public void opens() { try { //MessageBox.Show("Button works"+ sheet); OleDbConnection con = new OleDbConnection("Provider = Microsoft.ACE.OLEDB.12.0; Data Source = " + filePath + "; Extended Properties =\"Excel 8.0; HDR=Yes; IMEX=1;\""); //string from = textBox_from.Text.ToString(); //string to = textBox_to.Text.ToString(); if (from != "" && to != "") { OleDbCommand oconn = new OleDbCommand ( "SELECT * From [" + sheet + "$" + from + ":" + to + "]", con ); DataSet ds = new DataSet(); dataTable = new DataTable(); OleDbDataAdapter adapter = new OleDbDataAdapter(oconn); oconn.Connection = con; int i; int j; adapter.Fill(dataTable); //ds.Tables.Add(dataTable); ef = new ObservableCollection<ExcelRow>(); for (i = 0; i <= dataTable.Rows.Count - 1; i++) { ExcelRow r = new ExcelRow(); for (j = 0; j <= dataTable.Columns.Count - 1; j++) { // MessageBox.Show( dataTable.Rows[i][j].ToString()); string s = dataTable.Rows[i][j].ToString(); //er.Add(s); ExcelValue ev = new ExcelValue(); ev.Value = s; ev.row = i; ev.col = j; r.Row.Add(ev); } ef.Add(r); } // dataGrid1.DataContext = data; } else if (from == "" && to != "") { MessageBox.Show("Please Enter a starting Range for your selection. You can Enter A1 to Z1 to Select a Row or A1 to A100 to select a Column"); } else if (from != "" && to == "") { MessageBox.Show("Please Enter a starting Range for your selection. You can Enter A1 to Z1 to Select a Row or A1 to A100 to select a Column"); } else { OleDbCommand oconn = new OleDbCommand ( "SELECT * From [" + sheet + "$]", con ); DataSet ds = new DataSet(); dataTable = new DataTable(); OleDbDataAdapter adapter = new OleDbDataAdapter(oconn); oconn.Connection = con; int i; int j; adapter.Fill(dataTable); //ds.Tables.Add(dataTable); ef = new ObservableCollection<ExcelRow>(); for (i = 0; i <= dataTable.Rows.Count - 1; i++) { ExcelRow r = new ExcelRow(); for (j = 0; j <= dataTable.Columns.Count - 1; j++) { // MessageBox.Show( dataTable.Rows[i][j].ToString()); string s = dataTable.Rows[i][j].ToString(); //er.Add(s); ExcelValue ev = new ExcelValue(); ev.Value = s; ev.row = i; ev.col = j; r.Row.Add(ev); } ef.Add(r); } // dataGrid1.DataContext = data; } } catch (Exception ButtonException) { MessageBox.Show(" an Exception happend, " + ButtonException); } }