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

Created Unassigned: What is the easiest way to export a dataTable to Excel in C# [15507]

$
0
0
I have found lots of examples and tutorials about how to export a DataTable as Excel by using epplus, but I cannot find a direct way to do it. Therefore I tried the following code..


my dataTable:

```
===============================
d1 | d2 | d3
===============================
aa1 | bb1 | cc1
aa2 | bb2 | cc2
aa3 | bb3 | cc3
aa4 | bb4 | cc4
```

script:

```
using OfficeOpenXml;
using OfficeOpenXml.Drawing;

//........
protected viod exportToExcel (dataTable dt)
{
try
{

Response.Clear();
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
Response.AddHeader("content-disposition", "attachment;filename=" + HttpUtility.UrlEncode("Logs.xlsx", System.Text.Encoding.UTF8));

using (ExcelPackage pck = new ExcelPackage())
{
ExcelWorksheet ws = pck.Workbook.Worksheets.Add("Logs");
ws.Cells["A1"].LoadFromDataTable(dt, true);
var ms = new System.IO.MemoryStream();
pck.SaveAs(ms);
ms.WriteTo(Response.OutputStream);
}

}
catch (Exception ex)
{
Debug("error: " + ex.Message);//catch nothing
}

}
```
It returns a server error and no any exception is caught, so I have no idea what error happens..

However, no error occurs when I remove the

```
using (ExcelPackage pck = new ExcelPackage())
```
section in above code.

Any ideas?

Commented Unassigned: Pivot Table based on a Named Range [15421]

$
0
0
There is an issue with saving a workbook which contains a Pivot Table based on a Named Range.
Please find attached three workbooks which suffer from this issue. To replicate the issue, just open one of these workbooks with EPPlus and save.

EPPlus throws "Object reference not set to an instance of an object" in line 3191, ExcelWorksheet.cs, because variable "ws" is set to null.
Comments: The issue still exists in version 4.1 (643d411b032b). In ExcelWorksheet.cs, in the SavePivotTables method, can you please add this: 3381: var ws = Workbook.Worksheets[pt.CacheDefinition.SourceRange.WorkSheet]; if (ws != null) { //<- add this check //lines 3382 to 3430 } 3431: pt.PivotTableXml.Save(pt.Part.GetStream(FileMode.Create));

Created Unassigned: Worksheets return System.NullReferenceException when loading xlsx with hyperlinks created by SSRS [15508]

$
0
0
__Description:__
A report is created by SSRS (SQL Server Reporting Services) in XLSX format.
After loading the file with EPPlus, a System.NullReferenceException is thrown when trying to access the worksheets. Opening the file in Microsoft Excel works just fine, and saving the file here an opening the new Microsoft copy no longer produces the exception.

__Solution:__
It looks like the problem is that hyperlink definition nodes are not self-closing, similar to Issue #14784.
```
<hyperlinks>
<hyperlink ref="E6" location="&apos;AP Invoice Detail&apos;!H9">
</hyperlink>
...
```

This can fixed with a similar skip logic:
```
while(xr.Read())
{
//08.08.2016 by Brandon Lawrence, to ignore </hyperlink> End Element
if (xr.NodeType == XmlNodeType.EndElement) continue;
if (xr.LocalName == "hyperlink")
{ ...
```




An example of the file giving the error is attached.

Edited Unassigned: Worksheets return System.NullReferenceException when loading xlsx with hyperlinks created by SSRS [15508]

$
0
0
__Description:__
A report is created by SSRS (SQL Server Reporting Services) in XLSX format.
After loading the file with EPPlus, a System.NullReferenceException is thrown when trying to access the worksheets. Opening the file in Microsoft Excel works just fine, and saving the file here an opening the new Microsoft copy no longer produces the exception.

__Solution:__
It looks like the problem is that hyperlink definition nodes are not self-closing, similar to Issue #14784.
```
<hyperlinks>
<hyperlink ref="E6" location="'AP Invoice Detail'!H9">
</hyperlink>
...
```

This can fixed with a similar skip logic:
```
while(xr.Read())
{
//08.08.2016 by Brandon Lawrence, to ignore </hyperlink> End Element
if (xr.NodeType == XmlNodeType.EndElement) continue;
if (xr.LocalName == "hyperlink")
{ ...
```




An example of the file giving the error is attached.

Created Unassigned: Problem with Persian Fonts [15509]

$
0
0
I found out that ٍEPPlus has problem with Persian fonts like "B Nazanin". when I open an existed excel file and change some cell values, then saving using SaveAs method it becomes fail in saving persian fonts correctly.
when you open saved file in MS Excel you can see that the font is not correct. you can see correct font when you change the cell's font to another font and then change it again to "B Nazanin".
by checking Styles.xl file in back of excel file we can see that 'charset' tag of persian fonts are removed.
that caused font does'nt affect on strings and just showing its name in font name.
by adding this removed tag to styles it becomes fine.


Created Unassigned: Strange behavior in AutoFitColumns [15510]

$
0
0
I encountered a very strange behavior in Autofit. The following code resizes columns 1 and 2:

```
ExcelWorksheet worksheet = pack.Workbook.Worksheets.Add("Inventory");
worksheet.Cells[1, 1].Value = "foo";
worksheet.Cells[1, 2].Value = "bar";
worksheet.Cells.AutoFitColumns(0);
```

If I remove one of the two setters, it doesn't resize anything.

This behavior seems to be independent from the rest of the document: if one of the cells A1 or B1 is empty, AutoFitColumns doesn't do anything.

Created Unassigned: ROUND(626.3,-3) returns incorrect result [15511]

$
0
0
The round function seems to always do a truncate when the second argument is negative, which is incorrect.

See here: https://support.office.com/en-us/article/ROUND-function-c018c5d8-40fb-4053-90b1-b3e7f61a213c#tblID0EABBAAA

Edited Unassigned: ROUND(626.3,-3) returns incorrect result [15511]

$
0
0
The round function seems to always do a truncate when the second argument is negative, which is incorrect. EPPlus returns 0, while Excel returns 1000.

See here: https://support.office.com/en-us/article/ROUND-function-c018c5d8-40fb-4053-90b1-b3e7f61a213c#tblID0EABBAAA

Another example is ROUND(25.2,-1) in which EPPLUS returns 20, while excel returns 30.


Commented Unassigned: ROUND(626.3,-3) returns incorrect result [15511]

$
0
0
The round function seems to always do a truncate when the second argument is negative, which is incorrect. EPPlus returns 0, while Excel returns 1000.

See here: https://support.office.com/en-us/article/ROUND-function-c018c5d8-40fb-4053-90b1-b3e7f61a213c#tblID0EABBAAA

Another example is ROUND(25.2,-1) in which EPPLUS returns 20, while excel returns 30.

Comments: Fixed here: https://epplus.codeplex.com/SourceControl/network/forks/Motley/EPPlusRoundingFix/contribution/8927

Created Unassigned: Concat operator can throw a NullReferenceException with an empty ExcelAddressExpression [15512]

$
0
0
ExcelAddressExpressions can be modified to always return an IRangeInfo. If the content of a single cell range is empty, the IRangeInfo is null and OfficeOpenXml.FormulaParsing.Excel.Operators.Operator.Concat() performs a .ToString() on it, causing a NullReferenceException.

Commented Unassigned: Concat operator can throw a NullReferenceException with an empty ExcelAddressExpression [15512]

$
0
0
ExcelAddressExpressions can be modified to always return an IRangeInfo. If the content of a single cell range is empty, the IRangeInfo is null and OfficeOpenXml.FormulaParsing.Excel.Operators.Operator.Concat() performs a .ToString() on it, causing a NullReferenceException.
Comments: Resolved in fork: https://hg.codeplex.com/forks/pdxsam/concatemptyrangefix

Created Unassigned: Comment handling several errors [15513]

$
0
0
The following code adds, then deletes comments.

Create a worksheet with a few cells in Excel. Run this code, which will add a comment and save.

Rerun the code in debug, and notice that the "comments" collection count is 2 (should be one) and although you can delete it, you can then re-add the comment that will corrupt the xml. Both comments have the same address.

I've tried different ways to delete the comments...this implementation is just one of several I have tried. None have worked correctly. Sometimes a comment can be deleted, and then the cell will show comments == null, but when adding one it throws "comment already exists" error.

Version of EPPLUS is 4.1.0.0.

There are reports that the comment deletion errors were fixed in 2012...has there been a regression?

Anybody else have these problems?


FileInfo file = new FileInfo("D:\\test.xlsx");
using (var pck = new ExcelPackage(file))
{
var ws = pck.Workbook.Worksheets[1];

ws.Cells[1, 1].AddComment("abc", "def");

for (int row = ws.Dimension.End.Row; row>0;row--)
{
for (int col=ws.Dimension.End.Column;col>0;col--)
{
if (ws.Cells[row,col].Comment!=null)
{
ws.Comments.Remove(ws.Cells[row, col].Comment);
}
}
}

ws.Cells[1, 1].AddComment("xyz", "pdq");

pck.Save();

Created Unassigned: NullReferenceException adding comments in the last two rows [15514]

$
0
0
When running the following code (using either 4.1 or the current source after 0271551045e6) a NullReferenceException is thrown from CellStore.NextCell() during the call to ExcelRange.AddComment:

ExcelPackage ep = new ExcelPackage(new FileInfo(@"c:\test.xlsx"));
ExcelWorksheet es = ep.Workbook.Worksheets.Add("test");
for (int i = 1048575; i <= 1048576; i++)
{
ExcelRange er = es.Cells[i, 1];
ExcelComment ec = er.AddComment("info", "me"); // NullReferenceException when i reaches 1048576!
}
ep.Save();

When just adding a comment to cell A1048576 everything works fine.

I see this may not be a case that would happen everyday, but we're exporting pretty large data sets spanning several work sheets (and sometimes need a couple of comments in the last few lines, too).

Any help would be greatly appreciated!

Created Unassigned: Change chart type by [15515]

$
0
0
I've tried to create a chart with 2 columns and 2 lines. But it doesn't work : when I try to open the excel file, excel needs to repair it, and the chart doesn't appear. Here is the error log :
> <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<recoveryLog xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"><logFileName>error085000_01.xml</logFileName><summary>Errors were detected in file 'C:\Users\dev\AppData\Local\Temp\test-2.xlsx'</summary><removedParts summary="Following is a list of removed parts:"><removedPart>Removed Part: /xl/drawings/drawing1.xml part. (Drawing shape)</removedPart></removedParts></recoveryLog>

It works with 2 columns and one line but not with 2 columns and 2 lines.

Here is the code I wrote :
```
ExcelChart chart = (ExcelChart)ws.Drawings.AddChart(indicator.Title, eChartType.ColumnClustered);
var chartTypeLine = chart.PlotArea.ChartTypes.Add(eChartType.Line);
foreach (KeyValuePair<string,Tuple<ExcelRange, string>> kvRange in chartRangeDic)
{
if (string.Equals(kvRange.Value.Item2, "Column"))
{
var serieColumn = chart.Series.Add(kvRange.Value.Item1, xAxisRange);
serieColumn.Header = kvRange.Key;
}
else
{
var serieLine = chartTypeLine.Series.Add(kvRange.Value.Item1, xAxisRange);
serieLine.Header = kvRange.Key;
}
}
```
Is it possible to create the chart with EPPlus ?

Thanks

Edited Unassigned: Change chart type by serie [15515]

$
0
0
I've tried to create a chart with 2 columns and 2 lines. But it doesn't work : when I try to open the excel file, excel needs to repair it, and the chart doesn't appear. Here is the error log :
> <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<recoveryLog xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"><logFileName>error085000_01.xml</logFileName><summary>Errors were detected in file 'C:\Users\dev\AppData\Local\Temp\test-2.xlsx'</summary><removedParts summary="Following is a list of removed parts:"><removedPart>Removed Part: /xl/drawings/drawing1.xml part. (Drawing shape)</removedPart></removedParts></recoveryLog>

It works with 2 columns and one line but not with 2 columns and 2 lines.

Here is the code I wrote :
```
ExcelChart chart = (ExcelChart)ws.Drawings.AddChart(indicator.Title, eChartType.ColumnClustered);
var chartTypeLine = chart.PlotArea.ChartTypes.Add(eChartType.Line);
foreach (KeyValuePair<string,Tuple<ExcelRange, string>> kvRange in chartRangeDic)
{
if (string.Equals(kvRange.Value.Item2, "Column"))
{
var serieColumn = chart.Series.Add(kvRange.Value.Item1, xAxisRange);
serieColumn.Header = kvRange.Key;
}
else
{
var serieLine = chartTypeLine.Series.Add(kvRange.Value.Item1, xAxisRange);
serieLine.Header = kvRange.Key;
}
}
```
Is it possible to create the chart with EPPlus ?

Thanks

Commented Unassigned: Issue with Named Styles [15506]

$
0
0
In the version 4.1 following code throws exception:

```
ens = ep.Workbook.Styles.CreateNamedStyle("Test")
Dim bTestOK As Boolean = ens.Style.WrapText
ens.Style.HorizontalAlignment = OfficeOpenXml.Style.ExcelHorizontalAlignment.Center
Dim bTestNG As Boolean = ens.Style.WrapText
```


Here are the exception details.


```
=== System.ArgumentOutOfRangeException =========================
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
----------------------------
Source: mscorlib
----------------------------
at System.ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument argument, ExceptionResource resource)
at System.Collections.Generic.List`1.get_Item(Int32 index)
at OfficeOpenXml.ExcelStyleCollection`1.get_Item(Int32 PositionID) in <path>\EPPlus\36\e1834888\ExcelStyleCollection`1.cs:line 30
at OfficeOpenXml.Style.ExcelStyle.get_WrapText() in <path>\EPPlus\52\de9556c8\ExcelStyle.cs:line 60
```

Each time the style is changing an internal hash key of all values is created for inventory of identical styles and stored in Id property.
For example

```
General|Calibri110FFFFNone|None0000|None00None00None00None00None00FalseFalse|Bottom|General|False|ContextDependent|1|False
```

The hash key includes XfId at the second to last location.
I think this could be a mistake and should not be a part of the hash key.

Workaround for the issue is to save and re-open the file before accessing attributes of the Named Styles.

Comments: The problem could stem from the NamedStylePropertyChange functions, which perhaps incorrectly modifies the index of the style in its own collection. The file is: \EPPlus\ExcelStyles.cs ``` /// <summary> /// Handles property changes on Named styles. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> /// <returns></returns> internal int NamedStylePropertyChange(StyleBase sender, Style.StyleChangeEventArgs e) { int index = NamedStyles.FindIndexByID(e.Address); if (index >= 0) { int newId = CellStyleXfs[NamedStyles[index].StyleXfId].GetNewID(CellStyleXfs, sender, e.StyleClass, e.StyleProperty, e.Value); int prevIx=NamedStyles[index].StyleXfId; NamedStyles[index].StyleXfId = newId; NamedStyles[index].Style.Index = newId; // *** the index of the style in the list should not be modified NamedStyles[index].XfId = int.MinValue; foreach (var style in CellXfs) { if (style.XfId == prevIx) { style.XfId = newId; } } } return 0; } ```

Created Unassigned: Use user defined functions in cell (calculation) [15516]

$
0
0
EPPlus offers a lot of functionality but I somehow miss one. Is it by design or am I just missing something? I would like EPPlus to calculate user defined functions, as often found in a vba code module. As a result of the calculation function, the #NAME? is the value of the cell and the FormulaParserManager Logging shows:

Timestamp: 16.08.2016 10:29:24

Worksheet: inputs and calculations
Address: O10
'MyFunctionInVBAModule' is not a supported function

Please let me know what I have to change/expect.

thx. Peter

Created Unassigned: Hyperlink fragment identifiers are not returned [15517]

$
0
0
URL fragment identifiers (like #foo in http://example.com/#foo) are not returned from the spreadsheet XML.

The example sheet contains a single cell with the formula `HYPERLINK("http://example.com/#foo", "Click here")`. The getter method for ExcelRangeBase.Hyperlink should return a Uri object containing the full "http://example.com/#foo" string, but instead it only has "http://example.com". I created the sheet in Google Sheets, then downloaded it as an xlsx file.

The hyperlink object is stored in the XML across two files.

The first part is in sheet1.xml:

```
<hyperlinks>
<hyperlink location="foo" r:id="rId1" ref="A1"/>
</hyperlinks>
```

The second part is in sheet1.xml.rels:

```
<Relationship Id="rId1" Target="http://example.com/" TargetMode="External" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink"/>
```

EPPlus correctly resolves "rId1" to the Target string "http://example.com", but fails to concatenate it with the location attribute "foo".

Here's a first cut at a fix in Worksheet.cs, in the LoadHyperLinks method. This code reads in the value of the location attribute and includes it in the ExcelHyperLink object:

```
//...
    var location = xr.GetAttribute("location");
    location = (string.IsNullOrEmpty(location)) ? "" : "#" + location;

    if (uri.IsAbsoluteUri)
    {
    try
        {
        hl = new ExcelHyperLink(uri.AbsoluteUri + location);
        }
        catch
        {
        hl = new ExcelHyperLink(uri.OriginalString + location, UriKind.Absolute);
        }
    }
    else
    {
    hl = new ExcelHyperLink(uri.OriginalString + location, UriKind.Relative);
    }
//...
```

Created Unassigned: EPPlus Cell from ExcelRange [15518]

$
0
0
This problem has me completely puzzled.

I have a Excel document which loads in just fine.
It has rows, columns and data and I want to iterate through the rows.
But EPPLus is odd.

I take the second row:

```
ExcelRange range1 = worksheet.Cells[2, worksheet.Dimension.Start.Column, 2, worksheet.Dimension.End.Column];

```
Which gives me `{A2:D2}` Splendid! so far so good but then I want the first cell of the row:

```
ExcelRange range2 = range1[1,1];
```

Which give me `{A1}` and to make matter worse, the value of `range1` has also changed to `{A1}` instead of the row I selected.

How can I resolve this issue and take a ExcelRange from an ExcelRange?

This has me completely puzzled .... thanks for anyhelp

Created Unassigned: LoadFromText creates Table that is one row to long [15519]

$
0
0
If i create a Table from a CSV File the Excel Table has one empty row at the end.

Any suggestions?

regards, André

![Image](http://www.garnbleiche.de/issue.png)

```
using OfficeOpenXml;
using OfficeOpenXml.Table;
using System.IO;
using System.Reflection;

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

var format = new ExcelTextFormat() { Delimiter = ';' };

string csv = "first name;last name\r\nFrank;Smith\r\nJustin;Meier\r\nBastian;Poth\r\nGunther;Meier";

var range = sheet.Cells["A1"].LoadFromText(csv, format, TableStyles.Medium21, true);

string excelfile = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "test.xlsx");
package.SaveAs(new FileInfo(excelfile));
}
}
}
}
```
Viewing all 2262 articles
Browse latest View live


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