Excel interop - how to stop number (stored as text) being “evaluated”

前端 未结 4 1246
梦如初夏
梦如初夏 2021-01-13 09:24

I was wondering if anyone had come across the following problem and had any ideas on how to resolve it: I\'m exporting data from a C# application (.NET 3.5) to Excel (2003)

4条回答
  •  半阙折子戏
    2021-01-13 09:42

    I use this macro. It inserts an apostrophe before each value that is numeric in each cell.

    Sub Macro1()
        Dim rwIndex As Integer
        Dim colIndex As Integer
        For rwIndex = 1 To ActiveSheet.UsedRange.Rows.Count
                For colIndex = 1 To ActiveSheet.UsedRange.Columns.Count
                    If IsNumeric(Cells(rwIndex, colIndex).Value) Then _
                        Cells(rwIndex, colIndex).Value = "'" _
                         & Cells(rwIndex, colIndex).Value
                Next colIndex
        Next rwIndex
    End Sub
    

提交回复
热议问题