【问题标题】:How to set Excel chart style in vb如何在vb中设置Excel图表样式
【发布时间】:2020-07-21 16:37:15
【问题描述】:

我正在通过 vb.net 导出一个 excel 图表,但我想改变他的风格。问题是我目前只能更改他的颜色。

见下面的代码:

Private Sub ExportExcel()
    Dim PerfilSonho As Boolean = False

    If PerfilSonhoAtivo(CB_FuncaoNivel.SelectedItem, CB_CompetenciaNivel.SelectedItem) = True Then 'Ativar barras de Perfil Sonho
        PerfilSonho = True
    End If

    Dim excel As New Excel.Application 'Create Excel Application instance
    excel.Visible = True 'Set Excel Application to visible
    excel.Workbooks.Add() 'Add a new excel workbook

    'Add 3 Columns header for data fields
    excel.Range("A1").Value2 = "Operários"
    excel.Range("B1").Value2 = CT_Niveis.Series(0).LegendText
    If PerfilSonho = True Then
        excel.Range("C1").Value2 = CT_Niveis.Series(1).LegendText
    End If

    'Add data to the Cells
    Dim i As Integer = 2
    For j As Integer = 0 To CT_Niveis.Series(0).Points.Count - 1
        excel.Range("A" & i).Value2 = XChart(j)
        excel.Range("B" & i).Value2 = CT_Niveis.Series(0).Points(j).YValues
        i += 1
    Next
    If PerfilSonho = True Then
        i = 2
        For x As Integer = 0 To CT_Niveis.Series(1).Points.Count - 1
            excel.Range("C" & i).Value2 = CT_Niveis.Series(1).Points(x).YValues
            i += 1
        Next
    End If

    Dim range As Excel.Range = excel.Range("A1") 'Add range
    Dim chart As Excel.Chart = excel.ActiveWorkbook.Charts.Add(After:=excel.ActiveSheet) 'Add Chart
    chart.ChartWizard(Source:=range.CurrentRegion, Title:=CT_Niveis.Titles(0).Text) 'Add chart data source & title

    'Set Chart Style
    chart.ChartStyle = 27
    chart.Axes(2, 1).maximumscale = 4.5
    chart.Axes(2, 1).minimumscale = 0
End Sub

Excel 是这样导出的:

但我想把它改成这样,例如:

有可能吗?或者我们只能改变他的颜色? 提前致谢!

【问题讨论】:

标签: excel vb.net charts


【解决方案1】:

正如@Mkn 在此评论部分评论的那样,以下链接回答了我的问题:C# - Excel 2013 how to change chart style

基本上,我所要做的就是像这样将 图表样式 从 27 更改为 209 -

chart.ChartStyle = 209

现在图表看起来和我想要的完全一样 -

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多