Cells Formateo
Contents
[
Hide
]
Formato Cell o Rango de Cells
Si desea formatear una celda o un rango de celdas, entonces Aspose.Cells proporciona elestiloclase. Puede realizar todo el formato de la celda o rango de celdas usando esta clase. Algunas de las cosas relacionadas con el formato que se pueden lograr con la clase IStyle son las siguientes
- Establecer el color de relleno de la celda
- Establecer el ajuste de texto de la celda
- Establezca los bordes de las celdas como los bordes superior, izquierdo, inferior y derecho, etc.
- Establezca el color de la fuente, el tamaño de la fuente, el nombre de la fuente, el tachado, la negrita, la cursiva, el subrayado, etc.
- Establezca la alineación horizontal o vertical del texto a la derecha, izquierda, arriba, abajo, al centro, etc.
Si desea establecer el estilo de una sola celda, utiliceICell->Establecer EstiloI() método y si desea establecer el estilo de un rango de celdas, utiliceIRange->AplicarIEstilo()método.
Código de muestra
El siguiente código de ejemplo da formato a la celda C4 de la hoja de trabajo de varias maneras y la captura de pantalla muestra elarchivo de salida de Excel generado por él para su referencia.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-C | |
//Path of output excel file | |
StringPtr outputFormatCellOrRangeOfCells = outPath->StringAppend(new String("outputFormatCellOrRangeOfCells.xlsx")); | |
//Create a new workbook | |
intrusive_ptr<IWorkbook> wb = Factory::CreateIWorkbook(); | |
//Get first worksheet which is created by default | |
intrusive_ptr<IWorksheet> ws = wb->GetIWorksheets()->GetObjectByIndex(0); | |
//Access cell C4 by cell name | |
intrusive_ptr<ICell> cell = ws->GetICells()->GetObjectByIndex(new String("C4")); | |
//Add some text in cell | |
cell->PutValue((StringPtr)new String("This is sample data.")); | |
//Access the cell style | |
intrusive_ptr<IStyle> st = cell->GetIStyle(); | |
//Fille the cell color to Yellow | |
st->SetPattern(BackgroundType_Solid); | |
st->SetForegroundColor(Systems::Drawing::Color::GetYellow()); | |
//Set the text to wrapp | |
st->SetTextWrapped(true); | |
//Set the left and right border to Red | |
st->SetBorder(BorderType_LeftBorder, CellBorderType_Thick, Systems::Drawing::Color::GetRed()); | |
st->SetBorder(BorderType_RightBorder, CellBorderType_Thick, Systems::Drawing::Color::GetRed()); | |
//Set font color, font size, strike, bold, italic | |
st->GetIFont()->SetColor(Systems::Drawing::Color::GetBlue()); | |
st->GetIFont()->SetSize(16); | |
st->GetIFont()->SetStrikeType(TextStrikeType_Single); | |
st->GetIFont()->SetBold(true); | |
st->GetIFont()->SetItalic(true); | |
//Set text horizontal and vertical alignment to center | |
st->SetHorizontalAlignment(TextAlignmentType_Center); | |
st->SetVerticalAlignment(TextAlignmentType_Center); | |
//Set the cell style | |
cell->SetIStyle(st); | |
//Set the cell column width and row height | |
ws->GetICells()->SetColumnWidth(cell->GetColumn(), 20); | |
ws->GetICells()->SetRowHeight(cell->GetRow(), 70); | |
//Save the output excel file | |
wb->Save(outputFormatCellOrRangeOfCells); |