Hide Gridlines in Excel Chart in Java

This article demonstrates how to hide gridlines in an Excel chart using Spire.XLS for Java.

import com.spire.xls.*;

public class HideGridlinesInChart {

    public static void main(String[] args) {

        //Create a Workbook object
        Workbook workbook = new Workbook();

        //Load an Excel file that contains data for creating chart
        workbook.loadFromFile("C:\\Users\\Administrator\\Desktop\\data.xlsx");

        //Get the first worksheet
        Worksheet sheet = workbook.getWorksheets().get(0);

        //Add a column chart
        Chart chart = sheet.getCharts().add(ExcelChartType.ColumnClustered);
        chart.setChartTitle("Column Chart");

        //Set the chart data range
        chart.setDataRange(sheet.getCellRange("A1:C5"));
        chart.setSeriesDataFromRange(false);

        //Set the chart position
        chart.setLeftColumn(1);
        chart.setTopRow(6);
        chart.setRightColumn(8);
        chart.setBottomRow(19);

        //Hide the grid lines of chart
        chart.getPrimaryValueAxis().hasMajorGridLines(false);

        //Save the document
        workbook.saveToFile("HideGridlines.xlsx", ExcelVersion.Version2016);
    }
}

Hide Gridlines in Excel Chart in Java