显示和隐藏工作表和选项卡
显示和隐藏工作表
一个 Excel 文件可以有一个或多个工作表。每当我们创建 Excel 文件时,我们都会将工作表添加到我们工作的 Excel 文件中。 Excel 文件中的每个工作表都独立于其他工作表,具有自己的数据和格式设置等。有时,开发人员可能出于自己的兴趣需要隐藏一些工作表,而其他工作表在 Excel 文件中可见。所以,Aspose.Cells允许开发人员控制工作表在其 Excel 文件中的可见性。
Aspose.Cells提供了一个类,工作簿 , 表示一个 Excel 文件。这工作簿类包含一个工作表允许访问 Excel 文件中每个工作表的集合。
工作表由工作表班级。这工作表类提供了广泛的属性和方法来管理工作表。要控制工作表的可见性,请使用可见的财产工作表班级。可见是一个布尔属性,这意味着它只能存储一个真的要么错误的价值。
使工作表可见
隐藏工作表
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// 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 opened | |
FileStream fstream = new FileStream(dataDir + "book1.xls", FileMode.Open); | |
// Instantiating a Workbook object with opening the Excel file through the file stream | |
Workbook workbook = new Workbook(fstream); | |
// Accessing the first worksheet in the Excel file | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Hiding the first worksheet of the Excel file | |
worksheet.IsVisible = false; | |
// Shows first worksheet of the Excel file | |
//Worksheet.IsVisible = true; | |
// Saving the modified Excel file in default (that is Excel 2003) format | |
workbook.Save(dataDir + "output.out.xls"); | |
// Closing the file stream to free all resources | |
fstream.Close(); |
显示和隐藏标签
如果仔细查看 Microsoft Excel 文件的底部,您会看到许多控件。这些包括:
- 工作表标签。
- 选项卡滚动按钮。
工作表选项卡代表 Excel 文件中的工作表。单击任何选项卡以切换到该工作表。工作簿中的工作表越多,工作表标签就越多。如果 Excel 文件有大量工作表,您需要按钮来浏览它们。因此,Microsoft Excel 提供了用于滚动工作表选项卡的选项卡滚动按钮。
使用 Aspose.Cells,开发人员可以控制 Excel 文件中工作表选项卡和选项卡滚动按钮的可见性。
Aspose.Cells提供了一个类,工作簿 , 表示一个 Excel 文件。这工作簿类提供了广泛的属性和方法来管理 Excel 文件。要控制 Excel 文件中选项卡的可见性,开发人员可以使用工作簿班级'WorkbookSettings.ShowTabs财产。WorkbookSettings.ShowTabs是一个布尔属性,这意味着它只能存储一个真的要么错误的价值。
使选项卡可见
使选项卡可见工作簿班级'WorkbookSettings.ShowTabs财产给真的.
隐藏标签
通过设置隐藏 Excel 文件中的选项卡工作簿班级'WorkbookSettings.ShowTabs属性为假。
下面是打开 Excel 文件 (book1.xls)、隐藏其选项卡并将修改后的文件保存为 output.xls 的完整示例。代码执行后,您会看到工作簿的选项卡被隐藏了。
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Opening the Excel file | |
Workbook workbook = new Workbook(dataDir + "book1.xls"); | |
// Hiding the tabs of the Excel file | |
workbook.Settings.ShowTabs = false; | |
// Shows the tabs of the Excel file | |
//workbook.Settings.ShowTabs = true; | |
// Saving the modified Excel file | |
workbook.Save(dataDir + "output.xls"); |
控制标签栏宽度
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Instantiating a Workbook object | |
// Opening the Excel file | |
Workbook workbook = new Workbook(dataDir + "book1.xls"); | |
// Hiding the tabs of the Excel file | |
workbook.Settings.ShowTabs = true; | |
// Adjusting the sheet tab bar width | |
workbook.Settings.SheetTabBarWidth = 800; | |
// Saving the modified Excel file | |
workbook.Save(dataDir + "output.xls"); |