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

4
  • Why is it "WRONG"? Does it give an error? Does it not compile? Commented Feb 6, 2016 at 18:32
  • Because it does not compile. I thought it was not wpf Commented Feb 6, 2016 at 18:53
  • 1
    You are following a tutorial for a library (Spire.XLS)... are you actually using that library? Commented Feb 6, 2016 at 18:54
  • So awkward of me ...no i didn t noticed it. Any other way to set excel gridlines off with no added library? Commented Feb 6, 2016 at 19:30

2 Answers 2

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;
Sign up to request clarification or add additional context in comments.

1 Comment

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).
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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.