4

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?

easwee
  • 15,757
  • 24
  • 60
  • 83
RubenHerman
  • 1,674
  • 6
  • 23
  • 42

4 Answers4

18

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

RubenHerman
  • 1,674
  • 6
  • 23
  • 42
3

Try using Excel.Range.NumberFormat instead of Excel.Range.Style

TheQ
  • 508
  • 5
  • 15
0

Try using Excel.Range.Style.NumberFormat.Format="#,###.00%"

Nikolay Kostov
  • 16,433
  • 23
  • 85
  • 123
-1

Try this procentRange.NumberFormatLocal = "0.00%"

david
  • 391
  • 3
  • 11