using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.IO.Ports; using System.Drawing.Imaging; using System.Runtime.InteropServices; using Excel = Microsoft.Office.Interop.Excel; namespace spark { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button38_Click(object sender, EventArgs e) { Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application(); if (xlApp == null) { MessageBox.Show("Excel is not properly installed!!"); return; } Excel.Workbook xlWorkBook; Excel.Worksheet xlWorkSheet; Excel.Range range; object misValue = System.Reflection.Missing.Value; xlWorkBook = xlApp.Workbooks.Add(misValue); xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1); range = xlWorkSheet.UsedRange; OpenFileDialog openFileDialog1 = new OpenFileDialog { InitialDirectory = @"D:\", Title = "Browse XLS Files", CheckFileExists = true, CheckPathExists = true, DefaultExt = "xls", Filter = "xls files (*.xls)|*.xls", FilterIndex = 2, RestoreDirectory = true, ReadOnlyChecked = true, ShowReadOnly = true }; if (openFileDialog1.ShowDialog() == DialogResult.OK) { string filename = openFileDialog1.FileName; if (filename != "") { try { // String filename = DialogResult.ToString(); var excelApp = new Excel.Application(); excelApp.Visible = true; // excelApp.Visible = false; excelApp.Workbooks.Open(filename); } catch (Exception ew) { MessageBox.Show("Errror:" + ew.ToString()); } } } var tt = Convert.ToString(xlWorkSheet.Cells[1, 1]); textBox1.Text = tt.ToString(); MessageBox.Show(textBox1.Text.ToString()); //textBox1.Text = (string)((Microsoft.Office.Interop.Excel.Range)xlWorkSheet.Cells[1, 1]).Value; xlWorkBook.Close(true, null, null); xlApp.Quit(); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)