I'm looking for the same thing. You had any luck with it?
I'm looking for the same thing. You had any luck with it?
same issue for me, already reported under Id #13957. I suggest merging the bugs
same issue for me, already reported under Id #13957 (and #14012?). I suggest merging the bugs
We found a problem with some content in 'test.xlsx'. Do you want us to try to recover as much as we can? If you trust the source of this workbook, click Yes.
Clicking Yes gets me another message:Excel cannot open the file 'test.xlsx' because the file format or file extension is not valid. Verify that the file has not been corrupted and that the file extension matches the format of the file.
I have no issues creating a new .xlsx file with the following code: string newPath = @"C:\MyPath\test.xlsx";
using (FileStream fs = new FileStream(newPath, FileMode.Create, FileAccess.Write))
{
IWorkbook wb = new XSSFWorkbook();
wb.CreateSheet();
ISheet s = wb.GetSheetAt(0);
IRow r = s.CreateRow(0);
r.CreateCell(0);
ICell c = r.GetCell(0);
c.SetCellValue("test");
wb.Write(fs);
fs.Close();
}
That works fine. string newPath = @"C:\MyPath\test.xlsx";
using (FileStream fs = new FileStream(newPath, FileMode.Open, FileAccess.ReadWrite))
{
IWorkbook wb = new XSSFWorkbook(fs);
wb.Write(fs);
fs.Close();
}
However, after running through code that reads from it, gets ISheets, IRows, ICells, etc.... it corrupts the .xlsx file. Even though I specifically removed anything that modifies the workbook. No Creates, Sets, Styles, etc. with NPOI. IWorkbook
XSSFWorkbook
ISheet
IRow
ICell
.GetSheetAt
.GetRow
.GetCell
.LastRowNum
So one of those causes corruption. I would like to eventually set values again and get it working like I have for .xls.HSSFWorkbook hssfwb;
using (FileStream file = new FileStream(@"\\192.168.198.129\tmp\test.xls", FileMode.Open, FileAccess.Read))
{
//here the problem!!!
hssfwb = new HSSFWorkbook(file,false);
}
before i used https://github.com/ExcelDataReader/ExcelDataReader that open the file like a text(with filestream) and i loop data like a normal text.private void read()
{
FileStream stream = File.Open(@"\\192.168.198.129\tmp\test.xls", FileMode.Open, FileAccess.Read);
IExcelDataReader excelReader = ExcelReaderFactory.CreateBinaryReader(stream);
while (excelReader.Read())
{
Console.WriteLine(excelReader[0]);
}
DataSet result = excelReader.AsDataSet();
Console.Read();
}
is there any possibilities?Neuzilla is the software studio behind NPOI. Please follow us.
Our website: www.neuzilla.com
If you need NPOI support service/business customization service, please contact support@neuzilla.com
如果你需要关于NPOI的有偿技术支持和定制服务,请联系support@neuzilla.com
中文教程
NPOI 教程(简体中文)
NPOI 教程(繁体中文)
English Tutorial
NPOI 2.0 intro
NPOI 1.2 Japanese Tutorial
Export to Excel with third-party library (NPOI)
How to read in XLSX data for editing with NPOI
其他
NPOI Road Map
NPOI Team Members
NPOI Release Plan
History of Changes
NPOI Test Cases
Image may be NSFW.
Clik here to view.
支付宝捐款账号: tonyqus@163.com
Paypal: tonyqus@gmail.com
Image may be NSFW.
Clik here to view.
using (FileStream fs = new FileStream("temp.xlsx", FileMode.Open, FileAccess.Read))
{
IWorkbook wb = WorkbookFactory.Create(fs);
}
After reading excel file using above code process memory increased around 200MB. In my application multiple excel files are reading one after another, so process memory increasing for each file. I am unable to clear process memory because workbook doesn't have any dispose method. I want to clear memory occupied by workbook after completion of work with one excel file and read another file.