kwingkwingko
kwingkwingko

Reputation: 801

Remove Gridlines in LineChart in Excel using C#.net (Microsoft.Office.Interop.Excel)

I have a problem in removing/hiding the grid lines in LINE CHART in excel using C#.Net MVC with the DLL (Microsoft.Office.Interop.Excel) I want to remove it or just hide since it was the client's need. I've seen a lot of article but it's still not working for me.

Please click here for my sample excel

The 3 Numbers in the image is the thing that I want to remove or hide.

And here is my code for Border, ChartArea and PlotArea transparency.

  //Plot Area          
            chartPage.PlotArea.Format.Fill.Solid();
            chartPage.PlotArea.Format.Fill.ForeColor.RGB = (int)XlRgbColor.rgbWhite;
            chartPage.PlotArea.Format.Fill.Transparency = (float)1;
  //Chart Area
            chartPage.ChartArea.Format.Fill.Solid();
            chartPage.ChartArea.Format.Fill.ForeColor.RGB = (int)XlRgbColor.rgbWhite;
            chartPage.ChartArea.Format.Fill.Transparency = (float)1;
  //Border
            chartPage.ChartArea.Format.Line.ForeColor.RGB = (int)XlRgbColor.rgbWhite;
            chartPage.ChartArea.Format.Line.Transparency = (float)1;

My Problem is the Gridlines, please refer in the image.

Any helps would be appreciated.

Thanks!

Upvotes: 3

Views: 1069

Answers (1)

kwingkwingko
kwingkwingko

Reputation: 801

I've already found a solution for this problem.

I hope this will help to all of the guys who has the same problem.

Sample Excel

//This will get the X-Axis (#3 in the image)
Axis xAxis = (Axis)chartPage.Axes(XlAxisType.xlValue, XlAxisGroup.xlPrimary);

//This will get the Y-Axis (#2 in the image)
Axis yAxis = (Axis)chartPage.Axes(XlAxisType.xlCategory, XlAxisGroup.xlPrimary);

//This will delete the Grid Lines (#1 in the image)        
xAxis.MajorGridlines.Delete();
//This will delete the X-Axis (#3 in the image)
xAxis.Delete();
//This will delete the Y-Axis (#2 in the image)
yAxis.Delete();

Cheers!

Upvotes: 3

Related Questions