Quantcast
Viewing all 1621 articles
Browse latest View live

New Post: Is it possible embed OLEDB Object to Excel with NPOI

Hi,

I'm looking for the same thing. You had any luck with it?

Created Unassigned: DataValidation Explicit Values Extra Quotes [14021]

When setting data validation to an explicit list in excel, say 1 and 2, NPOI reads the datavalidation formula enclosed in an extra double quotes: ""1,2"" instead of "1,2", resulting in the ExplicitValues array to also contains the quotes.

using NPOI 2.2.1

Nic

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

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>
Comments: ** Comment from web user: Zebrette **

same issue for me, already reported under Id #13957. I suggest merging the bugs

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

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.
Comments: ** Comment from web user: Zebrette **

same issue for me, already reported under Id #13957 (and #14012?). I suggest merging the bugs

New Post: Cross sheet DataValidation

I'm trying to read the datavalidation of a cell using NPOI.

It works fine with a list of explicit values, or a range reference from the same sheet, but when the range reference is from another sheet, the method getDataValidations() doesn't return that specific data validation (although it return all the other ones).

I looked into the sheet xml, and it seems that the data validation that reference other sheets are not stored under the same xml tags they use <x14:dataValidation> instead of <dataValidation>. Is there a way to get all of them?

Nic

New Post: Problematic corruption of .xlsx files with NPOI - Excel cannot open the file 'file.xlsx" because the file format or file extension is not valid

When reading or modifying some user-created .xlsx files, I get the following error message:
We found a problem with some content in 'test.xlsx'. Do you want us to try to recover as much as we can? If you trust the source of this workbook, click Yes.
Clicking Yes gets me another message:
Excel cannot open the file 'test.xlsx' because the file format or file extension is not valid. Verify that the file has not been corrupted and that the file extension matches the format of the file.
I have no issues creating a new .xlsx file with the following code:
    string newPath = @"C:\MyPath\test.xlsx";
            
    using (FileStream fs = new FileStream(newPath, FileMode.Create, FileAccess.Write))
    {
        IWorkbook wb = new XSSFWorkbook();
        wb.CreateSheet();
        ISheet s = wb.GetSheetAt(0);
        IRow r = s.CreateRow(0);
        r.CreateCell(0);
        ICell c = r.GetCell(0);
        c.SetCellValue("test");
        wb.Write(fs);
        fs.Close();
    }
That works fine.

Even opening one of the problem child .xlsx files, setting it to an IWorkbook and writing it back to the file works:
    string newPath = @"C:\MyPath\test.xlsx";

    using (FileStream fs = new FileStream(newPath, FileMode.Open, FileAccess.ReadWrite))
    {
        IWorkbook wb = new XSSFWorkbook(fs);
        wb.Write(fs);
        fs.Close();
    }
However, after running through code that reads from it, gets ISheets, IRows, ICells, etc.... it corrupts the .xlsx file. Even though I specifically removed anything that modifies the workbook. No Creates, Sets, Styles, etc. with NPOI.

I can't really include my code because it would just be confusing, but for the sake of completeness I'm really only using the following types and functions from NPOI during this test:
    IWorkbook
    XSSFWorkbook
    ISheet
    IRow
    ICell
    .GetSheetAt
    .GetRow
    .GetCell
    .LastRowNum
So one of those causes corruption. I would like to eventually set values again and get it working like I have for .xls.

Has anyone experienced this? What are some NPOI functions that could cause corruption? Any input would be appreciated.

New Post: Problematic corruption of .xlsx files with NPOI - Excel cannot open the file 'file.xlsx" because the file format or file extension is not valid

I figured it out. It didn't like that I wrote the changed IWorkbook to the same file. Creating a new file solved this issue. Also, I believe if you do want to overwrite it, FileAccess.ReadWrite also seemed to work for the FileStream.

Created Unassigned: Append a cell / raw to saved/existing xls file [14025]

Hi Team /All.

I'm new to NPOI, I had started today and I must say well done !.
I have the following issue and I hope you can help / explain it to me.

I would like to write 10 different cells to a xls file, But i must save the file after each modification.
I tried to use the ".Write(file)" method and I get a big file but with results of only the first save. (all other 9 changes are not saved).

I tried to search for this issue but I could not find an answer.

Thanks in advance,
Eyal.

New Post: NPOI 2.2.0 try ShiftRows

I have the same issue with .xlsx files and .ShiftRows in 2.2.1. I saved the same file as an .xls and it didn't happen.

Reviewed: NPOI 2.1.3.1 (一月 03, 2017)

Rated 5 Stars (out of 5) - Oprating office is cool!

New Post: NPOI read big files

i m trying to use NPOI dll to import excel files, but with very large documents(more 56mb and 65k rows/250 columns) it s too low.
is there any method to open the excel without the preload?

now i open excel with this code
HSSFWorkbook hssfwb;
using (FileStream file = new FileStream(@"\\192.168.198.129\tmp\test.xls", FileMode.Open, FileAccess.Read))
{
      //here the problem!!!
      hssfwb = new HSSFWorkbook(file,false);
}
before i used https://github.com/ExcelDataReader/ExcelDataReader that open the file like a text(with filestream) and i loop data like a normal text.
(i dismissed it because i had some problems on encoding).
this is what i done before and what i hope to do with NPOI.
private void read()
        {
            FileStream stream = File.Open(@"\\192.168.198.129\tmp\test.xls", FileMode.Open, FileAccess.Read);
            IExcelDataReader excelReader = ExcelReaderFactory.CreateBinaryReader(stream);

            while (excelReader.Read())
            {
                Console.WriteLine(excelReader[0]);
            }

            DataSet result = excelReader.AsDataSet();
            Console.Read();
        }
is there any possibilities?

thank you

New Post: XXSF namespace is missing in action

Greetings,

I have downloaded the latest NPOI from git and compiled the DLL; I have also tried the beta binary release. In the object browser, the XXSF namespace is nowhere to be found. Does it still exist? Do I have the wrong version of the DLL? Thanks!

Theresa

Created Unassigned: Shape of the comment box to a giant Curved Arrow [14045]

As mentioned in some java posts, comment boxes are changing shape by themselves when saving XLSX.
Here is one bugzilla link:
https://bz.apache.org/bugzilla/show_bug.cgi?id=55410
And MS link:
https://answers.microsoft.com/en-us/msoffice/forum/msoffice_excel-mso_windows8/comment-boxes-changing-shape-by-themselves/db78c2e1-756a-48f9-ba30-ab062993a0ab

So, are there any fixes already for NPOI in C# for this problem?

Thanks in advance
David

Updated Wiki: Documentation

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

Our website: www.neuzilla.com

 

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

Who are We
Neuzilla is the studio behind NPOI. For detail, you can checkwww.neuzilla.com

Image may be NSFW.
Clik here to view.
 

 
 
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

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

 

 

Image may be NSFW.
Clik here to view.

 
Extensions
 

New Post: Server-side Excel library for use with C# and .NET

My question would be: Is NPOI library the library I am looking for ? Does NPOI support the features below ?

At our company we are using the [Telerik RadSpreadProcessing] Library with .NET C#. It can manipulate data on the server-side without the need for Office. Unfortunately the Telerik library is missing few features that we need. Such features are:
• Add Graphic in Header and Footer
• Rotation of Text in a cell
• Charts should not be thrown away (Telerik library throws away)

The library should support the .xlsx format but also Formulas to manipulate the data.

Furthermore it would be ideal if the library has the below functionalities:

• OpenWorkbook
• AddNewWorkbook
• AddNewSheet
• RemoveSheetByName
• RemoveSheetByIndex
• SelectSheetByName
• SelectSheetByIndex
• GetSheetNames
• SetSheetName
• GetCellValue
• SetCellValue
• SetCellText
• SetCellTextFromClipboard
• SetRowValues
• SetColumnValues
• AutoFit
• SetHeader
• SetFooter
• SetCellStyles
• SetCellStyle
• SetCellBorders
• SetCellBorder
• SetCellAlignments
• SetCellAlignment
• SetCellProtections
• SetCellProtection
• SetSheetProtection
• SetCellFormat
• SetCellFormats
• Save
• SaveAs
• Close
• GetSessions

New Post: How to clear NPOI WorkBook memory.

I am using NPOI dll to read excel file which contains 35k rows(10MB )
using (FileStream fs = new FileStream("temp.xlsx", FileMode.Open, FileAccess.Read))
{
      IWorkbook wb = WorkbookFactory.Create(fs);
}
After reading excel file using above code process memory increased around 200MB. In my application multiple excel files are reading one after another, so process memory increasing for each file. I am unable to clear process memory because workbook doesn't have any dispose method. I want to clear memory occupied by workbook after completion of work with one excel file and read another file.
After reading excel file : Is there any method to clear workbook memory?

New Post: How can I change the long date format to short date format?

It works fine for me. But date format always shows like dd-mm-yyyy format in Excel sheet. How to change to dd/mm/yyyy. Please reply

New Post: Server-side Excel library for use with C# and .NET ?

Does this library support the below things ?
  • Add Graphic in Header and Footer
  • Rotation of Text in a cell
  • Charts
The library should support the .xlsx format but also Formulas to manipulate the data.

Created Unassigned: Excel Error-In the Excel File multiple Sheet with pivot Table ,Excel Write Issue [14062]

Hi All team / I have the following issue and I hope you can help / explain it to me.
I Have one template of excel file ,in this excel file 1st sheet is pivot table and 2nd normal data sheet ,but right now problem is donot wite this file some exception through NPOI ( using XSSFWorkbook) .
Exception Is -( The method or operation is not implemented.) I try to solved this issue but i could not solved.
So please give me better solution on this issue.
Viewing all 1621 articles
Browse latest View live


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