常用的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)