将行标记添加到行系列/图表(Apache POI XSSF或Excel VBA)

时间:2014-10-29 08:02:20

标签: java excel-vba apache-poi vba excel

我研究过Apache POI Example on how to create a line chart

它输出单个折线图,如Apache POI add a Series name into LineChart中的图表。

enter image description here

如何将线标记添加到线?

1 个答案:

答案 0 :(得分:1)

我正在使用Apache POI 3.10。到目前为止,Apache POI XSSF无法添加行标记!所以,我使用excel vba来做到这一点。

我做的是创建一个带有VBA宏的xlsm模板,以便在用户打开xlsm文件时添加行标记。此外,我们无法按照here

中提到的POI添加VBA宏
Macros can not be created. The are currently no plans to support macros. However, 
reading and re-writing files containing macros will safely preserve the macros.

因此我们必须创建一个模板并将其用作POI输入。

FileInputStream file = new FileInputStream(new File("template.xlsm"));
XSSFWorkbook workbook = new XSSFWorkbook(file);

这是我的VBA宏:

Sub auto_open()

Dim myChart As ChartObject
    For Each myChart In Sheets("Sheet1").ChartObjects
        For Each Series In myChart.Chart.SeriesCollection
            Series.MarkerStyle = xlMarkerStyleSquare
        Next
    Next myChart
End Sub

通过使用此解决方法,我们可以为POI的简单输出折线图添加更多样式。