【问题标题】:Set Margins In Excel Using Excel Interop VB.Net使用 Excel Interop VB.Net 在 Excel 中设置边距
【发布时间】:2010-04-08 18:22:17
【问题描述】:

任何人都有使用 excel interop 和 vb.net 设置边距(上、左、右、下)的代码。我认为它必须是工作表对象的一部分,但可能是工作簿对象。很难找到一个例子。提前致谢。

【问题讨论】:

    标签: c# vb.net excel


    【解决方案1】:

    我发现它是工作表对象的一部分...

    xlWorkSheet.PageSetup.TopMargin=0.5

    【讨论】:

      【解决方案2】:

      边距通过PageSetup 对象设置,您可以从WorkSheet.PageSetup 属性中获得该对象。

      【讨论】:

      • Charles 这就是我的想法,但由于某种原因,excel 并没有接受它。我的边距没有在输出文件中设置
      • 不知道您的问题可能是什么。我实际上使用的是包装 Excel 对象模型的 SpreadSheetGear,所以我不直接使用 Excel 类。也许如果您发布非工作代码,有人会注意到问题。
      • ws.PageSetup.Orentation=Excel.xlpageorentation.xlLandscape ws.PageSetup.Zoom=False ws.PageSetup.FitToPagesWide=1 ws.PageSetup.FitToPagesTall=1 ws.PageSetup.TopMargin=0.5 ws.PageSetup .LeftMargin=0.25 ws.PageSetup.RightMargin=0.25 ws.PageSetup.BottomMargin=0 ws.Protect() 忽略我可能犯的任何错别字。一切都很好,但边距
      【解决方案3】:

      边距值必须以点为单位。使用 InchesToPoints(Double) 或 CentimetersToPoints(Double) 指定值。

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-06-17
        相关资源
        最近更新 更多