在Apache poi-ooxml-schemas 5.2.2版本中,没有直接提供添加次要垂直轴的代码。该版本的Apache poi-ooxml-schemas库主要用于解析和处理Office Open XML(OOXML)格式的文档,而不是用于创建或修改这些文档。

要添加次要垂直轴,您需要使用Apache POI库,而不是Apache poi-ooxml-schemas库。Apache POI库提供了用于创建和修改Excel文件的功能。

以下是使用Apache POI库添加次要垂直轴的示例代码:

import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

public class AddSecondaryVerticalAxisExample {
    public static void main(String[] args) throws Exception {
        Workbook workbook = new XSSFWorkbook();
        Sheet sheet = workbook.createSheet("Sheet1");
        
        Drawing drawing = sheet.createDrawingPatriarch();
        ClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 0, 5, 10, 15);
        
        Chart chart = drawing.createChart(anchor);
        ChartLegend legend = chart.getOrCreateLegend();
        ChartAxis bottomAxis = chart.getChartAxisFactory().createCategoryAxis(AxisPosition.BOTTOM);
        ValueAxis leftAxis = chart.getChartAxisFactory().createValueAxis(AxisPosition.LEFT);
        ValueAxis rightAxis = chart.getChartAxisFactory().createValueAxis(AxisPosition.RIGHT);
        ValueAxis secondaryVerticalAxis = chart.getChartAxisFactory().createValueAxis(AxisPosition.RIGHT);
        
        chart.plot(null, new ChartAxis[] { bottomAxis }, new ChartAxis[] { leftAxis, rightAxis, secondaryVerticalAxis });
        
        FileOutputStream fileOut = new FileOutputStream("workbook.xlsx");
        workbook.write(fileOut);
        fileOut.close();
        
        workbook.close();
    }
}

上述代码创建了一个新的Excel工作簿,并在其中创建了一个工作表。然后,它创建了一个图表,并添加了一个次要垂直轴。最后,它将工作簿保存到名为"workbook.xlsx"的文件中。

请注意,上述代码使用的是Apache POI库,而不是Apache poi-ooxml-schemas库。请确保将正确的Apache POI库添加到您的项目中,并在代码中引用它。

在Apache poi-ooxml-schemas 522版本中添加次要垂直轴的代码错误原因

原文地址: https://www.cveoy.top/t/topic/iiij 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录