Hi
I am just doing a basic save from the Open XML library, so no changes is being done to the excel file. But when I try to read it with the Excel Data Reader it gives my sheet count back as 0. I compared the 2 files in their xml form and they are identical.
Saving the file:
I am just doing a basic save from the Open XML library, so no changes is being done to the excel file. But when I try to read it with the Excel Data Reader it gives my sheet count back as 0. I compared the 2 files in their xml form and they are identical.
Saving the file:
WorksheetPart wsPart = wbPart.GetPartById(s.Id) as WorksheetPart;
WorksheetWriter writer = new WorksheetWriter(doc, wsPart);
if (wsPart == null)
{
continue;
}
var calcChainPart = wbPart.CalculationChainPart;
wbPart.DeletePart(calcChainPart);
wbPart.DeletePart(wbPart.VbaProjectPart);
foreach (Row row in wsPart.Worksheet.Descendants<Row>())
{
foreach (Cell c in row.Elements<Cell>())
{
if (c.CellFormula != null && (!(String.IsNullOrEmpty(c.CellFormula.ToString()))))
{
c.CellFormula.Remove();
}
}
}
}
wbPart.Workbook.Save();
Opening again in Excel Reader:FileStream stream = System.IO.File.Open(@"D:\Book1.xlsx", FileMode.Open);
IExcelDataReader excelReader;
switch (ext)
{
case ".xls":
excelReader = ExcelReaderFactory.CreateBinaryReader(stream);
break;
case ".xlsx":
excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream);
break;
case ".xlsm":
excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream);
break;
default:
ErrorMessage = "Incompatible file type.";
return RedirectToAction("Index");
}
DataSet result = excelReader.AsDataSet();
int sheetCount = result.Tables.Count;
When opening the file with excel it has no problems.