110,539
社区成员
发帖
与我相关
我的任务
分享
using Excel = Microsoft.Office.Interop.Excel;
Excel.Application app = null;
Excel.Workbook book = null;
Excel.Worksheet sheet = null;
try
{
app = new Excel.Application();
book = app.Workbooks.Open(@"d:\sheet1.xls");
sheet = book.Sheets[1];
MessageBox.Show(((DateTime)sheet.get_Range("A1").Value).ToShortDateString());
sheet.get_Range("A2").Copy();
sheet.get_Range("B2").PasteSpecial(Excel.XlPasteType.xlPasteValues);
MessageBox.Show(Convert.ToString(sheet.get_Range("B2").Value));
book.Close(true);
app.Quit();
}
finally
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(sheet);
System.Runtime.InteropServices.Marshal.ReleaseComObject(book);
System.Runtime.InteropServices.Marshal.ReleaseComObject(app);
GC.Collect();
}