Dölj och visa kalkylblad i en arbetsbok i VSTO och Aspose.Cells

Den här artikeln jämför att dölja och ta fram kalkylblad med VSTO, med antingen C# eller Visual Basic, med att utföra samma uppgift med Aspose.Cells, återigen med antingen C# eller Visual Basic. Aspose.Cells låter dig arbeta utan Microsoft Excel installerat.

Stegen för att dölja ett kalkylblad är:

  1. Öppna en fil.
  2. Skaffa ett arbetsblad.
  3. Göm kalkylbladet.
  4. Spara filen. För att visa ett kalkylblad igen, aktivera bara synligheten för det dolda bladet.

Kodexemplen nedan visar först hur man döljer ett kalkylblad. De första exemplen visar processen med VSTO, med antingen C#, jämfört med att använda Aspose.Cells, återigen med antingen C#.

Den andra uppsättningen kodexempel visar raden som används för att visa kalkylbladet i VSTO eller Aspose.Cells.

Döljer arbetsblad

Nedan finns kodexempel för VSTO och Aspose.Cells som illustrerar hur man döljer ett kalkylblad i en arbetsbok.

VSTO

 //Instantiate the Application object.

Excel.Application excelApp = Application;

//Specify the template Excel file path.

string myPath = "Book1.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

 //Instantiate a new Workbook.

Workbook workbook = new Workbook();

//Specify the template Excel file path.

string myPath = "Book1.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("Book1.xls");

Ta fram arbetsblad

Nedan finns kodexempel för VSTO och Aspose.Cells som illustrerar hur man visar ett kalkylblad i en arbetsbok.

VSTO

 //Unhide the worksheet.

	objSheet.Visible = Excel.XlSheetVisibility.xlSheetVisible;

Aspose.Cells

 //Unhide the worksheet.

objSheet.IsVisible = true;

Ladda ner provkod