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

Commented Unassigned: Invalid URL Exception [14858]

$
0
0
Hi!

I have a problem, if I try to open an XLSX file with EPPlus. The File was created with Microsoft Office 2010.

My code is:

```
foreach (string fajl in fajlok)
{
FileInfo fn = new FileInfo(@fajl);
string indicated_user = fn.Name.Split('_')[0];
ExcelPackage ep = new ExcelPackage(fn);

Constans.GLOBALLOG.LogWrite(ep.Workbook.Worksheets.Count().ToString());
if (ep.Workbook.Worksheets.Count() == 3)
{
.....
```

The Exception occurs at ep.Workbook.Worksheets.Count().
I read, that this problem has already fixed, however, it happened...

Is any fix for this problem?
I use the latest DLL version: EPPlus 3.1 Apr 11, 2012, Stable

Thanks for the answer!
Zsolt Abdai
Comments: Hi! I fixed this problem. The main reason for the exception is, that Microsoft allows you to put INVALID hyperlink to the cells. I put this value in a cell: ecsomany@google:huszar and I hit enter in my Excel, than a hyperlink was created, however, the link is invalid. (mailto: ecsomany@google:huszar) Sad, that in Office 2013 is this bug present too... In your code: if you found Hyperlink in the worksheet, you try to parse it, and the invalid URI exception occours. I checked out the source of your latest version and modified only one method, you can use it. In ExcelWorksheet.cs at line 784 is a method, which load and validate the hyperlinks: called LoadHyperLinks In the third if section I wrote a catch, if any exception occours by parsing the Uri. In this case I set cell.Hyperlink = new Uri(""); ``` if (xr.GetAttribute("id", ExcelPackage.schemaRelationships) != null) { cell.HyperLinkRId = xr.GetAttribute("id", ExcelPackage.schemaRelationships); try { var uri = Part.GetRelationship(cell.HyperLinkRId).TargetUri; try { if (uri.IsAbsoluteUri) { cell.Hyperlink = new ExcelHyperLink(HttpUtility.UrlDecode(uri.OriginalString)); } else { cell.Hyperlink = new ExcelHyperLink(HttpUtility.UrlDecode(uri.OriginalString), UriKind.Relative); } } catch { //We should never end up here, but to aviod unhandled exceptions we just set the uri here. JK cell.Hyperlink = uri; } } catch { //if the hiperlink is invalid, just ignore and reset the link to empty URL cell.Hyperlink = new Uri(""); } Part.DeleteRelationship(cell.HyperLinkRId); //Delete the relationship, it is recreated when we save the package. } ``` I attached my solution CS file. Best regards, Zsolt Abdai

Viewing all articles
Browse latest Browse all 2262

Trending Articles



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