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

Commented Unassigned: ColumnMax can not span over existing column 3. Exception when accessing Style of empty ExcelRange [15018]

$
0
0
Hello, I encountered above exception when - under certain circumstances - I try to access the style of an ExcelRange. Below you find a minimal self-contained program that reproduces the issue, when using EPPlus 4.0 Beta 2. This issue does not occur with the current stable 3.x version of EPPlus.

The program generates two excel files. In the first case the data block contains 4x4 cols/rows of data and everything works fine. The second time it tries to generate a file with 25x25 blocks. This time I encounter above issue. The issue can be worked around by assigning some value to the Value-property of the Range before accessing its style property.

```
using System.IO;
using OfficeOpenXml;
using OfficeOpenXml.Style;

namespace ConsoleApplication10 {
class Program {
static void Main() {
CreateXlsxSheet("test4.xlsx", 4, 4);
CreateXlsxSheet("test25.xlsx", 25, 25); }

private static void CreateXlsxSheet(string pFileName,int pRows,int pColumns) {
if(File.Exists(pFileName)) File.Delete(pFileName);

using(ExcelPackage excelPackage = new ExcelPackage(new FileInfo(pFileName))) {
ExcelWorksheet excelWorksheet = excelPackage.Workbook.Worksheets.Add("Testsheet");

// Fill with data
for (int row = 1; row <= pRows; row++) {
for (int column = 1; column <= pColumns; column++) {
if (column > 1 && row > 2) {
using (ExcelRange range = excelWorksheet.Cells[row, column]) {
range.Style.Numberformat.Format = "0";
range.Style.HorizontalAlignment = ExcelHorizontalAlignment.Right;
range.Style.VerticalAlignment = ExcelVerticalAlignment.Center; }
excelWorksheet.Cells[row, column].Value = row*column; } } }

// Try to style the first column, begining with row 3 which has no content yet...
using (ExcelRange range = excelWorksheet.Cells[ExcelCellBase.GetAddress(3, 1, pRows, 1)]) {
ExcelStyle style = range.Style; }

// now I would add data to the first column (left out here)...
excelPackage.Save(); } } } }
```
Comments: Fixed in commit c35695785810

Viewing all articles
Browse latest Browse all 2262

Trending Articles



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