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

Commented Unassigned: ExcelAddress has "" for WorkSheet [15503]

$
0
0
The _public ExcelAddress(int fromRow, int fromCol, int toRow, int toColumn);_ constructor causes the non-public _WorkSheet_ prooperty (and __ws_ variable) to be set to "" instead of _null_. This causes my code to add a table to a worksheet to fail:

```
ExcelAddress tableRange = new ExcelAddress(headerCells.Start.Row, headerCells.Start.Column, headerCells.End.Row + rowCount, headerCells.End.Column);
ExcelTable table = headerCells.Worksheet.Tables.Add(tableRange, newTableName);
```

Attaching with the debugger and changing the value to null allows the code to run, but there is no way to fix this without the debugger.
The code worked in a previous version (3.5 I think).

Resulting error message (System.ArgumentException):
> Range does not belong to worksheet
> Parameter name: Range
Comments: I found a work around: ``` ExcelAddress tableRange = new ExcelAddress(headerCells.Start.Row, headerCells.Start.Column, headerCells.End.Row + rowCount, headerCells.End.Column); //The above ExcelAddress constructor does not properly clear the worksheet name (uses "" instead of null). This code works around the bug. string worksheetName = '\'' + headerCells.Worksheet.Name.Replace("\'", "'") + '\''; //get the safe version of the worksheet name. tableRange = new ExcelAddress(worksheetName + "!" + tableRange.Address); //Create a new ExcelAddress using the string representation, including the worksheet name. ExcelTable table = headerCells.Worksheet.Tables.Add(tableRange, newTableName); ```

Viewing all articles
Browse latest Browse all 2262

Trending Articles



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