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

New Post: Writing image to HSSFHeader and HSSFFooter

$
0
0
My requirement is to write data to excel Header & Footer section which is accomplished using the following code. HSSFHeader header=this.sheet.getHeader(); header.setCenter("XXX"); header.setLeft("YYY"); header.setRight(HSSFHeader.page()); HSSFFooter footer=this.sheet.getFooter(); footer.setCenter("XXX"); footer.setLeft("YYY"); footer.setRight("ZZZ"); My question is how can I write an image (for eg:a logo)to the header/footer? setCenter() setLeft() setRight() alll expects String Please help me to resolve the issue.

Reviewed: NPOI 1.2.5 (авг 25, 2016)

$
0
0
Rated 5 Stars (out of 5) - Excellent and stable release. Unfortunately the newest versions have memory leak problems.

Created Unassigned: IPatternFormatting.FillPattern should be of type FillPattern, not short [13973]

$
0
0
Looks like I missed at least once place when I revamped the API a while back, fixing all of the 'short' and 'int' properties to be the appropriate enum types instead.

I just noticed that I missed IPatternFormatting.FillPattern.

Created Unassigned: XSSFPatternFormatting does not have a way to set an XSSFColor [13974]

$
0
0
This API may be missing because it's not possible, I don't know...

I'm hoping it's just something that's been overlooked :)

For now I can just use the IndexedColors, so this isn't a high priority...

Commented Unassigned: IPatternFormatting.FillPattern should be of type FillPattern, not short [13973]

$
0
0
Looks like I missed at least once place when I revamped the API a while back, fixing all of the 'short' and 'int' properties to be the appropriate enum types instead.

I just noticed that I missed IPatternFormatting.FillPattern.
Comments: ** Comment from web user: jstedfast **

I've submitted a PR to fix this here: https://github.com/tonyqus/npoi/pull/98

Commented Unassigned: XSSFPatternFormatting does not have a way to set an XSSFColor [13974]

$
0
0
This API may be missing because it's not possible, I don't know...

I'm hoping it's just something that's been overlooked :)

For now I can just use the IndexedColors, so this isn't a high priority...
Comments: ** Comment from web user: jstedfast **

I gave a quick look at the code last night and I *suspect* that I could probably clone the logic from XSSFCellStyle's `SetFillForegroundColor(XSSFColor)` over to XSSFPatternFormatting, but I am just guessing :)

Commented Unassigned: Incorrect value of calculation with INT operator [13924]

$
0
0
In the following example I try to calculate different formulas, but the results of calculation are sometimes incorrects (and really understandables) :

```
var workbook = new HSSFWorkbook();
var sheet = workbook.CreateSheet();
var row = sheet.CreateRow(0);
var cell = row.CreateCell(0);
var evaluator = workbook.GetCreationHelper().CreateFormulaEvaluator();

// should be 6.0 => OK
cell.SetCellFormula("INT(6.99)");
var cellValue = evaluator.Evaluate(cell);
var result = cellValue.NumberValue;

// should be 6.0 => KO : 7.0 is returned
var cell1 = row.CreateCell(1);
cell1.SetCellFormula("INT(6.991)");
var cellValue1 = evaluator.Evaluate(cell1);
var result1 = cellValue1.NumberValue;

// should be 6.0 => OK
var cell2 = row.CreateCell(2);
cell2.SetCellFormula("INT(6.9900000000000005)");
var cellValue2 = evaluator.Evaluate(cell2);
var result2 = cellValue2.NumberValue;

// should be 6.0 => KO : 7.0 is returned
var cell3 = row.CreateCell(3);
cell3.SetCellFormula("INT(6.9900000000000007)");
var cellValue3 = evaluator.Evaluate(cell3);
var result3 = cellValue3.NumberValue;
```

Am I doing something wrong ?
Comments: ** Comment from web user: brobic **

Hello,

I have exactly the same problem.

Have you found a solution to resolve it?

It generates multiple bugs in our application...

Thanks by advance.

New Post: How To Convert Shape to Image

$
0
0
I have requirement to get all images including shapes from excel (.xls and .xlsx) and save it in directory, I've trying using HSSFWorkbook.GetAllPictures(), it does get all images but not the shapes, so i find another method and i found GetSheetAt(0).DrawingPatriarch.

here snippet of my code :
var dr = workbook.GetSheetAt(sht).DrawingPatriarch;
HSSFPatriarch pat = (HSSFPatriarch)dr;
var shape = pat.Children;
int i = 0;
foreach (var s in shape)
{
    string patType = s.GetType().ToString();
    switch (patType)
    {
        case "NPOI.HSSF.UserModel.HSSFSimpleShape":
            {
                var simpleshape = (HSSFSimpleShape)s;

                /*Save Shape*/

                break;
            }
        case "NPOI.HSSF.UserModel.HSSFPicture":
            {
                var pic = (HSSFPicture)s;
                byte[] data = pic.PictureData.Data;

                /*Code to Save Image From Byte[]*/

                break;
            }
        default: break;
    }
}
With that code I'm able to get all images and shapes that I want, but I can only Save ImageData (HSSFPicture) to directory, and I can't find any method to Save Shapes Data (HSSFSimpleShape) or convert it to Image.

Question is, how to convert HSSFSimpleShape data to Image? Is that Possible? Is there anything I miss?


Hope Someone can help, Thanks

Commented Unassigned: Incorrect value of calculation with INT operator [13924]

$
0
0
In the following example I try to calculate different formulas, but the results of calculation are sometimes incorrects (and really understandables) :

```
var workbook = new HSSFWorkbook();
var sheet = workbook.CreateSheet();
var row = sheet.CreateRow(0);
var cell = row.CreateCell(0);
var evaluator = workbook.GetCreationHelper().CreateFormulaEvaluator();

// should be 6.0 => OK
cell.SetCellFormula("INT(6.99)");
var cellValue = evaluator.Evaluate(cell);
var result = cellValue.NumberValue;

// should be 6.0 => KO : 7.0 is returned
var cell1 = row.CreateCell(1);
cell1.SetCellFormula("INT(6.991)");
var cellValue1 = evaluator.Evaluate(cell1);
var result1 = cellValue1.NumberValue;

// should be 6.0 => OK
var cell2 = row.CreateCell(2);
cell2.SetCellFormula("INT(6.9900000000000005)");
var cellValue2 = evaluator.Evaluate(cell2);
var result2 = cellValue2.NumberValue;

// should be 6.0 => KO : 7.0 is returned
var cell3 = row.CreateCell(3);
cell3.SetCellFormula("INT(6.9900000000000007)");
var cellValue3 = evaluator.Evaluate(cell3);
var result3 = cellValue3.NumberValue;
```

Am I doing something wrong ?
Comments: ** Comment from web user: ebyrob **

This is controlled in the source code here:

main\SS\Formula\Functions\Int.cs

public class Int : OneArg
{

public override double Evaluate(double d)
{
if (d > 0)
return Math.Round(d - 0.49);
else
return Math.Round(d - 0.5);
}

}

Should be Math.Floor(d) instead of Round I think.

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
 
Our Sponsor (赞助商)
 
E-iceblue is a community sponsor of NPOI. 提供中文技术支持
Don't forget to have a try on Free Spire.XLS
XLS
 
 
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: 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
 
Our Sponsor (赞助商)
 
E-iceblue is a community sponsor of NPOI. 提供中文技术支持
Don't forget to have a try on Free Spire.XLS
XLS
 
 
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
 

Commented Unassigned: Incorrect value of calculation with INT operator [13924]

$
0
0
In the following example I try to calculate different formulas, but the results of calculation are sometimes incorrects (and really understandables) :

```
var workbook = new HSSFWorkbook();
var sheet = workbook.CreateSheet();
var row = sheet.CreateRow(0);
var cell = row.CreateCell(0);
var evaluator = workbook.GetCreationHelper().CreateFormulaEvaluator();

// should be 6.0 => OK
cell.SetCellFormula("INT(6.99)");
var cellValue = evaluator.Evaluate(cell);
var result = cellValue.NumberValue;

// should be 6.0 => KO : 7.0 is returned
var cell1 = row.CreateCell(1);
cell1.SetCellFormula("INT(6.991)");
var cellValue1 = evaluator.Evaluate(cell1);
var result1 = cellValue1.NumberValue;

// should be 6.0 => OK
var cell2 = row.CreateCell(2);
cell2.SetCellFormula("INT(6.9900000000000005)");
var cellValue2 = evaluator.Evaluate(cell2);
var result2 = cellValue2.NumberValue;

// should be 6.0 => KO : 7.0 is returned
var cell3 = row.CreateCell(3);
cell3.SetCellFormula("INT(6.9900000000000007)");
var cellValue3 = evaluator.Evaluate(cell3);
var result3 = cellValue3.NumberValue;
```

Am I doing something wrong ?
Comments: ** Comment from web user: Scampeon **

Thanks a lot !

This code corrects the problem
```
public class Int : OneArg
{
public override double Evaluate(double d)
{
return Math.Floor(d);
}
}
```

Both Excel and Math.Floor give the same result
```
- INT(-2) => -2
- INT(-1,9) => -2
- INT(-2,1) => -3
- INT(6,99) => 6
- INT(6,991) => 6
- INT(6,9900000000000005) => 6
- INT(6,9900000000000007) => 6

- Math.Floor(-2) => -2
- Math.Floor(-1.9) => -2
- Math.Floor(-2.1) => -3
- Math.Floor(6.99) => 6
- Math.Floor(6.991) => 6
- Math.Floor(6.9900000000000005) => 6
- Math.Floor(6.9900000000000007) => 6
```

New Post: Conditional Format is not work for XSSFWorkbook

$
0
0
this work for HSSFWorkbook, but not work for XSSFWorkbook.
is this a bug?
HSSFWorkbook wk = new HSSFWorkbook();  // 2003
//XSSFWorkbook wk = new XSSFWorkbook();    // 2007

ISheet sheet = wk.CreateSheet("Report");
ISheetConditionalFormatting ConditionalFormatting = sheet.SheetConditionalFormatting;

IConditionalFormattingRule LessThan1_33 = ConditionalFormatting.CreateConditionalFormattingRule(ComparisonOperator.LessThan, "1.33", null);
IPatternFormatting patternFmt1 = LessThan1_33.CreatePatternFormatting();
patternFmt1.FillBackgroundColor = NPOI.HSSF.Util.HSSFColor.Red.Index;
CellRangeAddress[] regions1 = { new CellRangeAddress(1, Designators.Count, 8, 8) };
ConditionalFormatting.AddConditionalFormatting(regions1, LessThan1_33);

Updated Wiki: Temporary Post Used For Theme Detection (634c749c-1bfd-4fed-ba30-a0b812defd82 - 3bfe001a-32de-4114-a6b4-4005b770f6d7)

$
0
0

This is a temporary post that was not deleted. Please delete this manually. (7aff0fb3-b046-410b-b5db-112606f50c57 - 3bfe001a-32de-4114-a6b4-4005b770f6d7)

Created Unassigned: RecordFormatException: Unable to construct record instance [13988]

$
0
0
Getting this error while accessing the Password Protected Excel file..

Inner Exception: {"Unknown encryption info 4"}.

Adding the code I have used to process this..

FileStream file = new FileStream(filefullPath, FileMode.Open, FileAccess.Read);
Biff8EncryptionKey.CurrentUserPassword = password;
IWorkbook hssfworkbook = new HSSFWorkbook(file);

Please advice.. I am not able to find.. what is causing this issue..

Attached exception details in the screenshot below..

New Post: Problem working with Excel 2007

$
0
0
Please ignore: Posted to incorrect thread.

New Post: Formula recalculation

$
0
0
Im' using the version 2.3.1 and when I call the HSSFFormulaEvaluator.EvaluateAllFormulaCells I get error:

Unexpected eval class (MissingArgEval) in NPOI.HSSF.UserModel.HSSFFormulaEvaluator.EvaluateFormulaCellValue(ICell cell)
in NPOI.HSSF.UserModel.HSSFFormulaEvaluator.EvaluateFormulaCell(ICell cell)
in NPOI.HSSF.UserModel.HSSFFormulaEvaluator.EvaluateAllFormulaCells(IWorkbook wb, IFormulaEvaluator evaluator)
in NPOI.HSSF.UserModel.HSSFFormulaEvaluator.EvaluateAllFormulaCells(HSSFWorkbook wb)

I don't understand which cell cause the Error.

It's possibile the download the source code of the last version of NOI?

Created Unassigned: EvaluateAllFormulaCells error [13992]

$
0
0
Im' using the version 2.3.1 and when I call the HSSFFormulaEvaluator.EvaluateAllFormulaCells I get error:

Unexpected eval class (MissingArgEval) in NPOI.HSSF.UserModel.HSSFFormulaEvaluator.EvaluateFormulaCellValue(ICell cell)
in NPOI.HSSF.UserModel.HSSFFormulaEvaluator.EvaluateFormulaCell(ICell cell)
in NPOI.HSSF.UserModel.HSSFFormulaEvaluator.EvaluateAllFormulaCells(IWorkbook wb, IFormulaEvaluator evaluator)
in NPOI.HSSF.UserModel.HSSFFormulaEvaluator.EvaluateAllFormulaCells(HSSFWorkbook wb)

I don't understand which cell cause the Error.

It's possibile the download the source code of the last version of NOI or know the cell that cause the error?

thanks

Reviewed: NPOI 2.1.3.1 (十月 15, 2016)

$
0
0
Rated 5 Stars (out of 5) - It' easy to use.

Created Unassigned: The supplied POIFSFileSystem does not contain a BIFF8 'Workbook' entry. Is it really an excel file? [13997]

$
0
0
I am using NPOI to process data in Excel 2003 (xls) file. This is my code

if (excelFormat.Equals(Constants.XLS_EXCEL_FORMAT))
{
using (FileStream file = new FileStream(filePath, FileMode.Open, FileAccess.Read))
{
wbImportXLS = new HSSFWorkbook(file); //crash here
}
sheetImport = wbImportXLS.GetSheet(CommonController.GetFirstSheetNameInFileXLS(wbImportXLS));
isXLS = true;
}

However I receive an error

"The supplied POIFSFileSystem does not contain a BIFF8 'Workbook' entry. Is it really an excel file?"

I checked my excel file. That is not contain any password. I used Apache Tika and received this information

"Application-Name: Microsoft Excel
Author:
Category:
Comments:
Company:
Content-Length: 13312
Content-Type: application/vnd.ms-excel
Creation-Date: 2016-10-03T11:22:28Z
Keywords:
Last-Author:
Manager:
X-Parsed-By: org.apache.tika.parser.DefaultParser
X-Parsed-By: org.apache.tika.parser.microsoft.OfficeParser
X-TIKA:digest:MD5: f5a1e42d6d1674aadd0e03e8583cfbb3
X-TIKA:digest:SHA256: bffb673b20f3929d62e20514696d39406d524716f002dbec25284b64995ae9e0
comment:
cp:category:
cp:subject:
creator:
dc:creator:
dc:subject:
dc:title:
dcterms:created: 2016-10-03T11:22:28Z
extended-properties:Application: Microsoft Excel
extended-properties:Company:
extended-properties:Manager:
meta:author:
meta:creation-date: 2016-10-03T11:22:28Z
meta:keyword:
meta:last-author:
resourceName: TIKA.xls
subject:
title:
w:comments: "

However, if I open excel file and re-save, then my code work fine.
Viewing all 1621 articles
Browse latest View live


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