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

New Post: How to rowspan and colspan by this library in excel 2007 format ( xlsx)

$
0
0
Please I want to create xlsx sheet that contains rowspan and colspan..
Is this library can help me to do that??

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: antondd **

Thanks for the comment nvanesch, adding the ICSharpCode.SharpZipLib library has indeed solved my problem with corrupted xlsx files.

Created Unassigned: Conditional formats in xlsx not shown in LibreOffice calc [13375]

$
0
0
Adding conditional formats (using the example file of NPOI 2.1.3) to an xlsx spreadsheet are missing when the file is opened in LibreOffice Calc. Excel opens correctly after "repairing" the file. If the "repaired" file is saved from excel the formats also appear in Calc.
Some digging in the xml data revealed that NPOI sets all "priority" fields in the cfRule entry of the sheet to "0".
It seems there is a line missing in the sheet.cs module .\ooxml\OpenXmlFormats\Speradsheet\Sheet.cs which copies the CT_CFRule fields to the XML file. Adding the priority field in the Set function fixes the issue.

public void Set(CT_CfRule src)
{
this.formula = src.formula;
this.stopIfTrue = src.stopIfTrue;
this.bottom = src.bottom;
this.percent = src.percent;
this.dxfId = src.dxfId;
// added priority field transfer copy
this.priority = src.priority;
this.@operator = src.@operator;
this.type = src.type;
this.equalAverage = src.equalAverage;
this.aboveAverage = src.aboveAverage;
this.colorScale = src.colorScale;
this.dataBar = src.dataBar;
this.iconSet = src.iconSet;
this.extLst = src.extLst;
}

New Post: Worksheet protection. IsLocked=false not working

$
0
0
Same problem here with XSSF. Downgrade is no option, will dig into the code.

New Post: Worksheet protection. IsLocked=false not working

Commented Unassigned: Conditional formats in xlsx not shown in LibreOffice calc [13375]

$
0
0
Adding conditional formats (using the example file of NPOI 2.1.3) to an xlsx spreadsheet are missing when the file is opened in LibreOffice Calc. Excel opens correctly after "repairing" the file. If the "repaired" file is saved from excel the formats also appear in Calc.
Some digging in the xml data revealed that NPOI sets all "priority" fields in the cfRule entry of the sheet to "0".
It seems there is a line missing in the sheet.cs module .\ooxml\OpenXmlFormats\Speradsheet\Sheet.cs which copies the CT_CFRule fields to the XML file. Adding the priority field in the Set function fixes the issue.

public void Set(CT_CfRule src)
{
this.formula = src.formula;
this.stopIfTrue = src.stopIfTrue;
this.bottom = src.bottom;
this.percent = src.percent;
this.dxfId = src.dxfId;
// added priority field transfer copy
this.priority = src.priority;
this.@operator = src.@operator;
this.type = src.type;
this.equalAverage = src.equalAverage;
this.aboveAverage = src.aboveAverage;
this.colorScale = src.colorScale;
this.dataBar = src.dataBar;
this.iconSet = src.iconSet;
this.extLst = src.extLst;
}
Comments: ** Comment from web user: tonyqus **

This will be fixed!

New Post: How to igrone cell inconsistent formula error

$
0
0
Hi,
I am using NPOI V 2.0.6.0 to create XSSFWorkbook. For some cells I am setting Formulas which are kinda inconsistent. So is there a way I can ignore the cell error from code?

Image

Your help is greatly appreciated

Thanks!

New Post: Protect Sheet with AutoFilters

$
0
0
I am trying to protect a xls sheet which has a filter row on top, but when i call:
sheet.ProtectSheet("xyz");
filters dont respond, is there a way to protect sheet while allowing autofilters?

Commented Unassigned: 通过网页下载xlsx文件报错,丢失文件 [13361]

$
0
0
运行代码:

FileStream file = new FileStream("test.xlsx", FileMode.Open, FileAccess.Read);//读入excel模板
var workbook = new XSSFWorkbook(file);
MemoryStream ms = new MemoryStream();
workbook.Write(ms);//写入内存流
byte[] data = ms.ToArray();
HttpResponse response = System.Web.HttpContext.Current.Response;
response.Clear();
response.Charset = "UTF-8";
response.ContentType = "application/vnd-excel";
System.Web.HttpContext.Current.Response.AddHeader("Content-Disposition", string.Format("attachment; filename=abc.xlsx"));
System.Web.HttpContext.Current.Response.BinaryWrite(data);
Comments: ** Comment from web user: tonyqus **

经测试,用2.1.3不能重现您的问题。请自行寻找原因,如果有预算,可以发邮件到support@neuzilla.com上个case,我们会提供远程协助,帮你排查问题。

Closed Unassigned: 通过网页下载xlsx文件报错,丢失文件 [13361]

$
0
0
运行代码:

FileStream file = new FileStream("test.xlsx", FileMode.Open, FileAccess.Read);//读入excel模板
var workbook = new XSSFWorkbook(file);
MemoryStream ms = new MemoryStream();
workbook.Write(ms);//写入内存流
byte[] data = ms.ToArray();
HttpResponse response = System.Web.HttpContext.Current.Response;
response.Clear();
response.Charset = "UTF-8";
response.ContentType = "application/vnd-excel";
System.Web.HttpContext.Current.Response.AddHeader("Content-Disposition", string.Format("attachment; filename=abc.xlsx"));
System.Web.HttpContext.Current.Response.BinaryWrite(data);

Created Unassigned: Exception opening a file in read-only mode [13397]

$
0
0
If I open an xlsx file with
```
workBook = new XSSFWorkbook(OPCPackage.Open(path,PackageAccess.READ));
```
it later throws an exception
```
NPOI.POIXMLException
en NPOI.POIXMLDocumentPart.CreateRelationship(POIXMLRelation descriptor, POIXMLFactory factory, Int32 idx, Boolean noRelation)
en NPOI.POIXMLDocumentPart.CreateRelationship(POIXMLRelation descriptor, POIXMLFactory factory)
en NPOI.XSSF.UserModel.XSSFWorkbook.OnDocumentRead()
en NPOI.POIXMLDocument.Load(POIXMLFactory factory)
en NPOI.XSSF.UserModel.XSSFWorkbook..ctor(OPCPackage pkg)
```
containing
```
System.InvalidOperationException "Operation not allowed, document open in read only mode!"
en NPOI.OpenXml4Net.OPC.OPCPackage.ThrowExceptionIfReadOnly()
en NPOI.OpenXml4Net.OPC.OPCPackage.CreatePart(PackagePartName partName, String contentType, Boolean loadRelationships)
en NPOI.OpenXml4Net.OPC.OPCPackage.CreatePart(PackagePartName partName, String contentType)
en NPOI.POIXMLDocumentPart.CreateRelationship(POIXMLRelation descriptor, POIXMLFactory factory, Int32 idx, Boolean noRelation)
```
It works if I use read&write PackageAccess.
Doesn't NPOI allow to simply read the file?

Created Unassigned: NPOI interprets date formats differently [13398]

$
0
0
I have an _xlsx_ file with several dates.
One cell appears in Excel 2007 (configured as Spanish, Spain, international) as "01/02/2003 4:05" (that is 1st February 2003). The cell format appears as "dd/mm/aaaa h:mm" in Excel. NPOI gets "2/1/03 4:05".
What appears as "01/12/2001" is read by NPOI as "12/1/01". The cell format is "*14/03/2001" in Excel.
What appears as "23:05:00" is read by NPOI as "11:05:00 ". The cell format is "*13:30:55" in Excel.

The code I use to read the file is:
```
DataFormatter dataFormatter= new DataFormatter(CultureInfo.CurrentCulture); // es-ES
// ...
object cellValue= dataFormatter.FormatCellValue(ijCell);
```

In some cases, I see that NPOI is applying the predefined formats from _NPOI.SS.UserModel.BuiltinFormats_, but they seem not to match what Spanish Excel does.

Is there a way to make NPOI use the same format as Spanish Excel?

Commented Unassigned: NPOI interprets date formats differently [13398]

$
0
0
I have an _xlsx_ file with several dates.
One cell appears in Excel 2007 (configured as Spanish, Spain, international) as "01/02/2003 4:05" (that is 1st February 2003). The cell format appears as "dd/mm/aaaa h:mm" in Excel. NPOI gets "2/1/03 4:05".
What appears as "01/12/2001" is read by NPOI as "12/1/01". The cell format is "*14/03/2001" in Excel.
What appears as "23:05:00" is read by NPOI as "11:05:00 ". The cell format is "*13:30:55" in Excel.

The code I use to read the file is:
```
DataFormatter dataFormatter= new DataFormatter(CultureInfo.CurrentCulture); // es-ES
// ...
object cellValue= dataFormatter.FormatCellValue(ijCell);
```

In some cases, I see that NPOI is applying the predefined formats from _NPOI.SS.UserModel.BuiltinFormats_, but they seem not to match what Spanish Excel does.

Is there a way to make NPOI use the same format as Spanish Excel?
Comments: ** Comment from web user: davidmef **

I am using an NPOI version from 2.0 but it also happens with 2.1.1.

Commented Unassigned: Exception opening a file in read-only mode [13397]

$
0
0
If I open an xlsx file with
```
workBook = new XSSFWorkbook(OPCPackage.Open(path,PackageAccess.READ));
```
it later throws an exception
```
NPOI.POIXMLException
en NPOI.POIXMLDocumentPart.CreateRelationship(POIXMLRelation descriptor, POIXMLFactory factory, Int32 idx, Boolean noRelation)
en NPOI.POIXMLDocumentPart.CreateRelationship(POIXMLRelation descriptor, POIXMLFactory factory)
en NPOI.XSSF.UserModel.XSSFWorkbook.OnDocumentRead()
en NPOI.POIXMLDocument.Load(POIXMLFactory factory)
en NPOI.XSSF.UserModel.XSSFWorkbook..ctor(OPCPackage pkg)
```
containing
```
System.InvalidOperationException "Operation not allowed, document open in read only mode!"
en NPOI.OpenXml4Net.OPC.OPCPackage.ThrowExceptionIfReadOnly()
en NPOI.OpenXml4Net.OPC.OPCPackage.CreatePart(PackagePartName partName, String contentType, Boolean loadRelationships)
en NPOI.OpenXml4Net.OPC.OPCPackage.CreatePart(PackagePartName partName, String contentType)
en NPOI.POIXMLDocumentPart.CreateRelationship(POIXMLRelation descriptor, POIXMLFactory factory, Int32 idx, Boolean noRelation)
```
It works if I use read&write PackageAccess.
Doesn't NPOI allow to simply read the file?
Comments: ** Comment from web user: davidmef **

I am using an NPOI version from 2.0 but it also happens with 2.1.1.

Updated Wiki: Documentation

$
0
0

Updated Wiki: Documentation

$
0
0

Commented Unassigned: Underline work incorrectly [12655]

$
0
0
Workbook do not write correct information about font's underline.
I made some changes which allow workbook to save information correctly.
__Styles.cs__
```
// why to set single line as as default option ?

public CT_UnderlineProperty()
{
// this.valField = ST_UnderlineValues.single;
this.valField = ST_UnderlineValues.none;
}

public ST_UnderlineValues val
{
get
{
// return (null == valField) ? ST_UnderlineValues.single : (ST_UnderlineValues)this.valField;
return (null == valField) ? ST_UnderlineValues.none : (ST_UnderlineValues)this.valField;
}
set
{
this.valField = value;
}
}
```
__XSSFFont__

```
public FontUnderlineType Underline
{
get
{
CT_UnderlineProperty underline = _ctFont.sizeOfUArray() == 0 ? null : _ctFont.GetUArray(0);
if (underline != null)
{
return (FontUnderlineType)underline.val;

//FontUnderline val = FontUnderline.ValueOf((int)underline.val);
//return (FontUnderlineType)val.ByteValue;
}
return (FontUnderlineType)FontUnderline.NONE.ByteValue;
}
set
{
SetUnderline(value);
}
}

internal void SetUnderline(FontUnderlineType underline)
{
if (underline == FontUnderlineType.None && _ctFont.sizeOfUArray() > 0)
{
_ctFont.SetUArray(null);
}
else
{
CT_UnderlineProperty ctUnderline = _ctFont.sizeOfUArray() == 0 ? _ctFont.AddNewU() : _ctFont.GetUArray(0);
ST_UnderlineValues val = (ST_UnderlineValues)FontUnderline.ValueOf(underline).ByteValue; //.Value;
ctUnderline.val = val;
}
}

```
Comments: ** Comment from web user: zxm13588 **

When I using version 2.0.6,I have the same problem.

Commented Unassigned: Underline work incorrectly [12655]

$
0
0
Workbook do not write correct information about font's underline.
I made some changes which allow workbook to save information correctly.
__Styles.cs__
```
// why to set single line as as default option ?

public CT_UnderlineProperty()
{
// this.valField = ST_UnderlineValues.single;
this.valField = ST_UnderlineValues.none;
}

public ST_UnderlineValues val
{
get
{
// return (null == valField) ? ST_UnderlineValues.single : (ST_UnderlineValues)this.valField;
return (null == valField) ? ST_UnderlineValues.none : (ST_UnderlineValues)this.valField;
}
set
{
this.valField = value;
}
}
```
__XSSFFont__

```
public FontUnderlineType Underline
{
get
{
CT_UnderlineProperty underline = _ctFont.sizeOfUArray() == 0 ? null : _ctFont.GetUArray(0);
if (underline != null)
{
return (FontUnderlineType)underline.val;

//FontUnderline val = FontUnderline.ValueOf((int)underline.val);
//return (FontUnderlineType)val.ByteValue;
}
return (FontUnderlineType)FontUnderline.NONE.ByteValue;
}
set
{
SetUnderline(value);
}
}

internal void SetUnderline(FontUnderlineType underline)
{
if (underline == FontUnderlineType.None && _ctFont.sizeOfUArray() > 0)
{
_ctFont.SetUArray(null);
}
else
{
CT_UnderlineProperty ctUnderline = _ctFont.sizeOfUArray() == 0 ? _ctFont.AddNewU() : _ctFont.GetUArray(0);
ST_UnderlineValues val = (ST_UnderlineValues)FontUnderline.ValueOf(underline).ByteValue; //.Value;
ctUnderline.val = val;
}
}

```
Comments: ** Comment from web user: serjn **

I use 2.0.6

Created Unassigned: Problem with .xlsx file for saving same workbook second time [13401]

$
0
0
Hi Team, I am developing .xls and .xlsx excel file using NPOI 2.1.3 beta version. I have a requirement of saving the same excel workbook multiple times.
With .xls file working good but .xlsx resulted corrupted excel.
But first time saved .xlsx file is working good, Second time saved causes the corrupted excel.

Commented Unassigned: Problem with .xlsx file for saving same workbook second time [13401]

$
0
0
Hi Team, I am developing .xls and .xlsx excel file using NPOI 2.1.3 beta version. I have a requirement of saving the same excel workbook multiple times.
With .xls file working good but .xlsx resulted corrupted excel.
But first time saved .xlsx file is working good, Second time saved causes the corrupted excel.
Comments: ** Comment from web user: tonyqus **

Can you upload the original xlsx file, first-time-saved .xlsx and second-time-saved .xlsx

Viewing all 1621 articles
Browse latest View live


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