4

Following this

http://www.e-iceblue.com/Tutorials/Spire.XLS/Spire.XLS-Program-Guide/Worksheet/How-to-hide-or-show-gridlines-on-a-worksheet-in-C.html

to hide gridlines I should do just:

Workbook wb = app.Workbooks.Add(XlWBATemplate.xlWBATWorksheet);
  Worksheet ws = wb.Worksheets[1];
   ws.GridLinesVisible = false;<----WRONG

but that is wrong.

And also the solution here

How to disable gridlines in Excel using open xml C#?

does not work. So any other method?

thank you in advance. PAtrick

Community
  • 1
  • 1
Patrick
  • 3,073
  • 2
  • 22
  • 60

2 Answers2

12

With no third party library, using only the simple Excel interop (Microsoft.Office.Interop.Excel), it should work with this:

Microsoft.Office.Interop.Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application();

xlApp.Visible = true;

Workbook wb = xlApp.Workbooks.Add(XlWBATemplate.xlWBATWorksheet);
Worksheet ws = wb.Worksheets[1];

xlApp.ActiveWindow.DisplayGridlines = false;
Szabolcs Dézsi
  • 8,743
  • 21
  • 29
  • Any info on how to hide gridlines on multiple sheets? I only seem to be able to get it on the `ActiveWindow` (the first sheet). – Benji Altman Dec 18 '19 at 21:23
0

For multiple sheets and working with Excel interop, activate each sheet first.

worksheet.Activate();
xlApp.ActiveWindow.DisplayGridlines = false;

Hope this helps those that need to deal with multiple sheets.

ding dong
  • 1
  • 1