翻譯|使用教程|編輯:李顯亮|2020-06-11 09:36:10.800|閱讀 541 次
概述:在接下來的系列教程中,將為開發(fā)者帶來Aspose.Cells for .NET的一系列使用教程,例如關(guān)于加載保存轉(zhuǎn)換、字體、渲染、繪圖、智能標(biāo)記等等。本文重點介紹如何顯示和隱藏工作表和選項卡。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
Aspose.Cells for .NET是Excel電子表格編程API,可加快電子表格管理和處理任務(wù),支持構(gòu)建具有生成,修改,轉(zhuǎn)換,呈現(xiàn)和打印電子表格功能的跨平臺應(yīng)用程序。
在接下來的系列教程中,將為開發(fā)者帶來Aspose.Cells for .NET的一系列使用教程,例如關(guān)于加載保存轉(zhuǎn)換、字體、渲染、繪圖、智能標(biāo)記等等。本文重點介紹如何顯示和隱藏工作表和選項卡。
>>Aspose.Cells for .NET已經(jīng)更新至v20.5,在MVC上支持GridWeb,在ASP.NET Core中支持Aspose.Cells.GridWeb,添加新的Excel“隱式交叉口算子” @符號,發(fā)現(xiàn)5處異常情況,點擊下載體驗
一個Excel文件可以包含一個或多個工作表。每當(dāng)我們創(chuàng)建Excel文件時,都會將工作表添加到工作所在的Excel文件中。Excel文件中的每個工作表都有自己的數(shù)據(jù)和格式設(shè)置等,因此與其他工作表無關(guān)。有時,出于自己的興趣,開發(fā)人員可能需要隱藏一些工作表,而其他工作表在Excel文件中可見。因此,Aspose.Cells允許開發(fā)人員控制其Excel文件中工作表的可見性。
Aspose.Cells提供了一個Workbook類,該類代表一個Excel文件。該Workbook類包含一個 Worksheets集合允許訪問在Excel文件中的每個工作表。
工作表由worksheet類表示。Worksheet類提供了廣泛的屬性和方法來管理工作表。若要控制工作表的可見性,請使用工作表類的IsVisible屬性。IsVisible是一個布爾屬性,這意味著它只能存儲真或假值。
使工作表可見
通過將Worksheet類的IsVisible屬性設(shè)置為true,使工作表可見
隱藏工作表
通過將Worksheet 類的IsVisible 屬性設(shè)置為false來隱藏工作表。
// 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();
如果仔細(xì)查看Microsoft Excel文件的底部,將會看到許多控件。這些包括:
圖紙選項卡代表Excel文件中的工作表。單擊任何選項卡以切換到該工作表。工作簿中的工作表越多,則工作表標(biāo)簽越多。如果Excel文件中包含大量工作表,則需要按鈕來瀏覽它們。因此,Microsoft Excel提供了用于滾動工作表標(biāo)簽的標(biāo)簽滾動按鈕。使用Aspose.Cells,開發(fā)人員可以控制工作表標(biāo)簽和Excel文件中標(biāo)簽滾動按鈕的可見性。
Aspose.Cells提供了一個Workbook類,該類代表一個Excel文件。的工作簿 類提供了一個寬范圍的性能,并管理Excel文件方法。為了控制Excel文件中選項卡的可見性,開發(fā)人員可以使用Workbook 類的WorkbookSettings.ShowTabs 屬性。WorkbookSettings.ShowTabs 是一個布爾屬性,這意味著它只能存儲true或false值。
使標(biāo)簽可見
使用Workbook 類的WorkbookSettings.ShowTabs 屬性設(shè)置為true可使選項卡可見。
隱藏標(biāo)簽
通過將Workbook 類的WorkbookSettings.ShowTabs 屬性設(shè)置為false,可以在Excel文件中隱藏選項卡。
下面是一個完整的示例,該示例打開一個Excel文件(book1.xls),隱藏其選項卡并將修改后的文件另存為output.xls。執(zhí)行代碼后,您將看到工作簿的選項卡被隱藏。
// 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");
控制選項卡欄的寬度
// 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");
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請郵件反饋至chenjj@fc6vip.cn