Comments (5)
Hi, can you please attach original file and corrupted?
from npoi.
Oh, sorry.
Here you have the 2 files. Hope that will help you.
Corrupt file.xlsx
Good file.xlsx
Thank you.
from npoi.
It seems to be smth wrong with shared formulas...
Can you please also provide your code to modificate the original file?
from npoi.
Hi, here the code. I clean up it because there is a connection to DB
string filename = "" //the filename goes here.
XSSFWorkbook newWorkbook = new();
XSSFSheet excelSheet = new();
initializeWorkbook(ref filename, ref newWorkbook, ref excelSheet);
int rowIndex = 1;
IRow row = excelSheet.CreateRow(rowIndex);
row.CreateCell(0).SetCellValue(12002219);
row.CreateCell(1).SetCellValue((double)2.2);
XSSFFormulaEvaluator.EvaluateAllFormulaCells(newWorkbook);
using FileStream fs = new(filename, FileMode.Create, FileAccess.Write);
newWorkbook.Write(fs);
fs.Close();
PrintMyExcelFile(filename);
//this code initialize the document
private void initializeWorkbook(ref string filename, ref XSSFWorkbook newWorkbook, ref XSSFSheet excelSheet)
{
newWorkbook = new();
using (FileStream filestream = new(filename, FileMode.Open, FileAccess.Read))
{
newWorkbook = new XSSFWorkbook(filestream);
filestream.Close();
}
int rowIndex = 0;
excelSheet = (XSSFSheet)newWorkbook.GetSheet("A PRODUIRE");
if (excelSheet != null)
{
while (excelSheet.GetRow(rowIndex) != null)
{
excelSheet.GetRow(rowIndex).GetCell(0)?.SetCellValue(0);
excelSheet.GetRow(rowIndex).GetCell(1)?.SetCellValue(0);
rowIndex++;
}
}
else
{
excelSheet = (XSSFSheet)newWorkbook.CreateSheet("A PRODUIRE");
}
IRow row = excelSheet.CreateRow(0);
row.CreateCell(0).SetCellValue("ItemId");
row.CreateCell(1).SetCellValue("Qté à produire");
row.CreateCell(2).SetCellValue(SelectedDate.Date);
}
//this code is for printing but crash at the line : Excel.Worksheet ws = (Excel.Worksheet)wb.Worksheets[1];
private void PrintMyExcelFile(string fileName)
{
Excel.Application excelApp = new();
Excel.Workbook wb = excelApp.Workbooks.Open(fileName,
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing);
Excel.Worksheet ws = (Excel.Worksheet)wb.Worksheets[1];
for (int i = 1; i <= wb.Worksheets.Count; i++)
{
if (((Excel.Worksheet)wb.Worksheets[i]).Name == "MAIN")
{
ws = (Excel.Worksheet)wb.Worksheets[i];
ws.PrintOut(Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
break;
}
}
// Cleanup:
GC.Collect();
GC.WaitForPendingFinalizers();
Marshal.FinalReleaseComObject(ws);
wb.Close(false, Type.Missing, Type.Missing);
Marshal.FinalReleaseComObject(wb);
excelApp.Quit();
Marshal.FinalReleaseComObject(excelApp);
}
Hope you will have the possibility to reproduce the error and fix it.
from npoi.
The bug was already fixed in #1291
from npoi.
Related Issues (20)
- GitHub: Missing release info/changelog for 2.7.1 HOT 3
- XSSFTable.CreateColumn return System.ArgumentOutOfRangeException: Index was out of range HOT 1
- The backport of POI Bug 60370 introduces a bug with PromptBox and ErrorBox text encoding HOT 1
- ByteArrayOutputStream is not disposed in NPOI.Util.IOUtils.ToByteArray method. Potential Memory leak HOT 2
- Reading Docs With DesignType,throw POIXMLException Error
- Wrong picture size in merged cell after picture.Resize() was invoked.
- Security vulnerabilities in SixLabors.ImageSharp HOT 4
- XSSFWorkbook write issue HOT 1
- Remove picture... HOT 2
- npoi-examples not available HOT 4
- 安装了最新版的库,处理同样多的数据,变慢了一半! HOT 4
- Inconsistent new lines in worksheets HOT 1
- Icon path in `Directory.Build.props` is invalid on MacOS HOT 1
- Request to update dependency packages to latest. ImageSharp library HOT 1
- How to create a Date or Time range in xlsx
- SXSSFWorkbook leaveOpen doesn't work as intend.
- The numFmt tag in the workbook file is missing the formatCode attribute value
- Incompatible license in file HOT 2
- Out of memory exception in reading .xlsx file using Xssfworkbook HOT 3
- Excel has new default font Aptos, NPOI should not set a default FontName HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from npoi.