翻譯|使用教程|編輯:李顯亮|2020-07-10 09:35:19.113|閱讀 651 次
概述:Aspose.Cells提供了控制工作表的行,列和滾動條的可見性的方法。在本文中將介紹如何顯示和隱藏行列和滾動條。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
Aspose.Cells for .NET是Excel電子表格編程API,可加快電子表格管理和處理任務,支持構建具有生成,修改,轉換,呈現和打印電子表格功能的跨平臺應用程序。
在接下來的系列教程中,將為開發者帶來Aspose.Cells for .NET的一系列使用教程,例如關于加載保存轉換、字體、渲染、繪圖、智能標記等等。本文重點介紹如何顯示和隱藏行列和滾動條。
>>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 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 集合的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 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 集合的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 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文件的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 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();
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn