Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Excel c# convert cell to percentage

I need to convert a cell with a double to a precentage. I used a macro in excel and it says:

Range("B5").Select
Selection.Style = "Percent"

When I do this in c#, it doesn't work:

Excel.Range procentRange = xlWorksheet.get_Range("A1","A1");
procentRange.Style = "Percent";

Anybody knows how to do this?

like image 627
RubenHerman Avatar asked Dec 02 '22 05:12

RubenHerman


1 Answers

I've found the anwser with help of JN Web

Excel.Range procentRange = xlWorksheet.get_Range("A1","A1");    
procentRange.NumberFormat = "###,##%";

So first you need a range, then set the decimals and add "%" -> automatically a 100 time multiplication

like image 59
RubenHerman Avatar answered Dec 04 '22 20:12

RubenHerman