Obtenir le texte d une cellule spécifique

VSTO

 //Instantiate the Application object.

Excel.Application excelApp = Application;

//Specify the template excel file path.

string myPath = "Get Text of Specific Cell.xlsx";

//Open the excel file.

Microsoft.Office.Interop.Excel.Workbook ThisWorkbook = excelApp.Workbooks.Open(myPath, Missing.Value, Missing.Value,

	  Missing.Value, Missing.Value,

	  Missing.Value, Missing.Value,

	  Missing.Value, Missing.Value,

	  Missing.Value, Missing.Value,

	  Missing.Value, Missing.Value,

	  Missing.Value, Missing.Value);

String res = "";

res = ThisWorkbook.Worksheets["Sheet1"].Range("A1").Text;

MessageBox.Show(res);

//Save the file.

excelApp.ActiveWorkbook.Save();

excelApp.Quit();

Aspose

 //Specify the excel file path.

string myPath = "Get Text of Specific Cell.xlsx";

//Instantiating a Workbook object

Workbook workbook = new Workbook(myPath);

//Get worksheet

Worksheet worksheet = workbook.Worksheets[0];

String res = "";

res= worksheet.Cells["A1"].Value.ToString();

Console.Write(res);

Console.ReadKey();

Télécharger le code source d’exemple