Aspose.Cells for .NET是Excel电子表格编程API,可加快电子表格管理和处理任务,支持构建具有生成,修改,转换,呈现和打印电子表格功能的跨平台应用程序。
>>Aspose.Cells for .NET已经更新至v20.5,在MVC上支持GridWeb,在ASP.NET Core中支持Aspose.Cells.GridWeb,添加新的Excel“隐式交叉口算子” @符 ,发现5处异常情况,体验
第七章:关于工作表的使用
▲第五节:显示和隐藏功能的使用
㈠显示和隐藏工作表和选项卡
显示和隐藏工作表
一个Excel文件可以包含一个或多个工作表。每当我们创建Excel文件时,都会将工作表添加到工作所在的Excel文件中。Excel文件中的每个工作表都有自己的数据和格式设置等,因此与其他工作表无关。有时,出于自己的兴趣,开发人员可能需要隐藏一些工作表,而其他工作表在Excel文件中可见。因此,Aspose.Cells允许开发人员控制其Excel文件中工作表的可见性。
Aspose.Cells提供了一个Workbook类,该类代表一个Excel文件。该Workbook类包含一个 Worksheets集合允许访问在Excel文件中的每个工作表。
工作表由worksheet类表示。Worksheet类提供了广泛的属性和方法来管理工作表。若要控制工作表的可见性,请使用工作表类的IsVisible属性。IsVisible是一个布尔属性,这意味着它只能存储真或假值。
使工作表可见
通过将Worksheet类的IsVisible属性设置为true,使工作表可见
隐藏工作表
通过将Worksheet 类的IsVisible 属性设置为false来隐藏工作表。
// The path to the documents directory.string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);// Creating a file stream containing the Excel file to be openedFileStream fstream = new FileStream(dataDir + "book1.xls", FileMode.Open);// Instantiating a Workbook object with opening the Excel file through the file streamWorkbook workbook = new Workbook(fstream);// Accessing the first worksheet in the Excel fileWorksheet worksheet = workbook.Worksheets[0];// Hiding the first worksheet of the Excel fileworksheet.IsVisible = false;// Shows first worksheet of the Excel file//Worksheet.IsVisible = true;// Saving the modified Excel file in default (that is Excel 2003) formatworkbook.Save(dataDir + "output.out.xls");// Closing the file stream to free all resourcesfstream.Close();
显示和隐藏标签
如果仔细查看Microsoft Excel文件的底部,将会看到许多控件。这些包括:
- 工作表标签。
- 标签滚动按钮。
图纸选项卡代表Excel文件中的工作表。单击任何选项卡以切换到该工作表。工作簿中的工作表越多,则工作表标签越多。如果Excel文件中包含大量工作表,则需要按钮来浏览它们。因此,Microsoft Excel提供了用于滚动工作表标签的标签滚动按钮。使用Aspose.Cells,开发人员可以控制工作表标签和Excel文件中标签滚动按钮的可见性。
Aspose.Cells提供了一个Workbook类,该类代表一个Excel文件。的工作簿 类提供了一个宽范围的性能,并管理Excel文件方法。为了控制Excel文件中选项卡的可见性,开发人员可以使用Workbook 类的WorkbookSettings.ShowTabs 属性。WorkbookSettings.ShowTabs 是一个布尔属性,这意味着它只能存储true或false值。
使标签可见
使用Workbook 类的WorkbookSettings.ShowTabs 属性设置为true可使选项卡可见。
隐藏标签
通过将Workbook 类的WorkbookSettings.ShowTabs 属性设置为false,可以在Excel文件中隐藏选项卡。
下面是一个完整的示例,该示例打开一个Excel文件(book1.xls),隐藏其选项卡并将修改后的文件另存为output.xls。执行代码后,您将看到工作簿的选项卡被隐藏。
// The path to the documents directory.string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);// Opening the Excel fileWorkbook workbook = new Workbook(dataDir + "book1.xls");// Hiding the tabs of the Excel fileworkbook.Settings.ShowTabs = false;// Shows the tabs of the Excel file//workbook.Settings.ShowTabs = true;// Saving the modified Excel fileworkbook.Save(dataDir + "output.xls");
控制选项卡栏的宽度
// The path to the documents directory.string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);// Instantiating a Workbook object// Opening the Excel fileWorkbook workbook = new Workbook(dataDir + "book1.xls");// Hiding the tabs of the Excel fileworkbook.Settings.ShowTabs = true;// Adjusting the sheet tab bar widthworkbook.Settings.SheetTabBarWidth = 800;// Saving the modified Excel fileworkbook.Save(dataDir + "output.xls");
还想要更多吗可以点击阅读【2019 · Aspose最新资源整合】,查找需要的教程资源。如果您有任何疑问或需求,请随时加入Aspose技术交流群(),我们很高兴为您提供查询和咨询。
标签:
声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!