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

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

HI Team, Please find the attached sample excel files. Here my environment is Windows 7 (64 bit) , Dot Net 4.5.


Reviewed: NPOI 2.1.3 (1月 13, 2015)

$
0
0
Rated 5 Stars (out of 5) - 1dfafasdasd

Commented Unassigned: Error while opening XL file [13106]

$
0
0
__Error while opening XL file__

An unhandled exception of type 'ICSharpCode.SharpZipLib.Zip.ZipException' occurred in ICSharpCode.SharpZipLib.dll

Additional information: Wrong Local header signature: 0xE011CFD0

```
internal DataTable OpenXL(string fullpath)
{
DataTable table = new DataTable();
XSSFWorkbook workbook = new XSSFWorkbook(new FileStream(fullpath, FileMode.Open, FileAccess.Read)); //ERROR AT THIS STATEMENT
.......
}
```
Comments: ** Comment from web user: hjjjizhan **

Hi, I happened same question with you, How do you solve ? But the error not happened all server, Attachment my code:

using (MemoryStream ms = new MemoryStream(downloadFile, 0, downloadFile.Length))
{
if (task.FileType == 2) //Office 2007
workbook = new XSSFWorkbook(ms); // Exception Code
else if (task.FileType == 1) //Office 2003
workbook = new HSSFWorkbook(ms); // Exception Code
}

Thx

Created Unassigned: Error while opening excel file stream [13416]

$
0
0
I happened a bad question, while publish production server, application read excel stream will throw exception "Wrong Local header signature", but test server no problem, attachment my code:



using (MemoryStream ms = new MemoryStream(downloadFile, 0, downloadFile.Length))
{
if (task.FileType == 2) //Office 2007
workbook = new XSSFWorkbook(ms); // throw exception
else if (task.FileType == 1) //Office 2003
workbook = new HSSFWorkbook(ms); // throw exception
}

Updated Wiki: Home

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

To get the latest code, please visit https://github.com/tonyqus/npoi
 
E-iceblue is a community sponsor of NPOI
E-iceblue components enable developers to Open, Create, Modify, Convert, Print, View MS Word, Excel, PowerPoint, PDF documents.
Banner
Donate NPOI
donate_btn
 
 
NPOI Support Service
We provide onsite/offsite hand-on training, troubleshooting and software customization. For details, please contact tonyqus@163.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
 
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
 

Released: NPOI 2.0 (Jan 05, 2014)

$
0
0
NPOI User Group: http://www.linkedin.com/groups/NPOI-User-Group-6655065

Assembly version: 2.0.6

Provide 2 assembly versions: .net 2, .net 4

New features
a. Support Scatter chart in XSSF (xlsx) (other chart types are not supported yet)
b. Extract pictures from Excel (xlsx)
c. XWPF becomes stabler than before
d. Able to support xml:space="preserve" attribute
e. Add mono assembly in the release package
f. file generated by NPOI will contain NPOI tags in custom properties to identify the generator
g. Adjust some XWPF interfaces

Sample changes
a. add new samples like BigGridTest, WritePerformanceTest to test performance
b. add ScatterChart to show how to create Scatter chart
c. add LinkedDropDownList for both XSSF and HSSF
d. add MonthlySalaryReport to show how to use formula in XSSF
e. add CreateCustomProperties to show how to use custom props in XSSF and XWPF

Winhost low-cost hosting
Cheap ASP.NET Hosting - $4.95/Month - Click Here!

Bug fixes
a. fix shift row issue in XSSFSheet
b. fix performance issue due to XmlSerializer. NPOI is getting rid of XmlSerializer.
c. reading/writing CT_Drawing
d. fix ddd pattern issue in CellDateFormatter
e. Change some common interfaces in NPOI.SS
f. fix OutOfMemory issue in MemoryPackagePart
g. Able to read AbsoluteAnchor, OneCellAnchor, TwoCellAnchor in drawing.xml
h. Formula will be calculated automatically after generation
i. improve performance for XSSF while creating new rows
For detail, please read https://npoi.codeplex.com/discussions/443655
j. fix name encoding issue of custom properties in HSSF
For detail, please read https://npoi.codeplex.com/workitem/12296
k. fix exception in HSSFRows.RemoveAllCells
l. fix CellStyle Hashtable comparison issue in class HSSFCellUtil. This can help prevent over 4000 styles issue from code.
m. Fix globalization issue in ExpandedDouble
n. fix a lot of xml serialization issue for OOXML
o. implement XSSFCell.IsMergedCell
p. IWorkbook implements IList<ISheet>

To get the source code, please visit https://github.com/tonyqus/npoi/releases/tag/2.0.6RC1

Updated Release: NPOI 2.0 (一月 05, 2014)

$
0
0
NPOI User Group: http://www.linkedin.com/groups/NPOI-User-Group-6655065

Assembly version: 2.0.6

Provide 2 assembly versions: .net 2, .net 4

New features
a. Support Scatter chart in XSSF (xlsx) (other chart types are not supported yet)
b. Extract pictures from Excel (xlsx)
c. XWPF becomes stabler than before
d. Able to support xml:space="preserve" attribute
e. Add mono assembly in the release package
f. file generated by NPOI will contain NPOI tags in custom properties to identify the generator
g. Adjust some XWPF interfaces

Sample changes
a. add new samples like BigGridTest, WritePerformanceTest to test performance
b. add ScatterChart to show how to create Scatter chart
c. add LinkedDropDownList for both XSSF and HSSF
d. add MonthlySalaryReport to show how to use formula in XSSF
e. add CreateCustomProperties to show how to use custom props in XSSF and XWPF

Winhost low-cost hosting
Cheap ASP.NET Hosting - $4.95/Month - Click Here!

Bug fixes
a. fix shift row issue in XSSFSheet
b. fix performance issue due to XmlSerializer. NPOI is getting rid of XmlSerializer.
c. reading/writing CT_Drawing
d. fix ddd pattern issue in CellDateFormatter
e. Change some common interfaces in NPOI.SS
f. fix OutOfMemory issue in MemoryPackagePart
g. Able to read AbsoluteAnchor, OneCellAnchor, TwoCellAnchor in drawing.xml
h. Formula will be calculated automatically after generation
i. improve performance for XSSF while creating new rows
For detail, please read https://npoi.codeplex.com/discussions/443655
j. fix name encoding issue of custom properties in HSSF
For detail, please read https://npoi.codeplex.com/workitem/12296
k. fix exception in HSSFRows.RemoveAllCells
l. fix CellStyle Hashtable comparison issue in class HSSFCellUtil. This can help prevent over 4000 styles issue from code.
m. Fix globalization issue in ExpandedDouble
n. fix a lot of xml serialization issue for OOXML
o. implement XSSFCell.IsMergedCell
p. IWorkbook implements IList<ISheet>

To get the source code, please visit https://github.com/tonyqus/npoi/releases/tag/2.0.6RC1

New Post: XWPFTable: how to set column width and cell borders?

$
0
0
Hello,
I have just begun creating docx with XWPFDocument. Could you please advice if my approach is proper, assuming that I would like to create a table with 3 columns, first narrow, second and third wider:
XWPFTable t0 = doc.CreateTable( 3, 3 );
t0.Width = 5000;

t0.GetRow( 0 ).GetCell( 0 ).SetText( "A" );
t0.GetRow( 0 ).GetCell( 1 ).SetText( "B" );
t0.GetRow( 0 ).GetCell( 2 ).SetText( "C" );

t0.GetRow( 1 ).GetCell( 0 ).SetText( "X" );
t0.GetRow( 1 ).GetCell( 1 ).SetText( "Name 1, Name 2, Name 3, Name 4" );
t0.GetRow( 1 ).GetCell( 2 ).SetText( "Name 1, Name 2, Name 3, Name 4" );

t0.SetColumnWidth( 0, 1000 );
t0.SetColumnWidth( 1, 2000 );
t0.SetColumnWidth( 2, 2000 );
Beside of it I would like to leave only horizontal lines (top, bottom and innern) for the table.
I know how to modify presence of cell borders for a spreadsheet but not for the Word docx table. Any help if I may please?

Created Unassigned: getIndex-method gone after upgrading to 2.1.3 (from 2.0.6.0) [13436]

$
0
0
Hi there,

great Library so far.

I just upgraded to the latest version because of the alignment-bug (vertical-align top results in center). But now I have another Problem setting the background color of some cells.

The Code:
```
short palIndex = palette.FindSimilarColor(color.R, color.G, color.B).GetIndex();
menuCellStyle.FillForegroundColor = palIndex;
```

I get the following errormessage:
Error 1 'NPOI.HSSF.Util.HSSFColor' does not contain a definition for 'GetIndex' and no extension method 'GetIndex' accepting a first argument of type 'NPOI.HSSF.Util.HSSFColor' could be found (are you missing a using directive or an assembly reference?) ...\WriteToExcel.cs 80 66 apetito.MenuPlanner.Utils

I updated the assembly via nuget. Any help here? I searched the documentation and googled, but didn't find a solution or a hint so far.

Best regards,
Dominik

Commented Unassigned: getIndex-method gone after upgrading to 2.1.3 (from 2.0.6.0) [13436]

$
0
0
Hi there,

great Library so far.

I just upgraded to the latest version because of the alignment-bug (vertical-align top results in center). But now I have another Problem setting the background color of some cells.

The Code:
```
short palIndex = palette.FindSimilarColor(color.R, color.G, color.B).GetIndex();
menuCellStyle.FillForegroundColor = palIndex;
```

I get the following errormessage:
Error 1 'NPOI.HSSF.Util.HSSFColor' does not contain a definition for 'GetIndex' and no extension method 'GetIndex' accepting a first argument of type 'NPOI.HSSF.Util.HSSFColor' could be found (are you missing a using directive or an assembly reference?) ...\WriteToExcel.cs 80 66 apetito.MenuPlanner.Utils

I updated the assembly via nuget. Any help here? I searched the documentation and googled, but didn't find a solution or a hint so far.

Best regards,
Dominik
Comments: ** Comment from web user: Pinguwien **

Ah, just got it... it's "Indexed" now. Sorry for the inconvenience, I'Ve been blind :-)

New Post: Inserting .TIFF images into .XLS

$
0
0
Is it possible using NPOI to insert .TIFF images into .XLS?

I know that NPOI supports multiple image formats but I dont see .TIFF as being one of them. See the code below:
 public class HSSFPictureData
    {
        // MSOBI constants for various formats.
        public const short MSOBI_WMF = 0x2160;
        public const short MSOBI_EMF = 0x3D40;
        public const short MSOBI_PICT = 0x5420;
        public const short MSOBI_PNG = 0x6E00;
        public const short MSOBI_JPEG = 0x46A0;
        public const short MSOBI_DIB = 0x7A80;
Is it possible to modify this class to include a MSOBI for TIFF files? If so, does anyone know what the value would be?

New Post: trying to export column header from DataTable only getting last value

$
0
0
I am trying to loop though a data table of headers. It is only writing the last one.
Any idea why?
//set the workbook properties and add a default sheet in it
                IWorkbook workBook = new XSSFWorkbook();
                ISheet worksheet1 = workBook.CreateSheet("Transactions");                

               DataTable columnHeader = new DataTable("Header");
                columnHeader.Columns.Add("a", typeof(String));
                columnHeader.Columns.Add("b", typeof(String));
                columnHeader.Columns.Add("c", typeof(String));
                columnHeader.Columns.Add("d", typeof(String));
                columnHeader.Columns.Add("e", typeof(String));
                columnHeader.Columns.Add("f", typeof(String));
                columnHeader.Columns.Add("g", typeof(String));
                columnHeader.Columns.Add("h", typeof(String));
                columnHeader.Columns.Add("i", typeof(String));
                columnHeader.Columns.Add("j", typeof(String));
                columnHeader.Columns.Add("k", typeof(String));
                columnHeader.Columns.Add("l", typeof(String));
                columnHeader.Columns.Add("m", typeof(String));
                columnHeader.Columns.Add("n", typeof(String));
                columnHeader.Columns.Add("o", typeof(String));
                columnHeader.Columns.Add("p", typeof(String));
                columnHeader.Columns.Add("q", typeof(String));
                columnHeader.Columns.Add("r", typeof(String));
                columnHeader.Columns.Add("s", typeof(String));
                columnHeader.Columns.Add("t", typeof(String));
                int rowIndex = 0;
                CreateHeader(worksheet1, ref rowIndex, columnHeader);


 private static void CreateHeader(ISheet worksheet1, ref int rowIndex, DataTable dt)
        {
            int colIndex = 1;
            IRow row = worksheet1.CreateRow(rowIndex);

            foreach (DataColumn dc in dt.Columns) //Creating Headings
            {
                
                worksheet1.CreateRow(rowIndex).CreateCell(colIndex).SetCellValue(dc.ColumnName.ToString()); 
                colIndex++;               

            }
        }

New Post: trying to export column header from DataTable only getting last value

$
0
0
even more odd a simple thing like this only creates the last one in header.

worksheet1.CreateRow(0).CreateCell(1).SetCellValue("a");
worksheet1.CreateRow(0).CreateCell(2).SetCellValue("b");
worksheet1.CreateRow(0).CreateCell(3).SetCellValue("c");

Reviewed: NPOI 2.1.3 (1月 29, 2015)

$
0
0
Rated 4 Stars (out of 5) - It is very convenient.

New Post: NPOI generated Excel file with multiple columns -- showing only 1

$
0
0
Hi,

We are currently using NPOI to generate/update Excel files. However, we have come across an issue where the NPOI generated excel file cannot be read by other Excel readers correctly.

Summary of issue/steps
  1. Generate an Excel file with the first row populated with data (first 10 cells)
  2. Next, open up the file using ExcelDataReader to read contents of first row
    (At this point ExcelDataReader is detecting only 1 column and is only able to read the first cell)
If we manually open the generated Excel file with Office Excel, the contents looks good. When we close the file, the "Save dialog" pops up and requires us to "save" even no updates were made. If you save it and open it with ExcelDataReader ... all the columns are now visible/readable.

Can show code if needed.

Closed Unassigned: getIndex-method gone after upgrading to 2.1.3 (from 2.0.6.0) [13436]

$
0
0
Hi there,

great Library so far.

I just upgraded to the latest version because of the alignment-bug (vertical-align top results in center). But now I have another Problem setting the background color of some cells.

The Code:
```
short palIndex = palette.FindSimilarColor(color.R, color.G, color.B).GetIndex();
menuCellStyle.FillForegroundColor = palIndex;
```

I get the following errormessage:
Error 1 'NPOI.HSSF.Util.HSSFColor' does not contain a definition for 'GetIndex' and no extension method 'GetIndex' accepting a first argument of type 'NPOI.HSSF.Util.HSSFColor' could be found (are you missing a using directive or an assembly reference?) ...\WriteToExcel.cs 80 66 apetito.MenuPlanner.Utils

I updated the assembly via nuget. Any help here? I searched the documentation and googled, but didn't find a solution or a hint so far.

Best regards,
Dominik

Closed Unassigned: Error while opening excel file stream [13416]

$
0
0
I happened a bad question, while publish production server, application read excel stream will throw exception "Wrong Local header signature", but test server no problem, attachment my code:



using (MemoryStream ms = new MemoryStream(downloadFile, 0, downloadFile.Length))
{
if (task.FileType == 2) //Office 2007
workbook = new XSSFWorkbook(ms); // throw exception
else if (task.FileType == 1) //Office 2003
workbook = new HSSFWorkbook(ms); // throw exception
}

New Post: Images created in foreach-loop not resizing correctly

$
0
0
Hi there,

so I am not sure if this is an issue or just my stupidity, but I don't get the Images I create inside a loop to resize correctly. I asked the question at StackOverflow over here, but noone answered yet so I hope I'll find help here, at the source :)

The following is a c&p from my stackoverflow-question:

I'm using NPOI 2.1.3 to create an excelsheet for a dynamic menuplan.

I have this code so far, which creates me pictures based on a list of imagepath-strings I get before:
...
var priceRow = sheet.GetRow(priceRowNum);
var priceCell = priceRow.CreateCell(i + 1);
...adding other contents...
List<string> imgList = createImagesList(codes);

foreach (string image in imgList)
{
    MemoryStream stream = new MemoryStream();
    Image.FromFile(image).Save(stream, ImageFormat.Png);
    var anc = new HSSFClientAnchor(0, 0, 20, 20, 0, 0, 0, 0)
    {
        Col1 = priceCell.ColumnIndex
    };
    anc.Row1 = priceRow.RowNum;
    anc.AnchorType = 0;
    int pictureIndex = excel.AddPicture(stream.ToArray(), PictureType.PNG);
    drawing.CreatePicture(anc, pictureIndex).Resize();
}
My Problem might be best described by the following picture:

Image

so it seems that only the pictures in the last foreach-iteration are resized correctly to the containing cell and I'm out of ideas why.

I searched a bit and found some other problems, but nothing seems to fit. Here are my insights so far: I didn't change the font, cellstyle etc. for my priceRow/priceCell, for I am aware that resize is just working correctly when the default size is used. Although, I used some style/fontchanges for other cells, but I always created a new font/cellstyle, so I never touched the "default" workbook-style.

Also, my patriarch drawing is created once per sheet (found this in another answer for a resizeproblem).

I also tried switching the anchortype from zero to two and back, and to manually add a height to my priceRow, but nothing of that took effect, so I hope someone could help me out here for I am really absolutely out of Ideas.

I don't think this is a "nested for/foreach-logic"-error, because with other plans there's sometimes only the first iteration not resizing correctly,... - it just seems to be very weird.

Feel free to ask for more code/pictures!

Best regards,
Dominik

New Post: Images created in foreach-loop not resizing correctly

$
0
0
I just messed up my anchor-constructor. got it working now.

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

I have also experienced this issue using Win 7 64-bit, .Net 4.5. Originally I used NPOI 2.0.6. I also tested 2.1.3 beta. I was investigating this issue and happened to find this post. I include how I have worked around this issue and then my findings. I have not gotten around to digging into the NPOI code yet.

For files that need no modification I use the following work around, writing to a MemoryStream, then byte array and that array to a file:

``` C#
XSSFWorkbook wb = new XSSFWorkbook();
wb.CreateSheet();

byte[] bytes;

using (MemoryStream stream = new MemoryStream())
{
wb.Write(stream);
bytes = stream.ToArray();
}

for (int i = 0; i < 3; i++)
{
string fPath = @"C:\temp\NPOIExcel" + i + ".xlsx";
File.WriteAllBytes(fPath, bytes);
}
```


And now on to my investigation. I had narrowed down the problem by creating a new workbook with one empty sheet using the following code:

``` C#
XSSFWorkbook wb = new XSSFWorkbook();
wb.CreateSheet();

for (int i = 0; i < 3; i++)
{
string fPath = @"C:\temp\NPOIExcel" + i + ".xlsx";

using (FileStream sw = File.Create(fPath))
{
wb.Write(sw);
}
}
```

Only the first file opens and so I unzipped each .xlsx file revealing only the first contains the docProps\core.xml file.

Also, each call of

``` C#
wb.Write(sw);
```

appears to append to the original object within the NPOI library (keep in mind I have not looked at the code as of posting). Let me use the contents of docProps\app.xml as an example

**First .xlsx file**
``` XML
<?xml version="1.0"?>
<Properties xmlns:vt="http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes" xmlns="http://schemas.openxmlformats.org/officeDocument/2006/extended-properties">
...
</Properties>
```

**Second .xlsx file** (the first file contents are duplicated)
``` XML
<?xml version="1.0"?>
<Properties xmlns:vt="http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes" xmlns="http://schemas.openxmlformats.org/officeDocument/2006/extended-properties">
...
</Properties><?xml version="1.0"?>
<Properties xmlns:vt="http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes" xmlns="http://schemas.openxmlformats.org/officeDocument/2006/extended-properties">
...
</Properties>
```

These same symptoms are found in the other XML files with two exceptions: the XML file lives in a '_res' folder or the [Content_Types].xml file.

Viewing all 1621 articles
Browse latest View live


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