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

En la segunda parte de esta serie de tutoriales, continuamos nuestra visión general de los cambios en Workbooks for .NET v1.2 examinando diferentes ejemplos para ColumnRange, RowRange, RowHeight y CellRange

Más información Cuadernos Xeed para .NET

Continuamos nuestra visión general de los cambios en Workbooks for .NET v1.2.

Establecer la anchura en ColumnRange

Se ha añadido una propiedad Anchura a la ColumnRange para definir la anchura de las columnas cubiertas por la clase ColumnRange. Utilizando un ColumnRange nos permite definir una serie de Columnas.

La clase ColumnRange tiene las siguientes propiedades:

  • StartingElement: the first WorksheetElement of the range
  • EndingElement: the last WorksheetElement of the range
  • Width: the Width of all Columns in the range *NEW*
  • Elements: the list of all elements in the range (read-only)
  • Count: the number of items in the target range (read-only)
  • Style: the Style object for a worksheet element (read-only)
// Defining a ColumnRange and setting the width of those columns
using( var document = Workbook.Load( "testDoc.xlsx" ));
{
	var firstSheet = document.Worksheets[ 0 ];

	ColumnRange myRange = firstSheet.Columns[ "C", "G" ];
	myRange.Width = 50;

	// ...
}

Creación de RowRanges y ajuste de la Altura en RowRange

Ahora es posible definir un rango de filas consecutivas con la función RowRange clase. A Altura está disponible para establecer la altura de las filas cubiertas por la propiedad RowRange.

La clase RowRange tiene las siguientes propiedades:

  • StartingElement: the first WorksheetElement of the range
  • EndingElement: the last WorksheetElement of the range
  • Height: the Height of all Rows in the range
  • Elements: the list of all elements in the range (read-only)
  • Count: the number of items in the target range (read-only)
  • Style: the Style object for a worksheet element (read-only)
// Defining a RowRange and setting the height of those rows
using( var document = Workbook.Load( "testDoc.xlsx" ));
{
	var firstSheet = document.Worksheets[ 0 ];

	RowRange myRange = firstSheet.Rows[ 10, 25 ];
	myRange.Height = 50;

	// ...
}

Uso de Autoajuste para el Alto de Fila

En Altura puede ajustarse automáticamente en función de la celda más alta de una fila utilizando la función Autoajustar() disponible en el Fila clase.

El método AutoFit() tiene los siguientes parámetros:

  • minimumHeight: the minimum desired Height when AutoFitting a Row, 0 point by default.
  • maximumHeight: the maximum desired Height when AutoFitting a Row, 409 points by default.
  • startColumnId: the id of the Column used as the starting point for the AutoFit's range, 0 or "A" by default, which is the first Column in a Row.
  • endColumnId: the id of the Column used as the ending point of the AutoFit's range, 16383 or "XFD" by default, which is the last possible Column in a Row.

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

// Using AutoFit for the row height
using( var document = Workbook.Load( "testDoc.xlsx" ));
{
	var firstSheet = document.Worksheets[ 0 ];

	// Using all default values
	firstSheet.Rows[ "D" ].AutoFit();

	// Using the column IDs as a number index
	firstSheet.Rows[ "E" ].AutoFit(30, 50, 4, 4);

	// Using the column IDs as a letter index this time
	firstSheet.Rows[ "F" ].AutoFit(30, 50, "E", "E");

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

Modificación del Estilo en CellRange

Estilo se ha añadido la propiedad CellRange para añadir la posibilidad de especificar un estilo en un rango de celdas.

// Setting a Style on a range of cells
using( var document = Workbook.Load( "testDoc.xlsx" ));
{
	var firstSheet = document.Worksheets[ 0 ];

	// Specify the cell range
	CellRange myRange = firstSheet.Cells[ "A2, L2" ];

	// Specify the style
	myRange.Style.Alignment.Vertical = VerticalAlignment.Center;
	myRange.Style.Alignment.Horizontal = HorizontalAlignment.Center;
	myRange.Style.Font = new Font() { Bold = true, Underline = true, Size = 18d };

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

Modificación del estilo en ColumnRange

Estilo se ha añadido la propiedad ColumnRange para añadir la posibilidad de especificar un estilo en un rango de columnas.

// Setting a Style on a range of columns
using( var document = Workbook.Load( "testDoc.xlsx" ));
{
	var firstSheet = document.Worksheets[ 0 ];

	// Specify the column range
	ColumnRange myRange = firstSheet.Columns[ "C", "G" ];

	// Specify the style
	myRange.Style.Font.Size = 14d;
	myRange.Style.Font.Name = "Broadway";
	myRange.Style.Font.Color = System.Drawing.Color.Blue;
	myRange.Style.Alignment.Vertical = VerticalAlignment.Center;
	myRange.Style.Alignment.Horizontal = HorizontalAlignment.Center;

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

Modificación del Estilo en RowRange

Estilo se ha añadido la propiedad RowRange para añadir la posibilidad de especificar un estilo en un rango de filas.

// Setting a Style on a range of rows
using( var document = Workbook.Load( "testDoc.xlsx" ));
{
	var firstSheet = document.Worksheets[ 0 ];

	// Specify the row range
	RowRange myRange = firstSheet.Rows[ 10, 25 ];

	// Specify the style
	myRange.Style.Font.Size = 12d;
	myRange.Style.Font.Name = "Broadway";
	myRange.Style.Font.Color = System.Drawing.Color.Green;
	myRange.Style.Alignment.Vertical = VerticalAlignment.Center;
	myRange.Style.Alignment.Horizontal = HorizontalAlignment.Left;

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

Más información en la Parte III.

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