Crear y manipular tablas de Excel

Posibles escenarios de uso

Aspose.Cells le permite crear y manipular tablas o objetos de lista nuevos o existentes. Puede hacer uso de varios métodos del objeto de lista o tabla, por ejemplo, estilo de fila de encabezado, franjas de columna, tipo de estilo, mostrar subtotal, etc. y también trabajar con columnas individuales de la tabla y establecer su nombre y función de cálculo de totales que podría ser Min , Máx., Recuento, Promedio, Suma, etc.

Crear y manipular tablas de Excel

El siguiente código de ejemplo carga elejemplo de archivo de Excel y luego crea un objeto de lista o tabla en un rango A1: H10, luego hace uso de sus diversos métodos y establece mostrar subtotal. Luego establece las funciones totales de las columnas 3, 4 y 5 en Min, Max y Count respectivamente y escribe elarchivo de salida de Excel. La siguiente captura de pantalla muestra el efecto del código de muestra en elejemplo de archivo de Excel después de la ejecución.

todo:imagen_alternativa_texto

Código de muestra

//For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-C
//Source directory path
StringPtr dirPath = new String("..\\Data\\TechnicalArticles\\");
//Output directory path
StringPtr outPath = new String("..\\Data\\Output\\");
//Path of input excel file
StringPtr sampleCreateAndManipulateExcelTable = dirPath->StringAppend(new String("sampleCreateAndManipulateExcelTable.xlsx"));
//Path of output excel file
StringPtr outputCreateAndManipulateExcelTable = outPath->StringAppend(new String("outputCreateAndManipulateExcelTable.xlsx"));
//Load the sample excel file
intrusive_ptr<IWorkbook> wb = Factory::CreateIWorkbook(sampleCreateAndManipulateExcelTable);
//Access first worksheet
intrusive_ptr<IWorksheet> ws = wb->GetIWorksheets()->GetObjectByIndex(0);
//Add table i.e. list object
int idx = ws->GetIListObjects()->Add(new String("A1"), new String("H10"), true);
//Access the newly added list object
intrusive_ptr<IListObject> lo = ws->GetIListObjects()->GetObjectByIndex(idx);
//Use its display methods
lo->SetShowHeaderRow(true);
lo->SetShowTableStyleColumnStripes(true);
lo->SetShowTotals(true);
//Set its style
lo->SetTableStyleType(TableStyleType_TableStyleLight12);
//Set total functions of 3rd, 4th and 5th columns
lo->GetIListColumns()->GetObjectByIndex(2)->SetTotalsCalculation(TotalsCalculation_Min);
lo->GetIListColumns()->GetObjectByIndex(3)->SetTotalsCalculation(TotalsCalculation_Max);
lo->GetIListColumns()->GetObjectByIndex(4)->SetTotalsCalculation(TotalsCalculation_Count);
//Save the output excel file
wb->Save(outputCreateAndManipulateExcelTable);