Más información Cuadernos Xeed para .NET
Concluimos nuestra visión general de los cambios en Workbooks for .NET v1.2.
Fusión y separación de celdas
Se ha añadido la posibilidad de unir y separar celdas. Puede hacerse utilizando la función Añadir() y QuitarAt() de la hoja de cálculo CeldasFusionadas o con la FusionarCélulas() y UnmergeCells() métodos en el CellRange fusionar/desunir
La propiedad MergedCells de una hoja de cálculo es una propiedad MergedCellCollectionque representa una colección de todos los rangos de celdas que deben fusionarse.
La clase MergedCellCollection tiene las siguientes propiedades:
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 clase MergedCellCollection tiene los siguientes métodos:
Add: adds a CellRange element in the collection
RemoveAt: Removes an element from the collection
El método Add() tiene 2 sobrecargas disponibles, para especificar las celdas de inicio y fin por dirección de celda o usando los ids de fila y columna:
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();
}
El método MergeCells() de la clase CellRange tiene los siguientes parámetros:
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();
}
Envolver el contenido de una celda
En IsTextWrapped se ha añadido la propiedad Alineación para especificar si el contenido de una celda se envuelve o no.
// 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();
}
Modificar más propiedades de la imagen
En Fotografía anteriormente sólo tenía la clase Descripción, DrawingClientData y PictureLocks propiedades, y se amplió para incluir más propiedades.
La clase Picture ahora también tiene las siguientes propiedades:
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.
Importar datos
Ahora los datos pueden importarse utilizando la función ImportData() en el Hoja de trabajo clase.
El método ImportData() admite datos de los siguientes tipos:
Array
2D-Array
ArrayList
ICollection
IDictionary
DataTable
DataView
CSV path/stream
El método ImportData() tiene los siguientes parámetros:
data: the data to import.
options: the options when importing the data
Las opciones pueden ser de los siguientes tipos:
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
ImportOptions
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();
}
UserObjectImportOptions
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();
}
DataTableImportOptions
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();
}
Para más información, consulte el documentación.