Make Major and Minor Grid lines hidden for Column chart in Java

Hello Team,

If I save workbook with .xlsx then gridlines are still visible. Please can you suggest what is wrong in this code ?

import com.aspose.cells.Chart;
import com.aspose.cells.ChartType;
import com.aspose.cells.CrossType;
import com.aspose.cells.FormattingType;
import com.aspose.cells.Workbook;
import com.aspose.cells.Worksheet;

public class AsposeCellTestGridlines {

public static void main(String args []) throws Exception {
	//Instantiating a Workbook object
	Workbook workbook = new Workbook();
	//Adding a new worksheet to the Excel object
	int sheetIndex = workbook.getWorksheets().add();
	//Obtaining the reference of the newly added worksheet by passing its sheet index
	Worksheet worksheet = workbook.getWorksheets().get(sheetIndex);
	//Adding a sample value to "A1" cell
	worksheet.getCells().get("A1").putValue(50);
	//Adding a sample value to "A2" cell
	worksheet.getCells().get("A2").putValue(100);
	//Adding a sample value to "A3" cell
	worksheet.getCells().get("A3").putValue(150);
	//Adding a sample value to "B1" cell
	worksheet.getCells().get("B1").putValue(4);
	//Adding a sample value to "B2" cell
	worksheet.getCells().get("B2").putValue(20);
	//Adding a sample value to "B3" cell
	worksheet.getCells().get("B3").putValue(50);
	//Adding a chart to the worksheet
	int chartIndex = worksheet.getCharts().add(ChartType.COLUMN, 5, 0, 25, 5);
	//Accessing the instance of the newly added chart
	Chart chart = worksheet.getCharts().get(chartIndex);
	//Adding NSeries (chart data source) to the chart ranging from "A1" cell to "B3"
	chart.getNSeries().add("A1:B3", true);
	chart.getValueAxis().getMajorGridLines().setVisible(false);
	chart.getValueAxis().getMajorGridLines().setFormattingType(FormattingType.NONE);
	chart.getCategoryAxis().getMajorGridLines().setVisible(false);
	//Set the max value of value axis
	chart.getValueAxis().setMaxValue(200);
	//Set the min value of value axis
	chart.getValueAxis().setMinValue(0);
	//Set the major unit
	chart.getValueAxis().setMajorUnit(25);
	//Category(X) axis crosses at the maxinum value.
	chart.getValueAxis().setCrossType(CrossType.MAXIMUM);
	//Set he number of categories or series between tick-mark labels. 
	chart.getCategoryAxis().setTickLabelSpacing(2);
	//Saving the Excel file
	workbook.save("C:\\book1.xlsx");
}

}

@amanguest353,

Please try the following sample code, it will work for your needs:
e.g.
Sample code:

 //Instantiating a Workbook object
        Workbook workbook = new Workbook();
        //Adding a new worksheet to the Excel object
        int sheetIndex = workbook.getWorksheets().add();
        //Obtaining the reference of the newly added worksheet by passing its sheet index
        Worksheet worksheet = workbook.getWorksheets().get(sheetIndex);
        //Adding a sample value to "A1" cell
        worksheet.getCells().get("A1").putValue(50);
        //Adding a sample value to "A2" cell
        worksheet.getCells().get("A2").putValue(100);
        //Adding a sample value to "A3" cell
        worksheet.getCells().get("A3").putValue(150);
        //Adding a sample value to "B1" cell
        worksheet.getCells().get("B1").putValue(4);
        //Adding a sample value to "B2" cell
        worksheet.getCells().get("B2").putValue(20);
        //Adding a sample value to "B3" cell
        worksheet.getCells().get("B3").putValue(50);
        //Adding a chart to the worksheet
        int chartIndex = worksheet.getCharts().add(ChartType.COLUMN, 5, 0, 25, 5);
        //Accessing the instance of the newly added chart
        Chart chart = worksheet.getCharts().get(chartIndex);
        //Adding NSeries (chart data source) to the chart ranging from "A1" cell to "B3"
        chart.getNSeries().add("A1:B3", true);
        chart.getValueAxis().getMajorGridLines().setVisible(false);
        chart.getValueAxis().getMinorGridLines().setVisible(false);            
        chart.getCategoryAxis().getMajorGridLines().setVisible(false);
        chart.getCategoryAxis().getMinorGridLines().setVisible(false);
        //Set the max value of value axis
        chart.getValueAxis().setMaxValue(200);
        //Set the min value of value axis
        chart.getValueAxis().setMinValue(0);
        //Set the major unit
        chart.getValueAxis().setMajorUnit(25);
        //Category(X) axis crosses at the maxinum value.
        chart.getValueAxis().setCrossType(CrossType.MAXIMUM);
        //Set he number of categories or series between tick-mark labels.
        chart.getCategoryAxis().setTickLabelSpacing(2);
         //Saving the Excel file
	workbook.save("C:\\book1.xlsx");

Hope, this helps a bit.

image.png (4.4 KB)

I still get this with all gridlines.

@amanguest353

Please upgrade to latest version of API because I can not notice any gridlines with Excel 2016. Gridlines.PNG (3.2 KB)