using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Shapes; using DevExpress.Xpf.Core; using DevExpress.Xpf.Bars; using DevExpress.Xpf.Grid; using DevExpress.Xpf.Printing; using System.ComponentModel; using System.Collections.ObjectModel; using DevExpress.Xpf.NavBar; using System.Data.SqlClient; using System.Data; using System.Data.OleDb; using Excel = Microsoft.Office.Interop.Excel;
InitializeComponent(); DataContext = new DataSource(); } private void Button_Click_1(object sender, RoutedEventArgs e) { } private void Button_Click_2(object sender, RoutedEventArgs e) { // Create OpenFileDialog Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog(); // Set filter for file extension and default file extension dlg.DefaultExt = ".txt"; dlg.Filter = "EXCEL Files (*.xlsx)|*.xlsx"; // Display OpenFileDialog by calling ShowDialog method Nullable<bool> result = dlg.ShowDialog(); // Get the selected file name and display in a TextBox if (result == true) { // Open document string filename = dlg.FileName; } } public class ExcelData { public DataView Data { get { Excel.Application excelApp = new Excel.Application(); Excel.Workbook workbook; Excel.Worksheet worksheet; Excel.Range range; workbook = excelApp.Workbooks.Open(Environment.CurrentDirectory + "\\Excel.xlsx"); worksheet = (Excel.Worksheet)workbook.Sheets["Test Sheet"];//.get_Item(1); int column = 0; int row = 0; range = worksheet.UsedRange; DataTable dt = new DataTable(); dt.Columns.Add("ID"); dt.Columns.Add("Name"); dt.Columns.Add("Position"); dt.Columns.Add("Web Site"); for (row = 2; row <= range.Rows.Count; row++) { DataRow dr = dt.NewRow(); for (column = 1; column <= range.Columns.Count; column++) { dr[column - 1] = (range.Cells[row, column] as Excel.Range).Value2.ToString(); } dt.Rows.Add(dr); dt.AcceptChanges(); } workbook.Close(true, Missing.Value, Missing.Value); excelApp.Quit(); return dt.DefaultView; }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)