using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Reflection;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Excel=Microsoft.Office.Interop.Excel;
namespace read
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
Excel.Application xApp = new Excel.ApplicationClass();
xApp.Visible = true;
Excel.Workbook xBook = xApp.Workbooks._Open(@"D:/p.xlsx",
Missing.Value, Missing.Value, Missing.Value, Missing.Value
, Missing.Value, Missing.Value, Missing.Value, Missing.Value
, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
Excel.Worksheet xSheet = (Excel.Worksheet)xBook.Sheets[1];
Excel.Range[] r=new Excel.Range[3];
for (int i = 1; i < 3; i++)
{
r[i]=(Excel.Range)(xSheet.Cells[1,i]);
}
for(int i = 1; i < 3; i++)
{
listBox1.Items.Add(r[i].Value2);
}
xBook.Save();
xApp.Quit();
}
}
}