导出为excel,设置页边距

2017年4月13日

Module Module1

Sub Main()
Dim hss As NPOI.HSSF.UserModel.HSSFWorkbook = Nothing
Using f = New IO.FileStream(“d:\11111.xls”, IO.FileMode.Open, IO.FileAccess.Read)
hss = New NPOI.HSSF.UserModel.HSSFWorkbook(f)
f.Close()
End Using

Dim sheet1 = hss.GetSheetAt(0)
sheet1.FitToPage = False
sheet1.PrintSetup.Landscape = True
sheet1.PrintSetup.Scale = 90
sheet1.PrintSetup.FooterMargin = 0
sheet1.PrintSetup.HeaderMargin = 0
sheet1.HorizontallyCenter = True ‘水平居中
sheet1.VerticallyCenter = True ‘垂直居中

sheet1.SetMargin(NPOI.SS.UserModel.MarginType.BottomMargin, 0.1 / 3)
sheet1.SetMargin(NPOI.SS.UserModel.MarginType.LeftMargin, 0.1 / 3)
sheet1.SetMargin(NPOI.SS.UserModel.MarginType.RightMargin, 0.1 / 3)
sheet1.SetMargin(NPOI.SS.UserModel.MarginType.TopMargin, 0.1 / 3)
Using f = New IO.FileStream(“d:\2222.xls”, IO.FileMode.Create)
hss.Write(f)
f.Close()
End Using
Dim wk As New Aspose.Cells.Workbook(“d:\11111.xls”)
Dim sh = wk.Worksheets(0)

sh.PageSetup.Orientation = Aspose.Cells.PageOrientationType.Landscape

sh.PageSetup.IsPercentScale = True
sh.PageSetup.FitToPagesWide = 1 ‘调整为一页宽
‘sh.PageSetup.FitToPagesTall = 1 ‘调整为一页高

wk.Save(“d:\2.xls”)

End Sub

End Module

声明: 本文采用 BY-NC-SA 协议进行授权. 转载请注明转自: 导出为excel,设置页边距
本文的评论功能被关闭了.