Excel c# convert cell to percentage

后端 未结 4 1937
陌清茗
陌清茗 2021-01-19 04:17

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\"
相关标签:
4条回答
  • 2021-01-19 04:54

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

    0 讨论(0)
  • 2021-01-19 04:57

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

    0 讨论(0)
  • 2021-01-19 05:02

    Try this procentRange.NumberFormatLocal = "0.00%"

    0 讨论(0)
  • 2021-01-19 05:05

    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

    0 讨论(0)
提交回复
热议问题