using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Office.Interop.Excel;
using System.Data.OleDb;
namespace EXCEL_SMS
{
class Program
{
static void Main(string[] args)
{
string path = "C:\\Projects\\ExcelSingleValue\\Test.xlsx ";
Application excel = new Application();
Workbook wb = excel.Workbooks.Open(path);
Worksheet excelSheet = wb.Activesheet;
// Read the first cell
string test = excelSheet.Cells[1, 1].Value.ToString();
// string sValue = (range.Cells[2, 4] as Microsoft.Office.Interop.Excel.Range).Value2.ToString();
wb.Close();
}
}
}
我在活動頁面出現錯誤,我想在Excel打開時讀取單元格值。任何人都可以告訴我如何實現它?我正在使用Visual Studio 2012.允許從Excel讀取單元格值到C#
你什麼錯誤得到的第一個單元格? – Filburt
錯誤'object'不包含'ActiveSheet'的定義,並且沒有可以找到接受'object'類型的第一個參數的擴展方法'ActiveSheet' –
@Filburt您是否得到我的問題 –