Home » excel » c# – How do I make Excel cell contents show a different value

c# – How do I make Excel cell contents show a different value

Posted by: admin April 23, 2020 Leave a comment

Questions:

I have an Excel VSTO file that makes a chart with the help of the data entered.
Whenever a cell gets a value ‘e’ it sums the value of all other cells and displays the result in that cell.

I want the cell to keep showing the value ‘e’ instead of the sum that is calculated.
How can I do this?

How to&Answers:

You can just give the cell a NumberFormat of "e". This will display e but not change the underlying value of the cell…

You will need to escape the quotation marks.

Target.NumberFormat = "\"e\"";

NB.

(this method will only work if the underlying value of the cell is a number).

Answer:

Select the cells you want to format and run:

Sub ChangeToText()
    Dim DQ As String, mesage As String
    DQ = Chr(34)
    mesage = DQ & "e" & DQ
    Selection.NumberFormat = mesage & ";" & mesage & ";" & mesage & ";"
End Sub

You will need to adapt this to c#