Get Text of Specific Cell

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();

Download Sample Code

  • Github
  • Bitbucket