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 examp开发者_如何学JAVAle. Thanks in advance.
I found it its part of the worksheet object...
i.e.
xlWorkSheet.PageSetup.TopMargin=0.5
Margins are set through the PageSetup object which you get from on the WorkSheet.PageSetup property.
Margin values have to mentioned in points. Use InchesToPoints(Double) or CentimetersToPoints(Double) to specify the value.
Eg:
Microsoft.Office.Interop.Excel.Application _ExcelAppl = new Microsoft.Office.Interop.Excel.Application();
Microsoft.Office.Interop.Excel.Workbook _ExcelWorkBook = oXL.Workbooks.Add(missing);
Microsoft.Office.Interop.Excel.Worksheet _ExcelWorkSheet = oWB.ActiveSheet as Microsoft.Office.Interop.Excel.Worksheet;
_ExcelWorkSheet.PageSetup.TopMargin = _ExcelAppl.InchesToPoints(0.25);
精彩评论