ワークブック内のワークシートを非表示および再表示する

ワークシートの非表示と再表示

この記事で比較する隠蔽再表示ワークシートVSTO、C# または Visual Basic を使用して、同じタスクをAspose.Cells、再び C# または Visual Basic を使用します。 Aspose.Cells では、Microsoft Excel がインストールされていなくても作業できます。

ワークシートを非表示にする手順は次のとおりです。

  1. ファイルを開きます。
  2. ワークシートを取得します。
  3. ワークシートを非表示にします。
  4. ファイルを保存します。

再表示する非表示のシートの表示をオンに切り替えるだけです。

以下のコード サンプルは、最初にワークシートを非表示にする方法を示しています。最初のサンプルは、プロセスを示していますVSTO、C# または Visual Basic を使用する場合と比較してAspose.Cells、再び C# または Visual Basics を使用します。

コード サンプルの 2 番目のセットは、ワークシートを再表示するために使用される行を示しています。VSTOまたAspose.Cells.

ワークシートを非表示にする

以下は、ブック内のワークシートを非表示にする方法を示す VSTO および Aspose.Cells のコード サンプルです。

VSTO でワークシートを非表示にする

C#

.......



using Microsoft.VisualStudio.Tools.Applications.Runtime;

using Excel = Microsoft.Office.Interop.Excel;

using Office = Microsoft.Office.Core;

using System.Reflection;

.......



//Instantiate the Application object.

Excel.Application excelApp = new Excel.ApplicationClass();



//Specify the template Excel file path.

string myPath=@"d:\test\MyBook.xls";



//Open the Excel file.

excelApp.Workbooks.Open(myPath, Missing.Value, Missing.Value,

Missing.Value, Missing.Value,

Missing.Value, Missing.Value,

Missing.Value, Missing.Value,

Missing.Value, Missing.Value,

Missing.Value, Missing.Value,

Missing.Value, Missing.Value);



//Get the first sheet.

Excel.Worksheet objSheet = (Excel.Worksheet)excelApp.ActiveWorkbook.Sheets["Sheet1"];

//Hide the worksheet.

objSheet.Visible = Excel.XlSheetVisibility.xlSheetHidden

//Save As the Excel file.

excelApp.ActiveWorkbook.Save();

//Quit the Application.

excelApp.Quit();

Aspose.Cells for .NET でワークシートを非表示にする

C#

.......



using Aspose.Cells;



.......



//Instantiate a new Workbook.

Workbook workbook = new Workbook();

//Specify the template Excel file path.

string myPath = @"d:\test\MyBook.xls";

//Open the Excel file.

workbook.Open(myPath);

//Get the first sheet.

Aspose.Cells.Worksheet objSheet = workbook.Worksheets["Sheet1"];

//Hide the worksheet.

objSheet.IsVisible = false;

//Save As the Excel file.

workbook.Save(@"d:\test\MyBook.xls");

ワークシートの再表示

以下は、VSTO と Aspose.Cells のコード サンプルで、ブック内のワークシートを再表示する方法を示しています。

VSTO でワークシートを再表示する

C#

//Unhide the worksheet.

objSheet.Visible = Excel.XlSheetVisibility.xlSheetVisible;

Aspose.Cells for .NET でワークシートを再表示する

C#

//Unhide the worksheet.

objSheet.IsVisible = true;