Excel管理控件Aspose.Cells开发者指南(三十三):显示和隐藏行列和滚动条

Aspose.Cells for .NET是Excel电子表格编程API,可加快电子表格管理和处理任务,支持构建具有生成,修改,转换,呈现和打印电子表格功能的跨平台应用程序。

>>Aspose.Cells for .NET已经更新至v20.6,加载图片/形状的性能提升,支持在GridWeb中存储会话信息的临时文件,发现5处异常情况体验

第七章:关于工作表的使用

▲第五节:显示和隐藏功能的使用

㈡显示和隐藏行和列

Aspose.Cells提供了一个Workbook类,该类代表Microsoft Excel文件。该工作簿 类包含一个 Workbook 集合,它允许开发人员访问每个工作表中的Excel文件。工作表由Worksheet 类表示。该 Workbook 类提供了一个Cells集合,表示工作表中的所有单元格。“ 单元格” 集合提供了几种用于管理工作表中的行或列的方法。

显示行和列

开发人员可以通过分别调用Cells 集合的UnhideRow 和UnhideColumn 方法来显示任何隐藏的行或列。两种方法都有两个参数:

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

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

// 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// 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 3rd row of the worksheetworksheet.Cells.HideRow(2);// Hiding the 2nd column of the worksheetworksheet.Cells.HideColumn(1);// Saving the modified Excel fileworkbook.Save(dataDir + "output.out.xls");// Closing the file stream to free all resourcesfstream.Close();
隐藏多行和多列

通过分别调用Cells 集合的HideRows 和HideColumns 方法,开发人员可以一次隐藏多行或多列。两种方法都以起始行或列索引以及应隐藏的行或列数作为参数。

// 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// 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 3,4 and 5 rows in the worksheetworksheet.Cells.HideRows(2, 3);// Hiding 2 and 3 columns in the worksheetworksheet.Cells.HideColumns(1, 2);// Saving the modified Excel fileworkbook.Save(dataDir + "outputxls");// Closing the file stream to free all resourcesfstream.Close();
㈢显示和隐藏滚动条

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

显示行和列

Aspose.Cells提供了一个代表Excel文件的Workbook类。的工作簿 类提供了一个宽范围的性质和用于管理Excel文件方法。若要控制滚动条的可见性,请使用Workbook 类的WorkbookSettings.IsVScrollBarVisible和WorkbookSettings.IsHScrollBarVisible 属性。WorkbookSettings.IsVScrollBarVisible 和WorkbookSettings.IsHScrollBarVisible 是布尔属性,这意味着这些属性只能存储true或false值。

Aspose.Cells提供了一个代表Excel文件的Workbook类。的工作簿 类提供了一个宽范围的性质和用于管理Excel文件方法。若要控制滚动条的可见性,请使用Workbook 类的WorkbookSettings.IsVScrollBarVisible和WorkbookSettings.IsHScrollBarVisible 属性。WorkbookSettings.IsVScrollBarVisible 和WorkbookSettings.IsHScrollBarVisible 是布尔属性,这意味着这些属性只能存储true或false值。

通过将Workbook类的WorkbookSettings.IsVScrollBarVisible 或WorkbookSettings.IsHScrollBarVisible 属性设置为true,使滚动条可见。

通过将Workbook类的WorkbookSettings.IsVScrollBarVisible 或WorkbookSettings.IsHScrollBarVisible 属性设置为false来隐藏滚动条。

下面是一个完整的代码,该代码打开一个Excel文件book1.xls,隐藏两个滚动条,然后将修改后的文件另存为output.xls。

// 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// Opening the Excel file through the file streamWorkbook workbook = new Workbook(fstream);// Hiding the vertical scroll bar of the Excel fileworkbook.Settings.IsVScrollBarVisible = false;// Hiding the horizontal scroll bar of the Excel fileworkbook.Settings.IsHScrollBarVisible = false;// Saving the modified Excel fileworkbook.Save(dataDir + "output.xls");// Closing the file stream to free all resourcesfstream.Close();

还想要更多吗可以点击阅读【2020 · Aspose最新资源整合】查找需要的教程资源。如果您有任何疑问或需求,请随时加入Aspose技术交流群(),我们很高兴为您提供查询和咨询
标签:

声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2020年6月7日
下一篇 2020年6月7日

相关推荐

发表回复

登录后才能评论