Quantcast
Channel: NPOI
Viewing all articles
Browse latest Browse all 1621

Closed Unassigned: xlsx format file with xls extension issue [13153]

$
0
0
hi i have an xslx format file but the user will upload it with an . xls extension.

IN my code im checking the extension...
if its .xlsx im using XssfWorkboox if its .xls im using HssfWorkbook...
BUt its giving me an error .. "Invalid header".. pls help me with a solution...
user cannot change the extension...


if (fileExt.ToLower() == ".xls")
{
isXlsxXSSFfFile = false;
//Use the NPOI Excel xls object
using (FileStream file = new FileStream(_pathAndFile, FileMode.Open, FileAccess.Read))
{
hssfwb = new HSSFWorkbook(file);
}
if (string.IsNullOrEmpty(_sheetName))
{
hssfSheet = (HSSFSheet)hssfwb.GetSheetAt(0);
}
else
{
if (this.SheetExists(_sheetName))
hssfSheet = (HSSFSheet)hssfwb.GetSheet(_sheetName);
else
throw new ObjectNotFoundException("Sheet name doesn't exist");
}
}
else //.xlsx extension
{
isXlsxXSSFfFile = true;

//Use the NPOI Excel xlsx object
using (FileStream file = new FileStream(_pathAndFile, FileMode.Open, FileAccess.Read))
{
xssfwb = new XSSFWorkbook(file);
}
if (string.IsNullOrEmpty(_sheetName))
{
xssfSheet = (XSSFSheet)xssfwb.GetSheetAt(0);

}
else
{
if (this.SheetExists(_sheetName))
xssfSheet = (XSSFSheet)xssfwb.GetSheet(_sheetName);
else
throw new ObjectNotFoundException("Sheet name doesn't exist");
}

}

Viewing all articles
Browse latest Browse all 1621

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>