I have created a class for reading data from an Excel sheet and holding on the variable. I am not sure if my code is optimized, meaning I will be reading heavily from Excel.
Is there a room to further optimized this code? I will be using this class heaving in my code, and I wanted to get some opinions/feedback.
I will be calling something like this:
ExcelReader xl = new ExcelReader();
string sss = xl.ExcelOpenSpreadsheets("mysheet");
//etc...
public class ExcelReader
{
Application _excelApp;
public ExcelReader()
{
_excelApp = new Application();
}
public string ExcelOpenSpreadsheets(string sheetName)
{
string _txt = string.Empty;
try
{
Workbook workBook = _excelApp.Workbooks.Open("filename_here",....);
_txt = ExcelScanIntenal(workBook, sheetName);
}
catch
{
//
// Deal with exceptions.
//
}
return _txt;
}
private string ExcelScanIntenal(Workbook workBookIn, string sheetName)
{
Worksheet sheet = workBookIn.Sheets[sheetName] as Worksheet;
Range a1 = sheet.get_Range("A1", "B2");
if (a1 != null)
{
string formattedText = r.Text;
}
return formattedText;
}