Skip to content
This repository has been archived by the owner on Mar 9, 2020. It is now read-only.
This repository has been archived by the owner on Mar 9, 2020. It is now read-only.

ColumnMax exception when AutoFitColumns call followed by setting VerticalAlignment #27

Closed
@davidgeewhiz

Description

Here is a small test that will throw a "ColumnMax can not span..." exception (VS C++ project). It seems that the VerticalAlignment statement causes the exception if it is set AFTER the AutoFitColumns call.

This worked fine in version 4.0.4.0, I am now having to update to 4.1.1.0 because of the recent horrible VBA issue.

The exception does not occur if the alignment is set BEFORE the autofit call, but the effect will be that ALL columns to the right of column 3 will be hidden, not just 4 and 5. Is this the expected behavior? In 4.0.4.0 the alignment being set AFTER the autofit call ONLY hides columns 4 and 5.

============================================================
FileInfo ^file = gcnew FileInfo("C:\Temp\Test.xlsx");

ExcelPackage ^pck = gcnew ExcelPackage(file);
ExcelWorksheet ^ws = pck->Workbook->Worksheets->Add("Worksheet");

if (ws != nullptr) {
ws->Cells["A1"]->Value = "Cell value 1";
ws->Cells["B1"]->Value = "Cell value 2";
ws->Cells["C1"]->Value = "Cell value 3";
ws->Cells["D1"]->Value = "Cell value 4";
ws->Cells["E1"]->Value = "Cell value 5";
}

//ws->Cells->Style->VerticalAlignment = ExcelVerticalAlignment::Top; // Columns 4 and greater hidden
ws->Cells->AutoFitColumns(0);
ws->Cells->Style->VerticalAlignment = ExcelVerticalAlignment::Top; // 4.1.1.0 - exception, 4.0.4.0 - columns 4 and 5 hidden

ws->Column(4)->Hidden = true;
ws->Column(5)->Hidden = true; // span exception

pck->Save();

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions