Excel管理控件Aspose.Cells開發(fā)者指南(三十四):顯示和隱藏網(wǎng)格線和行列標題
Aspose.Cells for .NET是Excel電子表格編程API,可加快電子表格管理和處理任務,支持構(gòu)建具有生成,修改,轉(zhuǎn)換,呈現(xiàn)和打印電子表格功能的跨平臺應用程序。
在接下來的系列教程中,將為開發(fā)者帶來Aspose.Cells for .NET的一系列使用教程,例如關(guān)于加載保存轉(zhuǎn)換、字體、渲染、繪圖、智能標記等等。本文重點介紹如何顯示和隱藏行列和滾動條。
>>Aspose.Cells for .NET已經(jīng)更新至v20.6,加載圖片/形狀的性能提升,支持在GridWeb中存儲會話信息的臨時文件,發(fā)現(xiàn)5處異常情況,點擊下載體驗
第七章:關(guān)于工作表的使用
▲第五節(jié):顯示和隱藏功能的使用
㈢顯示和隱藏網(wǎng)格線和行列標題
顯示和隱藏網(wǎng)格線
默認情況下,所有Excel工作表都有網(wǎng)格線。它們有助于描繪單元格,以便輕松將數(shù)據(jù)輸入特定單元格。網(wǎng)格線使我們能夠?qū)⒐ぷ鞅硪暈閱卧竦募希渲忻總€單元格都易于識別。
Aspose.Cells提供了一個Workbook類,它允許開發(fā)人員訪問每個工作表中的Excel文件。為了控制網(wǎng)格線的可見性,使用的工作表 類IsGridlinesVisible 。IsGridlinesVisible 是布爾值屬性,這意味著它只能存儲true或false 值。
通過將Worksheet 類IsGridlinesVisible 屬性設置為true,使網(wǎng)格線可見。通過將Worksheet 類IsGridlinesVisible 屬性設置為false來隱藏網(wǎng)格線。
下面給出一個完整的示例,該示例 通過打開excel文件(book1.xls),隱藏第一個工作表上的網(wǎng)格線并將修改后的文件另存為output.xls來演示IsGridlinesVisible屬性 的使用。
// 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 grid lines of the first worksheet of the Excel file worksheet.IsGridlinesVisible = false; // Saving the modified Excel file workbook.Save(dataDir + "output.xls"); // Closing the file stream to free all resources fstream.Close();
顯示和隱藏行列標題
Excel文件中的所有工作表均由按行和列排列的單元格組成。所有行和列都有唯一的值,這些值用于標識它們和標識單個單元格。例如,行編號為– 1、2、3、4,等等–列的字母順序為– A,B,C,D等。行和列的值顯示在標題中。使用Aspose.Cells,開發(fā)人員可以控制這些行和列標題的可見性。
Aspose.Cells提供了一個Workbook類,它允許開發(fā)人員訪問每個工作表中的Excel文件。
通過將Worksheet 類IsRowColumnHeadersVisible 屬性設置為true,使行和列標題可見。通過將Worksheet 類IsRowColumnHeadersVisible 屬性設置為false來隱藏行標題和列標題。
下面給出一個完整的示例,該示例演示如何 通過打開excel文件(book1.xls), 隱藏第一個工作表上的行標題和列標題并將修改后的文件另存為output.xls來使用 IsRowColumnHeadersVisible屬性。
// 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 headers of rows and columns worksheet.IsRowColumnHeadersVisible = false; // Saving the modified Excel file workbook.Save(dataDir + "output.xls"); // Closing the file stream to free all resources fstream.Close();
還想要更多嗎?您可以點擊閱讀【2020 · Aspose最新資源整合】,查找需要的教程資源。如果您有任何疑問或需求,請隨時加入Aspose技術(shù)交流群(642018183),我們很高興為您提供查詢和咨詢。