【问题标题】:C# Excel Dialog color paletteC# Excel 对话框调色板
【发布时间】:2022-07-19 22:09:19
【问题描述】:

如何通过 C# 为调色板设置 Excel 对话框,以便用户可以选择单元格颜色?

在 VBA 中,这可以通过以下代码完成:

If Application.Dialogs(84).Show <> False Then
        varColor = .Cells(3, enuFormatting.CellColor).Interior.Color
        'Convert Color to RGB
        modul.Color_RGB varColor, intRed, intGreen, intBlue
        'Preview
        Me.lbl_FormatFont.BackColor = RGB(intRed, intGreen, intBlue)
    End If

 Public Sub Color_RGB(ByVal varColor As Variant, ByRef intRed As Integer, ByRef intGreen As Integer, ByRef intBlue As Integer)
    'Convert color index to RGB
    On Error Resume Next
    intRed = varColor Mod 256
    varColor = (varColor - intRed) / 256
    intGreen = varColor Mod 256
    varColor = (varColor - intGreen) / 256
    intBlue = varColor Mod 256
End Sub

问候

【问题讨论】:

    标签: c# excel colors dialog


    【解决方案1】:

    您可以在 Microsoft Excel 中获取所有 Dialog 对象的集合:

    Application excel = new Microsoft.Office.Interop.Excel.Application();
    ...
    Dialogs dialogs = excel.Dialogs;
    

    然后你得到xlDialogPatterns 并调用Show() 方法:

    dialogs.Item[XlBuiltInDialog.xlDialogPatterns].Show();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-06-30
      • 1970-01-01
      • 1970-01-01
      • 2010-09-19
      • 2010-09-13
      • 2014-10-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多