Dölja och visa rader och kolumner

Kontrollera synligheten för rader och kolumner

Aspose.Cells tillhandahåller en klass,Arbetsbok , som representerar en Microsoft Excel-fil. DeArbetsbok klass innehåller enArbetsbladssamling som låter utvecklare komma åt varje kalkylblad i Excel-filen. Ett arbetsblad representeras avArbetsblad klass. DeArbetsblad klass ger enCells samling som representerar alla celler i kalkylbladet. DeCellssamling innehåller flera metoder för att hantera rader eller kolumner i ett kalkylblad. Några av dessa diskuteras nedan.

Döljer rader och kolumner

Utvecklare kan dölja en rad eller kolumn genom att anropaHideRow ochDölj kolumn metoder förCellsinsamling respektive. Båda metoderna tar rad- och kolumnindex som en parameter för att dölja den specifika raden eller kolumnen.

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// 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();

Visar rader och kolumner

Utvecklare kan visa alla dolda rader eller kolumner genom att anropaVisa rad ochTa fram kolumn metoder förCellsinsamling respektive. Båda metoderna tar två parametrar:

  • Rad- eller kolumnindex - indexet för en rad eller kolumn som används för att visa den specifika raden eller kolumnen.
  • Radhöjd eller kolumnbredd - radhöjden eller kolumnbredden som tilldelats raden eller kolumnen efter att ha visat sig.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// 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();

Dölja flera rader och kolumner

Utvecklare kan dölja flera rader eller kolumner samtidigt genom att anropaGöm rader ochDölj kolumner metoder förCellsinsamling respektive. Båda metoderna tar startraden eller kolumnindexet och antalet rader eller kolumner som ska döljas som parametrar.

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// 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();