【问题标题】:VSTO Localization issue .FindnextVSTO 本地化问题 .Findnext
【发布时间】:2018-04-22 07:54:53
【问题描述】:

我在 Excel VSTO 解决方案中遇到了 .Findnext 的一个奇怪问题。该代码在英语设置下运行良好,但在德语设置下失败并出现以下错误。

System.NullReferenceException: '对象引用未设置为对象的实例。'

调查时,EndRng = .FindNext(EndRng) 不返回任何内容。这个块怎么可能在英语设置下工作而不在德语设置下工作?

Dim StartRng As Excel.Range, EndRng As Excel.Range
Dim wrkSheet As Worksheet
Dim wb As Excel.Workbook = Globals.ThisAddIn.Application.ActiveWorkbook
Dim xlapp As Excel.Application = Globals.ThisAddIn.Application

Dim FormulaToFind As String = FormulaToLocal(FormulaString)
wrkSheet.Range(wrkSheet.Cells(RowStart, ColStart), wrkSheet.Cells(RowEnd, ColEnd)).Select()       
With xlapp.ActiveWindow.Selection
          StartRng = .Find(FormulaToFind, LookIn:=Excel.XlFindLookIn.xlFormulas, LookAt:=Excel.XlLookAt.xlPart)
          If Not StartRng Is Nothing Then
             EndRng = StartRng
             StartAddress = StartRng.Address
             Do
                EndAddress = EndRng.Address
                EndRng = .FindNext(EndRng)
                Loop While Not EndRng Is Nothing And EndRng.Address <> StartAddress
          End If
      End With

以下是将公式转换为本地的函数

 Public Function FormulaToLocal(ByVal RefFormula As String) As String
    Dim wb As Excel.Workbook = Globals.ThisAddIn.Application.ActiveWorkbook
    Dim TmpSheet As String = "TmpSheet"
    wb.Worksheets(TmpSheet).Range("AZ1").Formula = RefFormula 
    FormulaToLocal= wb.Worksheets(TmpSheet).Range("AZ1").Formulalocal
    wb.Worksheets(TmpSheet).Range("AZ1").value = ""
End Function

【问题讨论】:

  • 你需要给我们一个可以用来复制的例子。 FormulaString 是什么?你确定你从 `FormulaToLocal 中得到了你期望的值吗?
  • @CindyMeister FormulaString 的值为“=TRANSPOSE(MMULT(V49:X51,TRANSPOSE(C48:E48)))”。函数 FormulaToLocal 返回“=MTRANS(MMULT(V49:X51,MTRANS(C48:E48)))”,这是德语等效项。该功能完全按预期工作。该公式作为矩阵公式在 3 个连续行中重复。我需要检查公式是否应用了 3 次。

标签: excel localization vsto


【解决方案1】:

Microsoft 承认这存在一些问题。他们正在与高级工程师一起调查。以下是来自 Microsoft Community 的 Andreas 建议的替代解决方案。

With rngData
    StartRng = .Find(FormulaToFind, LookIn:=Excel.XlFindLookIn.xlFormulas, LookAt:=Excel.XlLookAt.xlPart,
                     SearchOrder:=Excel.XlSearchOrder.xlByRows, SearchDirection:=Excel.XlSearchDirection.xlNext)
    If Not StartRng Is Nothing Then
        EndRng = StartRng
        StartAddress = StartRng.Address
        Do
            EndAddress = EndRng.Address
            EndRng = .Find(FormulaToFind, After:=EndRng, LookIn:=Excel.XlFindLookIn.xlFormulas, LookAt:=Excel.XlLookAt.xlPart,
        SearchOrder:=Excel.XlSearchOrder.xlByRows, SearchDirection:=Excel.XlSearchDirection.xlNext)

        Loop While Not EndRng Is Nothing And EndRng.Address <> StartAddress
    End If
End With

【讨论】:

    猜你喜欢
    • 2010-12-16
    • 1970-01-01
    • 2012-03-26
    • 1970-01-01
    • 2011-02-18
    • 2011-07-11
    • 2011-02-23
    • 1970-01-01
    相关资源
    最近更新 更多