En savoir plus sur Xeed Workbooks pour .NET
Nous concluons notre aperçu des changements apportés par Workbooks for .NET v1.2.
Fusionner et défusionner des cellules
La possibilité de fusionner et de défusionner des cellules a été ajoutée. Il est possible de le faire en utilisant la fonction Ajouter() et RemoveAt() sur les méthodes de la feuille de calcul Cellules fusionnées ou avec le MergeCells() et UnmergeCells() sur le site de l Plage de cellules fusionner/dissocier
La propriété MergedCells d'une feuille de calcul est une propriété Collection de cellules fusionnéesqui représente une collection de toutes les plages de cellules qui doivent être fusionnées.
La classe MergedCellCollection possède les propriétés suivantes :
Count: the number of CellRange in the current collection (read-only)
Item: the CellRange object that represents all the Cells that will be merged at the given index (read-only)
La classe MergedCellCollection possède les méthodes suivantes :
Add: adds a CellRange element in the collection
RemoveAt: Removes an element from the collection
La méthode Add() dispose de deux surcharges permettant de spécifier les cellules de début et de fin soit par l'adresse de la cellule, soit en utilisant l'identifiant de la ligne et de la colonne :
Add(startingCellAddress, endingCellAddress, isCenter, isMergeAcross)
Add(startingRowId, startingColumnId, endingRowId, endingColumnId, isCenter, isMergeAcross)
// Using Worksheet.MergedCells
using( var document = Workbook.Load( "testDoc.xlsx" ));
{
var worksheet = document.Worksheets[ 0 ];
// Merge a range by adding it to the collection, using the cell address
worksheet.MergedCells.Add("B5", "C8", true, false);
// Merge a range (B10:C13) by adding it to the collection, using the cell IDs this time
worksheet.MergedCells.Add(9, 1, 12, 2, true, false);
// Unmerging the first range currently in the collection
worksheet.MergedCells.RemoveAt(0);
// save the modifications
document.Save();
}
La méthode MergeCells() de la classe CellRange a les paramètres suivants :
isCenter: centers the text horizontally and vertically; true by default.
isAcross: indicates if the merge is split per Row, for example "A1 : B2" will be merged as "A1: B1" and "A2 : B2"; false by default.
// Using the CellRange directly
using( var document = Workbook.Load( "testDoc.xlsx" ));
{
var worksheet = document.Worksheets[ 0 ];
// Merging
CellRange range1 = worksheet.Cells[ "B5, C8" ];
range1.MergeCells();
// Unmerging
CellRange range2 = worksheet.Cells[ "E5, F8" ];
range2.UnmergeCells();
// save the modifications
document.Save();
}
Envelopper le contenu d'une cellule
Le IsTextWrapped a été ajoutée à la propriété Alignement pour spécifier si le contenu d'une cellule est enveloppé ou non.
// Wrapping the content of a cell
using( var document = Workbook.Load( "testDoc.xlsx" ));
{
var worksheet = document.Worksheets[ 0 ];
worksheet.Cells[ "C12" ].Style.Alignment.IsTextWrapped = true;
// save the modifications
document.Save();
}
Modifier d'autres propriétés de l'image
Le Photo ne disposait auparavant que de l'option Description, DrawingClientData et Verrous d'image et a été étendu à d'autres biens.
La classe Picture possède désormais les propriétés suivantes :
AbsolutePosition: the absolute position of the Picture in the Worksheet, this value must be positive and is of type Position.
Note that setting this value will clear the value of AnchorPosition, as only one or the other can be used.AnchorPosition: the Anchor's position in the Worksheet, this value is of type CellRange.
Note that setting this value will clear the value of AbsolutePosition, as only one or the other can be used.AnchorType: the Anchor's type; can be either an AbsoluteAnchor, a OneCellAnchor or a TwoCellAnchor. (read-only)
BottomRightOffsets: offsets the bottom right corner of a TwoCellAnchor Picture.
Edit: affects the behavior of a TwoCellAnchor Picture when adding and deleting Rows and Columns using Excel's user interface.
Format: the file format of the uploaded media. (read-only)
Height: the height of an AbsoluteAnchor or OneCellAnchor Picture.
MeasureUnit: the unit used for measuring the Width and Height of the Picture.
Name: the name of the Picture in the Worksheet (must be unique across the whole Workbook).
TopLeftOffsets: offsets the top left corner of a TwoCellAnchor Picture.
Width: the width of an AbsoluteAnchor or OneCellAnchor Picture.
Importation de données
Les données peuvent désormais être importées à l'aide de la fonction ImportData() sur la méthode Feuille de travail classe.
La méthode ImportData() prend en charge les données des types suivants :
Array
2D-Array
ArrayList
ICollection
IDictionary
DataTable
DataView
CSV path/stream
La méthode ImportData() a les paramètres suivants :
data: the data to import.
options: the options when importing the data
Les options peuvent être du type suivant :
ImportOptions: import option properties when importing data in a Worksheet
base class for DataTableImportOptions, UserObjectImportOptions and CSVImportOptions.UserObjectImportOptions: import options for user objects when importing data in a Worksheet
derives from ImportOptions, useful when importing user object data, like a List, a Player[] or an ArrayDataTableImportOptions: import options for DataTables when importing data in a Worksheet
derives from ImportOptions, useful when importing a DataTableCSVImportOptions: import options for a CSV document or stream when importing data in a Worksheet
derives from ImportOptions, useful when importing CSV data
Options d'importation
using( var document = Workbook.Load( "testDoc.xlsx" ));
{
var worksheet = document.Worksheets[ 0 ];
// Define a list of strings, the import options(vertical by default) and call the ImportData function.
var stringData = new List() { "First", "Second", "Third", "Fourth" };
var stringImportOptions = new ImportOptions() { DestinationTopLeftAddress = "B5" };
worksheet.ImportData( stringData, stringImportOptions );
// save the modifications
document.Save();
}
Options d'importation d'objets d'utilisateur
using( var document = Workbook.Load( "testDoc.xlsx" ));
{
var worksheet = document.Worksheets[ 0 ];
// Define a list of user objects, the import options (vertical by default, specify PropertyNames and show propertyNames) and call the ImportData function.
var userObjectData = new List()
{
new Player() { Name = "Tom Sawyer", Team = Team.Miami_Ducks, Number = 9 },
new Player() { Name = "Mike Smith", Team = Team.Chicago_Hornets, Number = 18 },
new Player() { Name = "Kelly Tomson", Team = Team.LosAngelese_Raiders, Number = 33 },
new Player() { Name = "John Graham", Team = Team.NewYork_Bucs, Number = 7 },
};
var userObjectImportOptions = new UserObjectImportOptions() { DestinationTopLeftAddress = "H5", PropertyNames = new string[] { "Name", "Team" }, IsPropertyNamesShown = true };
worksheet.ImportData( userObjectData, userObjectImportOptions );
// save the modifications
document.Save();
}
Options d'importation de tables de données
using( var document = Workbook.Load( "testDoc.xlsx" ));
{
var worksheet = document.Worksheets[ 0 ];
// Define a dataTable, the import options(show specific ColumnNames) and call the ImportData function.
var dataTable = new DataTable( "Employees" );
dataTable.Columns.Add( "Name", typeof( string ) );
dataTable.Columns.Add( "Position", typeof( string ) );
dataTable.Columns.Add( "Experience", typeof( double ) );
dataTable.Columns.Add( "Salary", typeof( int ) );
dataTable.Rows.Add( "Jenny Melchuck", "Project Manager", 11.5d, 77000 );
dataTable.Rows.Add( "Cindy Gartner", "Medical Assistant", 1.3d, 56000 );
dataTable.Rows.Add( "Carl Jones", "Web Designer", 4d, 66000 );
dataTable.Rows.Add( "Anna Karlweiss", "Account Executive", 7.8d, 51000 );
dataTable.Rows.Add( "Julia Robertson", "Marketing Coordinator", 17.6d, 65000 );
var dataTableImportOptions = new DataTableImportOptions() { DestinationTopLeftAddress = "B5", ColumnNames = new string[] { "Name", "Experience", "Position" }, IsColumnNamesShown = true };
worksheet.ImportData( dataTable, dataTableImportOptions );
// save the modifications
document.Save();
}
CSVImportOptions
using( var document = Workbook.Load( "testDoc.xlsx" ));
{
var worksheet = document.Worksheets[ 0 ];
// Define a path to a csv document, the import options(which separator to use) and call the ImportData function.
var stringSCVData = "Book1.csv";
var stringCSVImportOptions = new CSVImportOptions() { DestinationTopLeftAddress = "C5", Separator = "," };
worksheet.ImportData( stringSCVData, stringCSVImportOptions );
// save the modifications
document.Save();
}
Pour plus d'informations, veuillez vous référer à la la documentation.