常用的Excel视图有三种:普通视图、页面布局视图和分页预览视图。Spire.XLS也支持使用C#和VB.NET设置以上三种视图模式,对应的设置为ViewMode.Normal 、 ViewMode.Layout、 和ViewMode.Preview。该文详细介绍如何使用Spire.XLS设置Excel视图模式和显示比例。
设置Excel视图模式
C#
//加载Excel文档
Workbook workbook = new Workbook();
workbook.LoadFromFile("Sample.xlsx");
//获取第一个工作表
Worksheet sheet = workbook.Worksheets[0];
//设置视图模式为分页预览及缩放比例
sheet.ViewMode = ViewMode.Preview;
sheet.ZoomScalePageBreakView = 80;
//保存文档
workbook.SaveToFile("Result.xlsx", ExcelVersion.Version2010);
VB.NET
'加载Excel文档
Dim workbook As New Workbook()
workbook.LoadFromFile("Sample.xlsx")
'获取第一个工作表
Dim sheet As Worksheet = workbook.Worksheets(0)
'设置视图模式为分页预览及缩放比例
sheet.ViewMode = ViewMode.Preview
sheet.ZoomScalePageBreakView = 80
'保存文档
workbook.SaveToFile("Result.xlsx", ExcelVersion.Version2010)
设置Exce工作表显示比例
C#
Workbook workbook = new Workbook();
workbook.LoadFromFile("Sample.xlsx");
Worksheet sheet = workbook.Worksheets[0];
sheet.Zoom = 75;
workbook.SaveToFile("Result.xlsx", ExcelVersion.Version2010);
VB.NET
Dim workbook As New Workbook()
workbook.LoadFromFile("Sample.xlsx")
Dim sheet As Worksheet = workbook.Worksheets(0)
sheet.Zoom = 75
workbook.SaveToFile("Result.xlsx", ExcelVersion.Version2010)