I have this code using NPOI.
I'm trying to have an object that will be a either aHSSFWorkbook
or a XSSFWorkbook
depending on version of excel file.
It is possible to have an Type
and past it to generic method in order to cast then return either HSSFWorkbook
or XSSFWorkbook
?
And also if it works, I will use GetWorkBook()
in different method.
Please see my comment on constructor.
public class ExcelReader
{
public ExcelReader(filePath)
{
var isXls = Path.GetExtension(_filePath) == ".xls";
// Is the following possible or is there any work around to get it work.
var type = isXls ? HSSFWorkbook : XSSFWorkbook;
var workbook = GetWorkBook<type>();
// Other init...
}
public T GetWorkBook<T>()
{
return (T)Workbook.GetSheetAt();
}
}