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

Created Unassigned: protect sheet grayed out for the worksheets copied from other workbook [13453]

$
0
0
hi

I have a workbook with some of worksheets copied from the other workbooks, but the issue is when right click the tab of some sheets, the protect sheet option is grayed out, those sheets((with formula)) may be more complex than other simple sheets(just data), after I activated a simple sheet, then the protect sheet option is available for all sheets , it seems the CopyTo doesn't work properly.

I want to try the version 1.2.5, but I don't know how to copy the worksheet from the other workbook, there is no such functionality such as CopyTo, CopySheets, If anyone knows a way, please let me know

Thanks,
Solo

New Post: How to pass a stream (excel generated file) back to an Angular application

$
0
0
Hello I am in the progress of migrating a MVC application to a SPA with angular. In the past application I was able to pass a Filestream object from the MVC controller back to my page which prompted the user to download the generated excel file. Within the SPA I am now working with a webapi controller as well as angular, services and controllers. I can pass the reporting object to the api and generate the memory stream from the NPOI assembly but I am stuck on how to pass this back from the webapi to the client to prompt them to download.

Here is the webapi method I have so far:
[HttpPost]
public HttpResponseMessage ExportReport([FromBody]DTOs.Report report)
{
  try
     {
      IReportPersistenceManager manager = ContainerConfigurator.Instance.Resolve<IReportPersistenceManager>();

      MemoryStream ms = new MemoryStream();
      //we have to pass to the NOPI assemble file type as well as file name 
     //since we only deal with excel for now we will set it but this could be configured later.
      long id = report.ReportId;
      string mimeType = "application/vnd.ms-excel";
      string filename = "unknown";
      manager.ExportDataToExcel(id, (name, mime) =>
      {
       mimeType = mime;
       filename = name;
       return ms;
      });
     ms.Position = 0;

    var response = new HttpResponseMessage();
    response.Content = new ByteArrayContent(ms.ToArray());
    response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/vnd.ms-excel");       
   return (response);
   }
   catch (Exception)
   {
   //error
   return new HttpResponseMessage(System.Net.HttpStatusCode.BadRequest);
   }
}
Based upon what I have read using HttpResponseMessge looks to be teh right direction but I am stuck on how to get this object once returned to unravel and prompt the user to download the file. I may be way off on the approach but I was wondering if anyone has used NPOI with Angular or some other similar SPA framework and what was needed to get the download to fire.

I've also posted this question on stackoverflow for reference

I'd really appreciate any guidance or suggestions on an approach

thank you

Created Unassigned: 【XSSFCellStyle.IsLocked = false】不起作用 [13456]

$
0
0
```
public static void Test()
{
var wb = new XSSFWorkbook();
var s0 = wb.CreateCellStyle();
s0.IsLocked = true;
var s1 = wb.CreateCellStyle();
s1.IsLocked = false;

var ws = wb.CreateSheet();
var r0 = ws.CreateRow(0);
var c0 = r0.CreateCell(0);
c0.SetCellValue("已锁定");
c0.CellStyle = s0;
var c1 = r0.CreateCell(1);
c1.SetCellValue("未锁定");
c1.CellStyle = s1;

ws.ProtectSheet("123");

var fn = Path.ChangeExtension(Path.GetTempFileName(), "xlsx");
using (var ms = File.OpenWrite(fn)) wb.Write(ms);
Process.Start(fn);
}
```

生成的xlsx文件中的两个单元格均不能编辑,在Excel里看到的“设置单元格格式->保护->锁定”都是被勾上的。

NPOI 2.1.3 版本。

HSSF里面这个功能正常。

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

I have also experienced this issue on xlsx files,Win8.1,vs2013,NPOI 2.1.3beta。

New Post: AutoSizeColumn got slow in NPOI 2.0

$
0
0
This issue is much more pressing than one would think. To extract 70k rows (around 25 columns) without autosizing took about 1 minute, I'm rarely able to extract the same amount with autosizing due to huge CPU load. This not only slows down the process, but hogs up all server resources so anyone within same application pool gets basically locked out of the application. I assume there might be some issues with our configuration, but we never saw this behavior before we upgraded to new NPOI version.

Please advise on alternative ways to sort this, it's not uncommon for us to extract over 10k rows, but anything over couple of thousand yields unacceptable results.

New Post: XSSF Performance: degrade when creating large number of rows

$
0
0
Noticed a thread on this subject from a couple years back. I have updated our code to use the latest beta release. Still experiencing the same performance degradation as more rows are being created. 700 rows are taking 6 minutes and 40 seconds consistently. Each row only has 6 columns. Any ideas on why it's taking so long to create rows? Here's an example of how the rows are being generated.

using NPOI.SS.UserModel;
using NPOI.SS.Util;
using NPOI.XSSF.UserModel;

int rowNumber = 0;
int columnNumber = 0;

private IRow CreateRow()
{
var row = sheet.CreateRow(rowNumber);
rowNumber++;
return row;
}

private ICell CreateCell(IRow row, object cellValue, ICellStyle cellStyle, int width = 0)
{
dynamic value = "";

var cell = row.CreateCell(columnNumber);
if (width != 0)
    sheet.SetColumnWidth(columnNumber, width);
else
    sheet.AutoSizeColumn(columnNumber);

if (cellValue is int)
    value = (int)cellValue;
else if (cellValue is string)
    value = (string)cellValue;
else if (cellValue is bool)
    value = (bool)cellValue;
else if (cellValue is double)
    value = (double)cellValue;

cell.SetCellValue(value);
cell.CellStyle = cellStyle;
columnNumber++;

return cell;
}

private void CreateOpportunities(List<Opportunity> opportunities)
{
foreach (var opportunity in opportunities)
{
    columnNumber = 0;
    var row = CreateRow();

    if (opportunity.HasContribution)
        cellStyle = "contentwithyellowbg";
    else
        cellStyle = "content";

    CreateCell(row, opportunity.ActionDate != DateTime.MinValue ? opportunity.ActionDate.ToShortDateString() : string.Empty, styles[cellStyle]);
    CreateCell(row, !string.IsNullOrEmpty(opportunity.Category) ? opportunity.Category : string.Empty, styles[cellStyle]);
    CreateCell(row, !string.IsNullOrEmpty(opportunity.Type) ? opportunity.Type : string.Empty, styles[cellStyle]);
    CreateCell(row, !string.IsNullOrEmpty(opportunity.SourceCode) ? opportunity.SourceCode : string.Empty, styles[cellStyle]);
    CreateCell(row, !string.IsNullOrEmpty(opportunity.Description) ? opportunity.Description : string.Empty, styles[cellStyle]);
    CreateCell(row, !string.IsNullOrEmpty(opportunity.Package) ? opportunity.Package : string.Empty, styles[cellStyle]);
}
}

New Post: XSSF Performance: degrade when creating large number of rows

$
0
0
Think I figured out our issue. Calling the AutoSizeColumn method during every cell write, instead of waiting till all the data is written and just do it once for all columns.

New Post: How can I get range by name

$
0
0
Hello, I have an .xls template with several named ranges, how can I get range by its name?

New Post: AutoSizeColumn got slow in NPOI 2.0

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

This issue will be fixed in the next release.

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

Wait a moment. Can you show me the complete code that you read the Excel and write the Excel? I'm afraid you are reading from one Excel file and write the file with append mode. This is not accepable. Instead, after reading the Excel, you should write the original file with replace mode instead of append mode

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

PackageAccess.READ and FileAccess.Read are different. Please read the Excel file using FileStream with readonly mode and then pass the filestream to XSSFWorkbook. It should work.

Commented Unassigned: Replace a formula with its result [13326]

$
0
0
Hi,
I have an excel that is filled with formulas right through a second tab which is hidden, then I want my first tab shows the values in the cells, not the formulas or references from where the information is obtained.

I were trying using this __sheet0.GetRow(5).GetCell(1).SetCellFormula(null)__ but it sets the cell to null or empty and i need the value converted from the formula.

Thanks in advance
Yoni Valdez
Comments: ** Comment from web user: tonyqus **

In this case, you should use XSSFFormulaEvaluator or HSSFFormulaEvaluator to evaluate the formula and set the result to the cell you want. Setting cell to null doesn't work at all

Closed Unassigned: Replace a formula with its result [13326]

$
0
0
Hi,
I have an excel that is filled with formulas right through a second tab which is hidden, then I want my first tab shows the values in the cells, not the formulas or references from where the information is obtained.

I were trying using this __sheet0.GetRow(5).GetCell(1).SetCellFormula(null)__ but it sets the cell to null or empty and i need the value converted from the formula.

Thanks in advance
Yoni Valdez

Closed Unassigned: [Bug] Incorrect handling of serialization for xlsx generated by MS Excel 2010/2013 [13281]

$
0
0
Our application is editing existing xlsx files. Problem is that it works with xlsx created by excel 2007, but does not work if file was saved in excel 2010 or 2013.

Problem is in serialization of some boolean values, in our cases in chart serialization. See following examples from chart.xml:

Original xlsx file:
<c:auto val="0"/>
<c:delete val="0"/>

File modified by NPOI:
<c:auto></c:auto>
<c:delete></c:delete>

val=0 is not written and it seems that excel interprets this as true

Problem is in chart.cs, CT_Boolean.Write that is writing values via XmlHelper.WriteAttribute with writeIfBlank parameter missing (meaning false).

Closed Unassigned: XSSFWorkbook is corrupt when CurrentThread.CurrentCulture uses a comma instead of a period as the decimal separator [13252]

$
0
0
```c#
IWorkbook workbook;
ISheet sheet;

Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
workbook = new XSSFWorkbook();
sheet = workbook.CreateSheet();
using (var stream = new FileStream("en-US.xlsx", FileMode.Create))
{
workbook.Write(stream);
}

Thread.CurrentThread.CurrentCulture = new CultureInfo("nl-BE");
workbook = new XSSFWorkbook();
sheet = workbook.CreateSheet();
using (var stream = new FileStream("nl-BE.xlsx", FileMode.Create))
{
workbook.Write(stream);
}
```

__en-US.xlsx__ will open fine, __nl-BE.xlsx__ will be corrupt (although repairable). When unzipping both files and running a diff, there's only one difference and it's in __xl\worksheets\sheet1.xml__

__en-US.xlsx__
```xml
<pageMargins left="0.7" right="0.7" top="0.75" bottom="0.75" header="0.3" footer="0.3"></pageMargins>
```

__nl-BE.xlsx__
```xml
<pageMargins left="0,7" right="0,7" top="0,75" bottom="0,75" header="0,3" footer="0,3"></pageMargins>
```

As you can see, it's the decimal separator.

Commented Unassigned: NPOI Save Excel unable open in iPhone [13251]

$
0
0
Hi,

I'm new to the NPOI, I've generated the excel file using NOIexamples and the version NPOI 2.1.1.

And I've attached the generated excel in email which unable to open in the iPhone, getting the below message during open the attached excel,

___test.xlsx

Office Open XML spreadsheet 1.1 MB___

Our requirement is to notify the staffs thru email with the generated excel attachment.

Kindly advise and if possible, provide the sample code for the same.

Regards,
Kumaran
Comments: ** Comment from web user: tonyqus **

Which software on Iphone are you using to open the xlsx?

Closed 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?

Commented Unassigned: [2.1.1]HSSFWorkbook.Write occurred NPOI.HPSF.ReadingNotSupportedException [13247]

$
0
0
dotnet4

A first chance exception of type 'NPOI.HPSF.ReadingNotSupportedException' occurred in NPOI.dll
A first chance exception of type 'NPOI.HPSF.ReadingNotSupportedException' occurred in NPOI.dll

Twice

also 2.0.6
Comments: ** Comment from web user: tonyqus **

Can you show me the reproduce code?

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

According to the comments, passing a Stream instead of a Package uses more memory because the whole file is read into memory.

Viewing all 1621 articles
Browse latest View live


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