C++/CLI syntax on VerticalAlignment e.g.

Mar 6, 2013 at 1:41 PM
Hi volks,

i have to say, that i'm a beginner in programming (only some C-Code and java in the past) and have some problems to "convert" some of the C#-examples to my C++/CLI Code. (Apart from that: great lib ;) ).

Currently i'm working on the cellformat and have problems with the syntax for the verticalAlignment or BackgroundColors (e.g.).

C# Code from some examples:
ws.Cells.Style.VerticalAlignment = ExcelVerticalAlignment.Center;
ws->Cells->Style->VerticalAlignment->Top;   => [error C2039: 'Top' : is not a member of 'System::Enum']
ws->Cells->Style->VerticalAlignment = ExcelVerticalAligment->Top;    [error C2275: 'OfficeOpenXml::Style::ExcelVerticalAlignment' : illegal use of this type as an expression]

both and many other variants arent working :(  

[error C2065: 'Color' : undeclared identifier]
[error C2227: left of '->Green' must point to class/struct/union/generic type]
I've replaced the "." with "->" - no question of that, but that doesnt fit with all lines of Code.
Furthermore I tested with :: (no success) or so on... well...
... apart from that, i can generate excelsheets now, but only without the settings above.
Maybe youre asking yourself why i'm using C++/CLI ... a good question - currently i'm really thinking to switch to C# at all (mainly because of the thousands of C#-examples) :/.
Mar 6, 2013 at 3:08 PM
Skill comes with practice ;)

I've resolved ...
ws.Cells.Style.VerticalAlignment = ExcelVerticalAlignment.Center [/or Top ;)  ];
ws->Cells->Style->VerticalAlignment = ExcelVerticalAlignment::Top;
obviously this was the only way i dont try before i posted here... .
Same procedure with:
ws->Cells[x, y]->Style->Border->Bottom->Style = ExcelBorderStyle::Thick;

Unfortunately the BackgroundColor seems to work in another way - obviously a function/method - but actually I have no clue or luck ( ;) ) to resolve the problem.
Mar 7, 2013 at 10:25 AM
Edited Mar 7, 2013 at 10:26 AM
This C# code will set a cell background color:
    worksheet.Cells["A1:B1"].Style.Fill.PatternType = ExcelFillStyle.Solid;
    worksheet.Cells["A1:B1"].Style.Fill.BackgroundColor.SetColor(Color.FromArgb(79, 129, 189));
The Color.FromArgb(79, 129, 189) bit references a 'using System.Drawing'
Mar 7, 2013 at 3:08 PM
Edited Mar 11, 2013 at 9:55 AM

With your help i found my mistakes in the c++/cli-Code ;)

I have to add the following lines/things:

C++/CLI (!)
#using <System.Drawing.dll>
using namespace System::Drawing;

worksheet->Cells[x, y]->Style->Fill->PatternType = ExcelFillStyle::Solid;
worksheet->Cells[x, y]->Style->Fill->BackgroundColor->SetColor(Color::Gray);
The "using"-part was the main point i forgot ...