Quantcast
Channel: EPPlus Issue Tracker Rss Feed
Viewing all 2262 articles
Browse latest View live

Commented Unassigned: LoadFromDataTable with empty Table and PrintHeaders false gives ArgumentException or ArgumentOutOfRangeException [14985]

$
0
0
I'm using 3.1.3.3.

```
using System;
using System.Data;
using OfficeOpenXml;

namespace Test
{
class Program
{
static void Main(string[] args)
{
var ep = new ExcelPackage();
var sheet = ep.Workbook.Worksheets.Add("Test");

// Make an empty table
var dt = new DataTable();
dt.Columns.Add(new DataColumn("col1"));
dt.Columns.Add(new DataColumn("col2"));

// Load empty table at A1
try
{
sheet.Cells["A1"].LoadFromDataTable(dt, false);
}
catch (ArgumentException e)
{
Console.WriteLine(e);
Console.WriteLine();
}

// Load empty table at A2
try
{
sheet.Cells["A2"].LoadFromDataTable(dt, false);
}
catch (ArgumentOutOfRangeException e)
{
Console.WriteLine(e);
Console.WriteLine();
}

Console.WriteLine("Press any key ...");
Console.ReadKey();
}
}
}
```

Output:

```
System.ArgumentException: Row out of range
at OfficeOpenXml.ExcelRange.ValidateRowCol(Int32 Row, Int32 Col)
at OfficeOpenXml.ExcelRange.get_Item(Int32 FromRow, Int32 FromCol, Int32 ToRo
w, Int32 ToCol)
at OfficeOpenXml.ExcelRangeBase.LoadFromDataTable(DataTable Table, Boolean Pr
intHeaders)

System.ArgumentOutOfRangeException: Specified argument was out of the range of v
alid values.
Parameter name: Start cell Address must be less or equal to End cell address
at OfficeOpenXml.ExcelAddressBase.Validate()
at OfficeOpenXml.ExcelAddressBase.SetAddress(String address)
at OfficeOpenXml.ExcelAddress.set_Address(String value)
at OfficeOpenXml.ExcelRange.get_Item(Int32 FromRow, Int32 FromCol, Int32 ToRo
w, Int32 ToCol)
at OfficeOpenXml.ExcelRangeBase.LoadFromDataTable(DataTable Table, Boolean Pr
intHeaders)
```
Comments: Also observed in 4.0.0-beta2.

Created Unassigned: Redundant check in ExcelWorksheet.Save [14986]

$
0
0
In ExcelWorksheet.cs, line 2430 (more or less):

```
if (Drawings.Count != null && _drawings.Count == 0)
{
//Remove node if no drawings exists.
DeleteNode("d:drawing");
}
```
Drawings.Count, being an integer, can never be *null*. However, if we just remove the first check, we have to refer to the Drawings property (not the _drawings field) in the remaining check; otherwise, saving a worksheet with no drawings (thus having _drawings still set to *null*) will throw a NullReferenceException.

```
if (Drawings.Count == 0)
{
//Remove node if no drawings exists.
DeleteNode("d:drawing");
}
```

Created Unassigned: Rethrowing exceptions [14987]

$
0
0
Sometimes, tracking down exceptions occurring in EPPlus can be more difficult than necessary, due to some *catch* blocks throwing catched exceptions again,instead of rethrowing them.
The difference in code is minimal, but the outcome can be radically different.
```
catch (Exception ex)
{
throw (ex); // Lose the exception's original stack frame
// Now the exception appears to have originated on the previous line,
// which is misleading and unnecessarily complicates debugging
}
```
Code like the above (without the comments, that is) appears in at least 4 places in EPPlus. It's probably better to change it to:
```
catch (Exception ex)
{
throw; // Preserve the exception's stack frame
}
```

Created Unassigned: Bug when saving a workbook loaded from a template [14988]

$
0
0
I'm not entirely sure this is a bug, but since it's about code that worked in previous versions and doesn't work now, I thought creating an issue was the appropriate course of action.

This code, which worked in previous versions (before the switch to DotNetZip) is now broken:
```
using (var templateStream = File.OpenRead(TEMPLATE_PATH))
using (var outStream = File.Open(OUTPUT_PATH, FileMode.Create, FileAccess.ReadWrite, FileShare.None))
using (var package = new ExcelPackage(outStream, templateStream))
{
// Create more content
package.Save();
}
```
The output file is created, but it's an exact copy of the template file. The new file contents are written to a memory stream which gets discarded right away.

Luckily, the following (almost equivalent) code works:
```
using (var package = new ExcelPackage(new FileInfo(OUTPUT_PATH), new FileInfo(TEMPLATE_PATH)))
{
// Create more content
package.Save();
}
```

The problem seems to lie in ExcelPackage.Save, which does not copy the memory stream resulting from _package.Save() to its output stream if it wasn't initialized with a file. This does not look like intended behavior; more like unfinished work, IMHO.

Created Unassigned: I cannot set the chart title without editing the XML [14989]

$
0
0
I am doing the following:

```
var chart = (ExcelScatterChart)oepSheetData.Drawings["Chart 1"];
chart.Series.Delete(0);
chart.Name = "New Name"; // I know this is not the title

// Add some series manually

// This doesn't seem to be working
chart.Title.Text = "New Title";

// This does work
chart.ChartXml.DocumentElement["c:chart"]["c:title"].InnerXml =
"<c:tx><c:rich><a:bodyPr /><a:lstStyle /><a:p><a:pPr><a:defRPr /></a:pPr><a:r><a:rPr lang=\"en-US\" /><a:t>New Title</a:t></a:r></a:p></c:rich></c:tx><c:layout /><c:overlay val=\"0\" />";
```

I tried chart.Title.RichText as well. I'll try to submit a patch later when I get a chance to dig into it.

Commented Issue: pivot table not correct when add three rowfield [14580]

$
0
0
when i add rowfield to pivottable, if i add 3 rowfield, rowfield sequence not correct when i open excel file.
example:
pivotTable1.RowFields.Add(pivotTable1.Fields("REGION")) ' sequence 1
pivotTable1.RowFields.Add(pivotTable1.Fields("ORG")) ' sequence 2
pivotTable1.RowFields.Add(pivotTable1.Fields("CODE_AND_NAME")) 'sequence 3

when i open excel file, rowlabel section in pivot table field list show:
"REGION"
"CODE_AND_NAME"
"ORG"
Comments: Great solution! I had exactly the same problem with the wrong order in the rowfields, and for me commenting out these lines helped, too. Thanks for sharing!

Created Unassigned: Error reading Excel file but not when under debug [14990]

$
0
0

When I run the following code with no break points set I am getting an: "Object reference not set to an instance of an object." exception from the package.workbook being nothing as soon as I try to interrogate the object ("If Not IsNothing(package.Workbook) AndAlso Not IsNothing(package.Workbook.Worksheets) AndAlso package.Workbook.Worksheets.Count > 0") to ensure that the workbook has been read and there is something there to work with.

When I run under debug and give it a few seconds to complete whatever operation it is doing in the background (i.e. would appear to be generating the workbook object) all works well. What I mean by this is that as soon as the code breaks at this point;

If Not IsNothing(package.Workbook) AndAlso Not IsNothing(package.Workbook.Worksheets) AndAlso package.Workbook.Worksheets.Count > 0 Then

When I hover over the package.workbook object it reports that it is nothing ... after a few seconds it starts to report that it is as expected (47 worksheets). This is with NO steps being taken in the debugging. So it would appear to my small mind like their is an action happing in the background that I need to get the code to wait to complete. I have tried a thread,sleep and this does not seem to help.

Any ideas?

The following is the code (which I again need to point out works fine when you allow it to work slowly under debug).

Private Function ReadExcelFileUsingEPP(ByRef strExcelFileName As String) As ExcelSheet()
ReadExcelFileUsingEPP = Nothing
Try
Dim arrTemp() As ExcelSheet = Nothing
Dim blnWorkbookRead As Boolean = False
Try
Dim myMemoryStream As Stream = OpenPackageAsMemoryStream(strExcelFileName)
Dim package As New ExcelPackage(myMemoryStream)
If Not IsNothing(package.Workbook) AndAlso Not IsNothing(package.Workbook.Worksheets) AndAlso package.Workbook.Worksheets.Count > 0 Then
ReDim arrTemp(package.Workbook.Worksheets.Count - 1)
Dim intWorkSheetsNotNothing As Integer = -1
For s As Integer = 1 To package.Workbook.Worksheets.Count
If Not IsNothing(package.Workbook.Worksheets(s)) AndAlso Not IsNothing(package.Workbook.Worksheets(s).Dimension) AndAlso Not IsNothing(package.Workbook.Worksheets(s).Dimension.End) AndAlso Not IsNothing(package.Workbook.Worksheets(s).Dimension.End.Row) AndAlso package.Workbook.Worksheets(s).Dimension.End.Row > 0 AndAlso Not IsNothing(package.Workbook.Worksheets(s).Dimension.End.Column) AndAlso package.Workbook.Worksheets(s).Dimension.End.Column > 0 Then
Console.WriteLine("Reading Sheet: " & package.Workbook.Worksheets(s).Name)
Dim myExcelSheet As ExcelSheet = ReadExcelWorkSheetUsingEPP(package.Workbook.Worksheets(s))
If Not IsNothing(myExcelSheet.SheetName) Then
intWorkSheetsNotNothing += 1
arrTemp(intWorkSheetsNotNothing) = myExcelSheet
End If
End If
Next
ReDim Preserve arrTemp(intWorkSheetsNotNothing)
End If
ReadExcelFileUsingEPP = arrTemp
package.Dispose()
blnWorkbookRead = True
Catch ex As Exception
Console.WriteLine("clsReportGenerator.ReadExcelFileUsingEPP Internal Error: " & ex.Message)
LogError("clsReportGenerator.ReadExcelFileUsingEPP Internal Error: ", ex.Message)
End Try
Catch ex As Exception
Console.WriteLine("clsReportGenerator.ReadExcelFileUsingEPP Error: " & ex.Message)
LogError("clsReportGenerator.ReadExcelFileUsingEPP", ex.Message)
Dim inner As Exception = ex.InnerException
While Not IsNothing(inner)
LogError("clsReportGenerator.ReadExcelFileUsingEPP.inner", inner.Message)
inner = inner.InnerException
End While
End Try
GC.Collect()
GC.WaitForPendingFinalizers()
End Function

Created Unassigned: Page breaks is not working EPPlus 4.0 Beta 2 [14991]

$
0
0
Hi Jan

I am facing page break issue in Epplus 4.0, previously i have used EPPlus 3.1, page break was working fine in Epplus 3.1 but later i have changed the class library Epplus 4.0 beta due to Title Repeat issue in V3.1, i could not able to use both column title repeat and row title repeat simultaneously, i can use only column title repeat or Row Title repeat in EPPLUS 3.1 stable Version , so please suggest me to rectify issue in page break or Title Repeat, it would be more helpful for me

Thank you for the awesome Class library

Edited Unassigned: Page breaks is not working EPPlus 4.0 Beta 2 [14991]

$
0
0
Hi Jan

I am facing page break issue in Epplus 4.0, previously i have used EPPlus 3.1, page break was working fine in Epplus 3.1 but later i have changed the class library Epplus 4.0 beta due to Title Repeat issue in V3.1, i could not able to use both column title repeat and row title repeat simultaneously, i can use only column title repeat or Row Title repeat in EPPLUS 3.1 stable Version , so please suggest me to rectify issue in page break or Title Repeat, it would be more helpful for me

Thank you for the awesome Class library

Created Unassigned: Array Formulas Messed Up On 4.0 Beta [14992]

$
0
0
Hello,

I have a workbook with a summary worksheet with array formulas and a data worksheet for inputting data with EPPlus. This worked very well with 3.1.3 but trying it with the new 4.0 Beta my array formulas are getting replaced with formulas such as "=1073741825". It appears that just saving the package causes the issue. Below is the code I used to test this. Attached is a test workbook.

```
using (ExcelPackage pck = new ExcelPackage(new System.IO.FileInfo("test.xlsx")))
{
pck.Save();
}
```

Thanks,
Tyler Brinkley

Commented Unassigned: Page breaks is not working EPPlus 4.0 Beta 2 [14991]

$
0
0
Hi Jan

I am facing page break issue in Epplus 4.0, previously i have used EPPlus 3.1, page break was working fine in Epplus 3.1 but later i have changed the class library Epplus 4.0 beta due to Title Repeat issue in V3.1, i could not able to use both column title repeat and row title repeat simultaneously, i can use only column title repeat or Row Title repeat in EPPLUS 3.1 stable Version , so please suggest me to rectify issue in page break or Title Repeat, it would be more helpful for me

Thank you for the awesome Class library
Comments: After looking through the code, the issue seems to be in ExcelWorksheet.UpdateRowBreaks(StreamWriter sw) ``` private void UpdateRowBreaks(StreamWriter sw) { StringBuilder breaks=new StringBuilder(); int count = 0; var cse = new CellsStoreEnumerator<object>(_values, 0, 0, ExcelPackage.MaxRows, 0); //foreach(ExcelRow row in _rows) while(cse.Next()) { var row=cse.Value as ExcelRow; if (row != null && row.PageBreak) { breaks.AppendFormat("<brk id=\"{0}\" max=\"1048575\" man=\"1\" />", cse.Row); count++; } } if (count>0) { sw.Write(string.Format("<rowBreaks count=\"{0}\" manualBreakCount=\"{0}\">{1}</rowBreaks>", count, breaks.ToString())); } } ``` When I changed it to the following with InternalRow instead of ExcelRow the problem was corrected. ``` private void UpdateRowBreaks(StreamWriter sw) { StringBuilder breaks=new StringBuilder(); int count = 0; var cse = new CellsStoreEnumerator<object>(_values, 0, 0, ExcelPackage.MaxRows, 0); //foreach(ExcelRow row in _rows) while(cse.Next()) { var row=cse.Value as RowInternal; if (row != null && row.PageBreak) { breaks.AppendFormat("<brk id=\"{0}\" max=\"1048575\" man=\"1\" />", cse.Row); count++; } } if (count>0) { sw.Write(string.Format("<rowBreaks count=\"{0}\" manualBreakCount=\"{0}\">{1}</rowBreaks>", count, breaks.ToString())); } } ```

Commented Unassigned: Array Formulas Messed Up On 4.0 Beta [14992]

$
0
0
Hello,

I have a workbook with a summary worksheet with array formulas and a data worksheet for inputting data with EPPlus. This worked very well with 3.1.3 but trying it with the new 4.0 Beta my array formulas are getting replaced with formulas such as "=1073741825". It appears that just saving the package causes the issue. Below is the code I used to test this. Attached is a test workbook.

```
using (ExcelPackage pck = new ExcelPackage(new System.IO.FileInfo("test.xlsx")))
{
pck.Save();
}
```

Thanks,
Tyler Brinkley
Comments: I debugged the code and it looks like the issue is in ExcelWorksheet.UpdateRowCellData(StreamWriter sw). The shared formula is being stored as a string but is being compared as an int. I was able to fix it by comparing it with an int or string. Original ``` object formula = _formulas.GetValue(cse.Row, cse.Column); if (formula is int) { int sfId = (int)formula; ``` My Hack ``` object formula = _formulas.GetValue(cse.Row, cse.Column); if (formula is int || formula is string) { int sfId = (formula is int) ? (int)formula : int.Parse((string)formula); ```

Commented Unassigned: Array Formulas Messed Up On 4.0 Beta [14992]

$
0
0
Hello,

I have a workbook with a summary worksheet with array formulas and a data worksheet for inputting data with EPPlus. This worked very well with 3.1.3 but trying it with the new 4.0 Beta my array formulas are getting replaced with formulas such as "=1073741825". It appears that just saving the package causes the issue. Below is the code I used to test this. Attached is a test workbook.

```
using (ExcelPackage pck = new ExcelPackage(new System.IO.FileInfo("test.xlsx")))
{
pck.Save();
}
```

Thanks,
Tyler Brinkley
Comments: Correction to hack ``` object formula = _formulas.GetValue(cse.Row, cse.Column); int sfId; if (formula is string && int.TryParse((string)formula, out sfId)) { ```

Created Unassigned: NullReferenceException on ExcelPackage Dispose (4.0 Beta 2) [14993]

$
0
0
Using 4.0 Beta 2, ExcelPackage Dispose() is throwing a NullReferenceException after opening a blank Excel file. Please see attached sample simple Console Application for example.

Could be related to: https://epplus.codeplex.com/workitem/14979

Commented Unassigned: Page breaks is not working EPPlus 4.0 Beta 2 [14991]

$
0
0
Hi Jan

I am facing page break issue in Epplus 4.0, previously i have used EPPlus 3.1, page break was working fine in Epplus 3.1 but later i have changed the class library Epplus 4.0 beta due to Title Repeat issue in V3.1, i could not able to use both column title repeat and row title repeat simultaneously, i can use only column title repeat or Row Title repeat in EPPLUS 3.1 stable Version , so please suggest me to rectify issue in page break or Title Repeat, it would be more helpful for me

Thank you for the awesome Class library
Comments: Hi Tydude4Christ Thanks you for save my time it is working fine, Thank you so much

Commented Unassigned: LoadFromDataTable with empty Table and PrintHeaders false gives ArgumentException or ArgumentOutOfRangeException [14985]

$
0
0
I'm using 3.1.3.3.

```
using System;
using System.Data;
using OfficeOpenXml;

namespace Test
{
class Program
{
static void Main(string[] args)
{
var ep = new ExcelPackage();
var sheet = ep.Workbook.Worksheets.Add("Test");

// Make an empty table
var dt = new DataTable();
dt.Columns.Add(new DataColumn("col1"));
dt.Columns.Add(new DataColumn("col2"));

// Load empty table at A1
try
{
sheet.Cells["A1"].LoadFromDataTable(dt, false);
}
catch (ArgumentException e)
{
Console.WriteLine(e);
Console.WriteLine();
}

// Load empty table at A2
try
{
sheet.Cells["A2"].LoadFromDataTable(dt, false);
}
catch (ArgumentOutOfRangeException e)
{
Console.WriteLine(e);
Console.WriteLine();
}

Console.WriteLine("Press any key ...");
Console.ReadKey();
}
}
}
```

Output:

```
System.ArgumentException: Row out of range
at OfficeOpenXml.ExcelRange.ValidateRowCol(Int32 Row, Int32 Col)
at OfficeOpenXml.ExcelRange.get_Item(Int32 FromRow, Int32 FromCol, Int32 ToRo
w, Int32 ToCol)
at OfficeOpenXml.ExcelRangeBase.LoadFromDataTable(DataTable Table, Boolean Pr
intHeaders)

System.ArgumentOutOfRangeException: Specified argument was out of the range of v
alid values.
Parameter name: Start cell Address must be less or equal to End cell address
at OfficeOpenXml.ExcelAddressBase.Validate()
at OfficeOpenXml.ExcelAddressBase.SetAddress(String address)
at OfficeOpenXml.ExcelAddress.set_Address(String value)
at OfficeOpenXml.ExcelRange.get_Item(Int32 FromRow, Int32 FromCol, Int32 ToRo
w, Int32 ToCol)
at OfficeOpenXml.ExcelRangeBase.LoadFromDataTable(DataTable Table, Boolean Pr
intHeaders)
```
Comments: I sent a [pull request](https://epplus.codeplex.com/SourceControl/network/forks/zippy1981/LoadFromEmptyXXXNoHeaders/contribution/6737) with a fix. I need to go back and check LoadFromDataReader() too.

Created Unassigned: Change GetColumnLetter to a public method [14997]

$
0
0
It would be very useful to have GetColumnLetter() as a public method for use in adding formulas.

Edited Issue: Arbitrary buffer size is too small; crash on save [14811]

$
0
0
I have a file generated with Excel 2010 (too large to attach) that, upon loading then saving with EPPlus without any changes, results in a "Index out of range" exception and the file is not saved.

CompoundDocument::GetChunk() is responsible for the error. It uses a buffer of size 4098 to hold a copy of the chunked data to return to the caller. __There are no checks to ensure the buffer is large enough to hold all the tokens being copied!__ The chosen hard-coded size is insufficient for my file, as the code attempts to index beyond byte 4098. For my particular file, a buffer size of at least 4109 is required to avoid this crash, but this is not necessarily the limit.

To fix this specific problem, change line 240 of CompoundDocument.cs from:

```
byte[] buffer = new byte[4098];
```
to:

```
byte[] buffer = new byte[4109];
```

Ideally, the buffer size allocated would be determined by counting the required bytes in the source data.


Commented Issue: Arbitrary buffer size is too small; crash on save [14811]

$
0
0
I have a file generated with Excel 2010 (too large to attach) that, upon loading then saving with EPPlus without any changes, results in a "Index out of range" exception and the file is not saved.

CompoundDocument::GetChunk() is responsible for the error. It uses a buffer of size 4098 to hold a copy of the chunked data to return to the caller. __There are no checks to ensure the buffer is large enough to hold all the tokens being copied!__ The chosen hard-coded size is insufficient for my file, as the code attempts to index beyond byte 4098. For my particular file, a buffer size of at least 4109 is required to avoid this crash, but this is not necessarily the limit.

To fix this specific problem, change line 240 of CompoundDocument.cs from:

```
byte[] buffer = new byte[4098];
```
to:

```
byte[] buffer = new byte[4109];
```

Ideally, the buffer size allocated would be determined by counting the required bytes in the source data.


Comments: Fixed in latest source code (Default Branch).

Edited Unassigned: Seemingly arbitrary cells are unformatted on package save [14995]

$
0
0
In some cases that I haven't been able to determine a well-descriptive pattern for, EPPlus 3.1.3.3 seems to unformat (or at least corrupt the formatting of) certain cells on worksheets.

See the attached input and output xlsx files. The output file's Sheet1!D3 cell has been unformatted.

This is a method body snippet that suffices to reproduce the output from the input:

```
var path = @"C:\path\to\file.xlsx";
var fi = new FileInfo(path);
var ep = new ExcelPackage(fi);
ep.Save();
```
Viewing all 2262 articles
Browse latest View live


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