显示和隐藏行列和滚动条

显示和隐藏行和列

Aspose.Cells提供了一个类,工作簿,代表一个 Microsoft Excel 文件。这工作簿类包含一个工作表允许开发人员访问 Excel 文件中的每个工作表的集合。工作表由工作表班级。这工作表类提供了Cells代表工作表中所有单元格的集合。这Cellscollection 提供了多种方法来管理工作表中的行或列。下面讨论其中的一些。

显示行和列

开发人员可以通过调用取消隐藏行取消隐藏列的方法Cells分别收藏。两种方法都有两个参数:

  • 行或列索引 用于显示特定行或列的行或列的索引。
  • 行高或列宽 取消隐藏后分配给行或列的行高或列宽。
// 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
// 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];
// Unhiding the 3rd row and setting its height to 13.5
worksheet.Cells.UnhideRow(2, 13.5);
// Unhiding the 2nd column and setting its width to 8.5
worksheet.Cells.UnhideColumn(1, 8.5);
// Saving the modified Excel file
workbook.Save(dataDir + "output.xls");
// Closing the file stream to free all resources
fstream.Close();

隐藏行和列

开发人员可以通过调用隐藏行隐藏列的方法Cells分别收藏。这两种方法都将行和列索引作为参数来隐藏特定的行或列。

// 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
// 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 3rd row of the worksheet
worksheet.Cells.HideRow(2);
// Hiding the 2nd column of the worksheet
worksheet.Cells.HideColumn(1);
// Saving the modified Excel file
workbook.Save(dataDir + "output.out.xls");
// Closing the file stream to free all resources
fstream.Close();

隐藏多行多列

开发人员可以通过调用隐藏行隐藏列的方法Cells分别收藏。这两种方法都将起始行或列索引以及应隐藏的行数或列数作为参数。

// 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
// 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 3,4 and 5 rows in the worksheet
worksheet.Cells.HideRows(2, 3);
// Hiding 2 and 3 columns in the worksheet
worksheet.Cells.HideColumns(1, 2);
// Saving the modified Excel file
workbook.Save(dataDir + "outputxls");
// Closing the file stream to free all resources
fstream.Close();

显示和隐藏滚动条

滚动条用于导航任何文件的内容。通常,有两种滚动条:

  • 垂直滚动条
  • 水平滚动条

Microsoft Excel 还提供水平和垂直滚动条,以便用户可以滚动浏览工作表内容。使用 Aspose.Cells,开发人员可以控制 Excel 文件中两种滚动条的可见性。

控制滚动条的可见性

Aspose.Cells提供了一个类,工作簿表示一个 Excel 文件。这工作簿类提供了广泛的属性和方法来管理 Excel 文件。要控制滚动条的可见性,请使用工作簿班级'工作簿设置.IsVScrollBarVisible工作簿设置.IsHScrollBarVisible特性。工作簿设置.IsVScrollBarVisible工作簿设置.IsHScrollBarVisible是布尔属性,这意味着这些属性只能存储真的要么错误的值。

使滚动条可见

通过设置滚动条可见工作簿班级'工作簿设置.IsVScrollBarVisible要么工作簿设置.IsHScrollBarVisible财产给真的.

隐藏滚动条

通过设置隐藏滚动条工作簿班级'工作簿设置.IsVScrollBarVisible要么工作簿设置.IsHScrollBarVisible财产给错误的.

示例代码

下面是打开 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);
// Creating a file stream containing the Excel file to be opened
FileStream fstream = new FileStream(dataDir + "book1.xls", FileMode.Open);
// Instantiating a Workbook object
// Opening the Excel file through the file stream
Workbook workbook = new Workbook(fstream);
// Hiding the vertical scroll bar of the Excel file
workbook.Settings.IsVScrollBarVisible = false;
// Hiding the horizontal scroll bar of the Excel file
workbook.Settings.IsHScrollBarVisible = false;
// Saving the modified Excel file
workbook.Save(dataDir + "output.xls");
// Closing the file stream to free all resources
fstream.Close();