Actualización de la versión 1.2 en Workbooks for .NET - Parte I

La versión 1.2 de Workbooks para .NET fue lanzada recientemente, y con ella vienen nuevas cosas que podemos hacer para personalizar nuestros documentos xlsx. Repasaremos algunas de ellas a lo largo de este y los próximos artículos.

Más información Cuadernos Xeed para .NET

La versión 1.2 de Workbooks para .NET fue lanzada recientemente, y con ella vienen nuevas cosas que podemos hacer para personalizar nuestros documentos xlsx. Repasaremos algunas de ellas a lo largo de este y los próximos artículos.

Insertar una hoja de cálculo

En nuestro primer artículo vimos cómo añadir una hoja de cálculo a nuestro documento utilizando la función Añadir() en el Colección de hojas de cálculo. Esto nos permitía añadir una hoja de cálculo, pero sólo al final de las hojas de cálculo existentes. En la v1.2 añadimos la función Insertar() para permitir a los usuarios especificar dónde quieren añadir la nueva hoja de cálculo.

Available overloads:

  • Insert(Int32,String) : the destination index and the name of the new Worksheet
  • Insert(String,String) : the name of the Worksheet that is currently located where the new Worksheet will be placed, and the name of the new Worksheet
  • Insert(Worksheet,String) : the Worksheet that is currently located where the new Worksheet will be placed, and the name of the new Worksheet
// Inserting a new Worksheet
using( var document = Workbook.Load( "testDoc.xlsx" ));
{
	// Start: "Sheet1", "Sheet2", "Sheet3"

	// Inserting at a specific index
	document.Worksheets.Insert(2, "NewSheet1");
	// Result: "Sheet1", "Sheet2", "NewSheet1", "Sheet3"

	// Inserting at the location of a specific Worksheet (by name)
	document.Worksheets.Insert("Sheet2", "NewSheet2");
	// Result: "Sheet1", "NewSheet2", "Sheet2", "NewSheet1", "Sheet3"

	// Inserting at the location of a specific Worksheet (by object)
	var position = document.Worksheets[ 2 ];
	document.Worksheets.Insert(position, "NewSheet3");
	// Result: "Sheet1", "NewSheet2", "NewSheet3", "Sheet2", "NewSheet1", "Sheet3"

	// save the modifications
	document.Save();
}

Insertar filas

Las filas pueden insertarse utilizando la tecla InsertarFilas() disponible en la página Hoja de trabajo clase.

En InsertarFilas() tiene los siguientes parámetros:

  • rowId: the id of the Row that is currently located where the new Rows will be inserted
  • count: the number of Rows that will be inserted, 1 by default
// Inserting rows
using( var document = Workbook.Load( "testDoc.xlsx" ));
{
	var firstSheet = document.Worksheets[ 0 ];

	// Insert 5 rows at the top of the worksheet
	firstSheet.InsertRows(0, 5);

	// save the modifications
	document.Save();
}

Insertar columnas

Las columnas pueden insertarse utilizando la función InsertarColumnas() disponible en la página Hoja de trabajo clase.

En InsertarColumnas() tiene los siguientes parámetros:

  • columnId: the id of the Column that is currently located where the new Columns will be inserted
  • count: the number or Columns that will be inserted, 1 by default

El método InsertColumns() tiene 2 sobrecargas, ambas tienen los mismos nombres de parámetros, pero una usa un entero para columnId para especificar el id de la columna por su índice, y la otra usa una cadena para especificar el id de la columna por su letra (por ejemplo, id 0 es lo mismo que id "A").

// Inserting columns
using( var document = Workbook.Load( "testDoc.xlsx" ));
{
	var firstSheet = document.Worksheets[ 0 ];

	// Insert 3 columns at the left of the worksheet using the number index
	firstSheet.InsertColumns(0, 3);

	// Insert another 2 columns at the left of the worksheet using the letter index this time
	firstSheet.InsertColumns("A", 2);

	// save the modifications
	document.Save();
}

Borrar filas

Las filas pueden eliminarse mediante la tecla BorrarFilas() disponible en la página Hoja de trabajo clase.

En BorrarFilas() tiene los siguientes parámetros:

  • rowId: the id of the Row that is currently located where the deletion will start
  • count: the number of Rows that will be deleted, 1 by default
// Deleting rows
using( var document = Workbook.Load( "testDoc.xlsx" ));
{
	var firstSheet = document.Worksheets[ 0 ];

	// Delete the top 5 rows
	firstSheet.DeleteRows(0, 5);

	// save the modifications
	document.Save();
}

Borrar columnas

Las columnas pueden eliminarse mediante la función BorrarColumnas() disponible en la página Hoja de trabajo clase.

En BorrarColumnas() tiene los siguientes parámetros:

  • columnId: the id of the Column that is currently located where the deletion will start
  • count: the number or Columns that will be deleted, 1 by default

El método DeleteColumns() tiene 2 sobrecargas, ambas tienen los mismos nombres de parámetros, pero una usa un entero para columnId para especificar el id de la columna por su índice, y la otra usa una cadena para especificar el id de la columna por su letra (por ejemplo, id 0 es lo mismo que id "A").

// Deleting columns
using( var document = Workbook.Load( "testDoc.xlsx" ));
{
	var firstSheet = document.Worksheets[ 0 ];

	// Delete the 3 left-most columns using the number index
	firstSheet.DeleteColumns(0, 3);

	// Delete another 2 columns at the left using the letter index this time
	firstSheet.DeleteColumns("A", 2);

	// save the modifications
	document.Save();
}

Más información en la Parte II, ¡siga atento!

Para más información, consulte el documentación.