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

Commented Unassigned: Corrupted Excel files with NPOI - asp.net [12762]

$
0
0
Hi all, I need a small help with NPOI and asp.net.
I'm trying to create an excel file from a web application, written in asp.net (vb).
Everything is fine with excel 2003 xls format, while using the XSSF object model I get corrupted files.
Opening files in Excel I get the message that says file is corrupted, and can be restored (and actually Excel repairs it). The problem occurs even if I try to save stream into a file, rather than using memorystream.
Help is appreciated...
Here's the code, see attachment for error:

Dim wb As New XSSFWorkbook
Dim ws As new XSSFSheet
ws = wb.CreateSheet("Sheet1")
Dim r As XSSFRow
r = ws.CreateRow(0)
Dim c = r.CreateCell(0)
c.SetCellValue("Test")

Dim m As New IO.MemoryStream
m.Flush()
wb.Write(m)

Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
Response.AddHeader("content-disposition", "attachment;filename=test.xlsx")
Response.Clear()
Response.BinaryWrite(m.GetBuffer())

Response.End()
Comments: ** Comment from web user: chantszhim **

I got the same problem after migrating the site from Windows Server 2008 R2 to Windows Server 2012 R2.


New Post: How to import NPOI dll into Windows 10 UWP project?

$
0
0
Hello,

How can I import NPOI dll into Windows 10 UWP project? When I add references, Visual Studio 2015 displays error message "A reference to 'xxx\NPOI.dll' could not be added. The project targets '.NETCore' while the file reference targets '.NETFramework'. This is not a supported scenario".

New Post: pivot

$
0
0
The version NPOI 2.2.1 support pivot table on xlsx files?

New Post: source code

$
0
0
it's possible to download the source code of version NPOI 2.2.1?
thanks

New Post: problem with xlsx file with pivot

$
0
0
I'm using NPOI 2.2.1. I open an xlsx with a Pivot table, I write some values in some cells an than save the file.
After that if I open the file with Excel I have the following errors:

/xl/pivotCache/pivotCacheDefinition1.xml with error XML. (cache pivot table).

What I can do?

thank

New Post: Inserting Excel Charts into Word Document

$
0
0
Hi Guys,

Was wondering if it is possible to add Excel charts into a word document with using NPOI?

New Post: source code

$
0
0
Hi,

I am totally new in here, so please bear with me, if I don't give the right information.

As far as I have figured out, the source code is here:
https://github.com/tonyqus/npoi

I haven't found any other forum for the software than here at codeplex, but the source code here seems to be very old.

/Rasmus

New Post: running MATCH formula from NPOI help

$
0
0
Good day, below is some code that I am trying to run. I realized my issue only happens when I have a 0 in for match but if I change it to 1 or -1 it works. It doesnt seem to be reconizing the 0, how do I fix this?

I tried another route by taking my data and moving it to the right hand of what I need and using a vlookup but the VLookup
sheet1.CreateRow(row + firstrow).CreateCell(19).SetCellFormula("VLOOKUP(" + j + "," + lookuprangess + "," + 2 + "," + "FALSE" + ")");  
gives the error
((NPOI.HSSF.UserModel.HSSFSheet)sheet1).IsAutoTabColor '((NPOI.HSSF.UserModel.HSSFSheet)sheet1).IsAutoTabColor' threw an exception of type 'System.NullReferenceException'
for (int row = 1; row <= 4; row++)
{
sheet1.CreateRow(row + firstrow + 1).CreateCell(15).SetCellFormula("LARGE(" + cellsranges + "," + row + ")");
HSSFFormulaEvaluator.EvaluateAllFormulaCells(hssfwb);

double j = sheet1.GetRow(row + firstrow + 1).GetCell(15).NumericCellValue;

sheet1.CreateRow(row + firstrow + 1).CreateCell(16).SetCellFormula("MATCH(" + j + "," + cellsranges + ", " + 0 + ")");
HSSFFormulaEvaluator.EvaluateAllFormulaCells(hssfwb);

double k = sheet1.GetRow(row + firstrow + 1).GetCell(16).NumericCellValue;

sheet1.CreateRow(row + firstrow + 1).CreateCell(17).SetCellFormula("INDEX(" + statesranges + "," + k + "," + 1 + ")");
HSSFFormulaEvaluator.EvaluateAllFormulaCells(hssfwb);

string stateperc = sheet1.GetRow(row + firstrow+1).GetCell(17).StringCellValue + "-" + j.ToString();

MessageBox.Show(stateperc);
}
I am new to this so sorry if it is simple!

Commented Issue: XSSFWorkbook Write corrupts XLSX File [12847]

$
0
0
This may be a duplicate of [12616](https://npoi.codeplex.com/workitem/12616), but after much research, I haven't been able to track down a solution.

I compiled NPOI from source in Visual Studio 2013 with a direct pull from GitHub - the NPOI version is 2.0.8. The issue occurs with the NPOI NuGet package as well. I am opening the file with Excel 2010. Consider the following:

```
IWorkbook wb = null;
string file = "numbers.xlsx";

using (FileStream fs = new FileStream(file, FileMode.Open, FileAccess.Read)) {
if (Path.GetExtension(file).Contains("xlsx")) {
wb = new XSSFWorkbook(fs);
} else {
wb = new HSSFWorkbook(fs);
}
}

using (FileStream fs = new FileStream(file, FileMode.Open, FileAccess.ReadWrite)) {
wb.Write(fs);
}
```

This will render the output XLSX file unusable. [Case in point on Excel's reaction](http://imgur.com/AMglz1Y,bcCXi0d).

Workbooks created/written in-code with the XSSF API open correctly. XLS files opened/written with the HSSF API are fine with respect to Excel.

The FileMode/FileAccess/FileShare options for the FileStream do not seem to make a difference.

In practice I have been opening far more complex XLSX files, writing a few new cells to the rows therein, and writing back, where after the spreadsheet cannot be opened or subsequently recovered.

I've attached the aforementioned XLSX spreadsheet for testing purposes. Thanks for having a look.
Comments: ** Comment from web user: SachaK **

If the file stream is created with FileMode.Create instead of FileMode.Open it works fine. It's confusing because it works with both for xls files.

See http://stackoverflow.com/questions/36142337

Created Unassigned: NPOI.HSSF AutoFilter Issue: "File error: data may have been lost" [14011]

$
0
0
Getting "File error: data may have been lost" when opening saved Excel after setting auto-filter.
Example files attached.


Attempt to add data filter over all columns of Excel file using HSSFWorkbook

- NPOI Version 2.2.1
- XLS workbook generated by Crystal Reports export in an ASP.net webforms application
- Excel version: Excel 2016


Crystal Reports XLS Export - unmodified:
Code:

Response.Clear();
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("Content-Disposition", string.Format("attachment; filename=\"{0}.xls\"", reportTitle));

using (Stream reportStream = _reportDocument.ExportToStream(ExportFormatType.Excel))
{
reportStream.CopyTo(Response.OutputStream);
}

Response.Flush();
Response.Close();
Response.End();


Generated file "SimpleReport - unmodified.xls"
which opens in Excel without warning/error.


Crystal Reports XLS Export - auto-filter added with HSSFWorkbook:
Code:

HSSFWorkbook workbook;
using (Stream reportStream = _reportDocument.ExportToStream(ExportFormatType.Excel))
{
workbook = new HSSFWorkbook(reportStream);
}

workbook.Workbook.Records.Add(new CountryRecord() { DefaultCountry = 1, CurrentCountry = 1 }); // need this else NPOI throws an exception

ISheet sheet = workbook.GetSheetAt(0);
CellRangeAddress cellRange = new CellRangeAddress(sheet.FirstRowNum, sheet.LastRowNum, sheet.GetRow(sheet.FirstRowNum).FirstCellNum, sheet.GetRow(sheet.LastRowNum).LastCellNum - 1);
sheet.SetAutoFilter(cellRange);

Response.Clear();
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("Content-Disposition", string.Format("attachment; filename=\"{0}.xls\"", reportTitle));

workbook.Write(Response.OutputStream);

Response.Flush();
Response.Close();
Response.End();


Generated file "SimpleReport - filter set with HSSFWorkbook.xls".
When opening in Excel, a dialog is shown stating: "File error: data may have been lost".
The spreadsheet appears to be ok though.

Created Unassigned: NPOI.XSSF - SetAutoFilter results in missing/unreadable xml in XLSX [14012]

$
0
0
Getting warning: "We found a problem with some content in 'SimpleReport '. Do you want us to try to recover as much as we can? If you trust the source of this workbook, click Yes." when opening saved Excel after setting auto-filter.
Example files attached.

Attempt to add data filter over all columns of Excel file using XSSFWorkbook

- NPOI Version 2.2.1
- XLSX workbook generated by Crystal Reports export in an ASP.net webforms application
- Excel version: Excel 2016


Crystal Reports XLSX Export - unmodified:
Code:

Response.Clear();
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
Response.AddHeader("Content-Disposition", string.Format("attachment; filename=\"{0}.xlsx\"", reportTitle));

using (Stream exportStream = _reportDocument.ExportToStream(ExportFormatType.ExcelWorkbook))
{
exportStream.CopyTo(Response.OutputStream);
}

Response.Flush();
Response.Close();
Response.End();


Generated file "SimpleReport - unmodified export.xlsx"
which opens in Excel without warning/error.


Crystal Reports XLSX Export - auto-filter added with XSSFWorkbook:
Code:

XSSFWorkbook workbook;
using (Stream reportStream = _reportDocument.ExportToStream(ExportFormatType.ExcelWorkbook))
{
workbook = new XSSFWorkbook(reportStream);
}

if (!string.IsNullOrWhiteSpace(filterCellRange))
{
ISheet sheet = workbook.GetSheetAt(0);
CellRangeAddress cellRange = new CellRangeAddress(sheet.FirstRowNum, sheet.LastRowNum, sheet.GetRow(sheet.FirstRowNum).FirstCellNum, sheet.GetRow(sheet.LastRowNum).LastCellNum - 1);
sheet.SetAutoFilter(cellRange);
}


Response.Clear();
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
Response.AddHeader("Content-Disposition", string.Format("attachment; filename=\"{0}.xlsx\"", reportTitle));

workbook.Write(Response.OutputStream);

Response.Flush();
Response.Close();
Response.End();


Generated file "SimpleReport - filter added with XSSFWorkbook.xlsx".


When opening the .xlsx file, Excel shows a dialog stating "We found a problem with some content in 'SimpleReport '. Do you want us to try to recover as much as we can? If you trust the source of this workbook, click Yes."

If you click "Yes", you get a dialog stating that "Excel was able to open the file by repairing or removing the unreadable content." and detail as follows: "Removed Part: /xl/styles.xml part with XML error. (Styles) Load error. Line 1, column 0.
Repaired Records: Cell information from /xl/worksheets/Sheet1.xml part".

It also points you to a log file with the contents:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<recoveryLog xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"><logFileName>error223040_01.xml</logFileName><summary>Errors were detected in file 'D:\work\AgeUK\AREP-66 - AgeUK MI (Management Information) Suite\TEST\SimpleReport Export\XLSX Export\SimpleReport - filter added with XSSFWorkbook - Copy.xlsx'</summary><removedParts><removedPart>Removed Part: /xl/styles.xml part with XML error. (Styles) Load error. Line 1, column 0.</removedPart></removedParts><repairedRecords><repairedRecord>Repaired Records: Cell information from /xl/worksheets/Sheet1.xml part</repairedRecord></repairedRecords></recoveryLog>

New Post: Pictures on DOCX file

$
0
0
Dear All,

I'm have to put a picture on a DOCX file using NPOI.

Using NPOI 2.1 I have no problem to do that using this code:
XWPFDocument doc = new XWPFDocument();
            XWPFParagraph p2 = doc.CreateParagraph();
            XWPFRun r2 = p2.CreateRun();
            r2.SetBold(true);
            r2.SetText("test");

            var widthEmus = (int)(400.0 * 9525);
            var heightEmus = (int)(300.0 * 9525);

            using (FileStream picData = new FileStream(imgPath, FileMode.Open, FileAccess.Read))
            {
                r2.AddPicture(picData, (int)PictureType.PNG, "image1", widthEmus, heightEmus);
            }

            using (FileStream sw = File.Create(outputfile))
            {
                doc.Write(sw);
            }
Anyway, using the version 2.2 this code does not work correctly sinche the create DOCX file cannot be open correctly using Word (but open office can open it!)

Do you have any idea on how to insert a Picture using version 2.2?

Thanks

Created Unassigned: Table1[Data1] can be resolved? [14014]

$
0
0
Hi.

Sheet sample:
```
|Data1|Data2|Data3|
|-----|-----|-----|
| 1| 2| 3|
| 4| 5| 6|
| 7| 8| 9|
```

Name Data1 is represented as __Table1[Data1]__. I can get actual cell range __=Sheet1!$A$2:$A$4__ if I delete and convert the table to ranges.


C# problem code:
```
XSSFWorkbook workbook = new XSSFWorkbook(fs);
var name = workbook.GetName("Data1");
var cells = new AreaReference(name.RefersToFormula);
```

AreaReference throws FormatException.

Another approach? I have tried ILSpy. Here is another one:
```
XSSFWorkbook workbook = new XSSFWorkbook(fs);
XSSFEvaluationWorkbook ev = XSSFEvaluationWorkbook.Create(workbook);
var name = workbook.GetName("Data1");
var ptgs = FormulaParser.Parse(name.RefersToFormula, ev);
```

Result:
* FormulaParseException: Specified named range 'Table1' does not exist in the current workbook.

Any good workaround?

Created Unassigned: FillForegroundColor is slow [14016]

$
0
0
I have a template and after filling it with values I set a background color but for a small file (about 6000 rows) it takes about 4 minutes. Whithout setting background color it takes only 8 seconds.

My code is:
var hssfworkbook = new XSSFWorkbook(file);
var sheet = hssfworkbook.GetSheetAt(0);

for (int i=0; i<sheet.LastRowNum; i++)
{
var currentCellStyle = hssfworkbook.CreateCellStyle();
currentCellStyle.FillForegroundColor = IndexedColors.Green.Index;
currentRow.Cells.ForEach(x=> x.CellStyle = currentCellStyle);
}

Updated Wiki: Home

$
0
0
Who are We
Neuzilla is the studio behind NPOI. For detail, you can check http://blog.neuzilla.com/.

 

 
 
What's NPOI
This project is the .NET version of POI Java project at http://poi.apache.org/. POI is an open source project which can help you read/write xls, doc, ppt files. It has a wide application.
 
For example, you can use it to
a. generate a Excel report without Microsoft Office suite installed on your server and more efficient than call Microsoft Excel ActiveX at background;
b. extract text from Office documents to help you implement full-text indexing feature (most of time this feature is used to create search engines).
c. extract images from Office documents
d. generate Excel sheets that contains formulas
 
 
Donate NPOI

支付宝捐款账号: tonyqus@163.com
Paypal: tonyqus@gmail.com


donate_btn
 
 
Advantage of NPOI
a. It's totally free to use
b. Cover most features of Excel (cell style, data format, formula and so on)
c. Support xls, xlsx, docx.
d. Designed to be interface-oriented (take a look at NPOI.SS namespace)
e. Support not only export but also import
f. .Net 2.0 based even for xlsx and docx (though we also support .NET 4.0)
g. Successful cases from all over the world
h. huge amout of basic examples
i. No dependency on isolated storage
 
To get the latest code, please visithttps://github.com/tonyqus/npoi.
 
 
Comments from NPOI users
image
image
image
image
image
 
 
Tutorial

NPOI on SNS
中文
QQ群: 189925337
 
English

System Requirement
VS2010 with .NET 4.0 runtime
VS2005 or VS2008 with .NET 2.0 Runtime (SP1)
vs2003 with .NET 1.1
Mono
medium trust environment in ASP.NET

 

 

 
Extensions
 

Updated Wiki: Documentation

$
0
0

Neuzilla is the software studio behind NPOI. Please follow us.

Our website: www.neuzilla.cn

 

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

Updated Wiki: Documentation

$
0
0

Neuzilla is the software studio behind NPOI. Please follow us.

Our website: www.neuzilla.cn

 

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

Updated Wiki: Home

$
0
0
Who are We
Neuzilla is the studio behind NPOI. For detail, you can check www.neuzilla.cn

 

 
 
What's NPOI
This project is the .NET version of POI Java project at http://poi.apache.org/. POI is an open source project which can help you read/write xls, doc, ppt files. It has a wide application.
 
For example, you can use it to
a. generate a Excel report without Microsoft Office suite installed on your server and more efficient than call Microsoft Excel ActiveX at background;
b. extract text from Office documents to help you implement full-text indexing feature (most of time this feature is used to create search engines).
c. extract images from Office documents
d. generate Excel sheets that contains formulas
 
 
Donate NPOI

支付宝捐款账号: tonyqus@163.com
Paypal: tonyqus@gmail.com


donate_btn
 
 
Advantage of NPOI
a. It's totally free to use
b. Cover most features of Excel (cell style, data format, formula and so on)
c. Support xls, xlsx, docx.
d. Designed to be interface-oriented (take a look at NPOI.SS namespace)
e. Support not only export but also import
f. .Net 2.0 based even for xlsx and docx (though we also support .NET 4.0)
g. Successful cases from all over the world
h. huge amout of basic examples
i. No dependency on isolated storage
 
To get the latest code, please visithttps://github.com/tonyqus/npoi.
 
 
Comments from NPOI users
image
image
image
image
image
 
 
Tutorial

NPOI on SNS
中文
QQ群: 189925337
 
English

System Requirement
VS2010 with .NET 4.0 runtime
VS2005 or VS2008 with .NET 2.0 Runtime (SP1)
vs2003 with .NET 1.1
Mono
medium trust environment in ASP.NET

 

 

 
Extensions
 

Updated Wiki: Temporary Post Used For Theme Detection (f5c60008-8a13-478d-b728-93753f95e810 - 3bfe001a-32de-4114-a6b4-4005b770f6d7)

$
0
0

This is a temporary post that was not deleted. Please delete this manually. (72069b14-ac87-4dde-97bf-8cf10c82dfc9 - 3bfe001a-32de-4114-a6b4-4005b770f6d7)

New Post: add pdf stream into worksheet

$
0
0
Is there any plans to support it in future releases?
Viewing all 1621 articles
Browse latest View live