tags:

views:

233

answers:

2

Anyone have code to set margins(top,left,right,bottom) using excel interop and vb.net. I think it must be part of the worksheet object but maybe the workbook object. Having a tough time finding an example. Thanks in advance.

+1  A: 

I found it its part of the worksheet object...

i.e.

xlWorkSheet.PageSetup.TopMargin=0.5

Nick LaMarca
+1  A: 

Margins are set through the PageSetup object which you get from on the WorkSheet.PageSetup property.

Charles
Charles thats what I thought, but excel isnt taking it for some reason. My margins are not getting set in the output file
Nick LaMarca
Don't know what your problem might be. I'm actually using SpreadSheetGear which wraps the Excel object model, so I don't use Excel classes directly. Maybe if you post the non-working code, someone will notice the problem.
Charles
ws.PageSetup.Orentation=Excel.xlpageorentation.xlLandscapews.PageSetup.Zoom=Falsews.PageSetup.FitToPagesWide=1ws.PageSetup.FitToPagesTall=1ws.PageSetup.TopMargin=0.5ws.PageSetup.LeftMargin=0.25ws.PageSetup.RightMargin=0.25ws.PageSetup.BottomMargin=0ws.Protect()Disregard any typos I may have made. Everything is setting fine, but the margins
Nick LaMarca
I meant add code to your question. :)
Charles