En savoir plus sur Xeed Workbooks pour .NET
Nous poursuivons notre tour d'horizon des changements apportés par Workbooks for .NET v1.2.
Définition de la largeur d'une plage de colonnes
Une propriété Width (largeur) a été ajoutée à l'élément Plage de colonnes pour définir la largeur des colonnes couvertes par la classe Plage de colonnes. L'utilisation d'un Plage de colonnes nous permet de définir une gamme de Colonnes.
La classe ColumnRange possède les propriétés suivantes :
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;
// ...
}
Création de RowRanges et définition de la hauteur des RowRanges
Il est désormais possible de définir une plage de lignes consécutives à l'aide de la fonction RowRange classe. A Hauteur est disponible pour définir la hauteur des lignes couvertes par la propriété RowRange.
La classe RowRange possède les propriétés suivantes :
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;
// ...
}
Utilisation d'AutoFit pour le RowHeight
Le Hauteur peut être ajustée automatiquement en fonction de la cellule la plus haute d'une ligne en utilisant la fonction AutoFit() disponible sur le site Rangée classe.
La méthode AutoFit() a les paramètres suivants :
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.
La méthode AutoFit() possède deux surcharges, toutes deux avec les mêmes noms de paramètres, mais l'une utilise un entier pour startColumnId et endColumnId afin de spécifier l'identifiant de la colonne par son index, et l'autre utilise des valeurs de chaîne pour spécifier l'identifiant de la colonne par sa lettre (par exemple, l'identifiant 0 est le même que l'identifiant "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();
}
Modifier le style d'une plage de cellules
A Style a été ajoutée à la propriété Plage de cellules pour ajouter la possibilité de spécifier un style sur une plage de cellules.
// 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();
}
Modifier le style de ColumnRange
A Style a été ajoutée à la propriété Plage de colonnes pour ajouter la possibilité de spécifier un style sur une série de colonnes.
// 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();
}
Modifier le style de RowRange
A Style a été ajoutée à la propriété RowRange pour ajouter la possibilité de spécifier un style sur une série de lignes.
// 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();
}
Plus d'informations dans la troisième partie, restez à l'écoute !
Pour plus d'informations, veuillez vous référer à la la documentation.