Ocultar y mostrar filas y columnas con Node.js vía C++

Controlar la Visibilidad de Filas y Columnas

Aspose.Cells for Node.js via C++ proporciona una clase, Workbook, que representa un archivo de Microsoft Excel. La clase Workbook contiene un WorksheetCollection que permite a los desarrolladores acceder a cada hoja en el archivo de Excel. Una hoja se representa mediante la clase Worksheet. La clase Worksheet proporciona una colección Cells que representa todas las celdas en la hoja. La colección Cells proporciona varios métodos para gestionar filas o columnas en una hoja. Algunos de estos se discuten a continuación.

Ocultar Filas y Columnas

Los desarrolladores pueden ocultar una fila o columna llamando a los métodos hideRow(number) y hideColumn(number) de la colección Cells respectivamente. Ambos métodos toman el índice de fila y columna como parámetro para ocultar la fila o columna específica.

const path = require("path");
const fs = require("fs");
const AsposeCells = require("aspose.cells.node");

// The path to the documents directory.
const dataDir = path.join(__dirname, "data");
const filePath = path.join(dataDir, "book1.xls");

// Reading the Excel file into a buffer
const fileBuffer = fs.readFileSync(filePath);

// Instantiating a Workbook object with Uint8Array
const workbook = new AsposeCells.Workbook(new Uint8Array(fileBuffer));

// Accessing the first worksheet in the Excel file
const worksheet = workbook.getWorksheets().get(0);

// Hiding the 3rd row of the worksheet
worksheet.getCells().hideRow(2);

// Hiding the 2nd column of the worksheet
worksheet.getCells().hideColumn(1);

// Saving the modified Excel file
workbook.save(path.join(dataDir, "output.out.xls"));

Mostrar Filas y Columnas

Los desarrolladores pueden mostrar cualquier fila o columna oculta llamando a los métodos unhideRow(number, number) y unhideColumn(number, number) de la colección Cells respectivamente. Ambos métodos requieren dos parámetros:

  • Índice de fila o columna - el índice de una fila o columna que se utiliza para mostrar la fila o columna específica.
  • Altura de fila o ancho de columna - la altura de fila o el ancho de columna asignados a la fila o columna después de desocultar.
const path = require("path");
const fs = require("fs");
const AsposeCells = require("aspose.cells.node");

// The path to the documents directory.
const dataDir = path.join(__dirname, "data");
const filePath = path.join(dataDir, "book1.xls");
// Read the Excel file into a Buffer (Uint8Array)
const fileBuffer = fs.readFileSync(filePath);

// Instantiating a Workbook object with file buffer
const workbook = new AsposeCells.Workbook(fileBuffer);

// Accessing the first worksheet in the Excel file
const worksheet = workbook.getWorksheets().get(0);

// Unhiding the 3rd row and setting its height to 13.5
worksheet.getCells().unhideRow(2, 13.5);

// Unhiding the 2nd column and setting its width to 8.5
worksheet.getCells().unhideColumn(1, 8.5);

// Saving the modified Excel file
workbook.save(path.join(dataDir, "output.xls"));

Ocultar Múltiples Filas y Columnas

Los desarrolladores pueden ocultar varias filas o columnas a la vez llamando a los métodos hideRows(number, number) y hideColumns(number, number) de la colección Cells respectivamente. Ambos métodos toman el índice de fila o columna inicial y el número de filas o columnas que deben ocultarse como parámetros.

const fs = require("fs");
const path = require("path");
const AsposeCells = require("aspose.cells.node");

// The path to the documents directory.
const dataDir = path.join(__dirname, "data");
const filePath = path.join(dataDir, "book1.xls");

// Creating a file stream containing the Excel file to be opened
const fileStream = fs.readFileSync(filePath);

// Instantiating a Workbook object
// Opening the Excel file through the file stream
const workbook = new AsposeCells.Workbook(fileStream);

// Accessing the first worksheet in the Excel file
const worksheet = workbook.getWorksheets().get(0);

// Hiding 3, 4, and 5 rows in the worksheet
worksheet.getCells().hideRows(2, 3);

// Hiding 2 and 3 columns in the worksheet
worksheet.getCells().hideColumns(1, 2);

// Saving the modified Excel file
workbook.save(path.join(dataDir, "outputxls"));