Cells Formattazione
Contents
[
Hide
]
Formato Cell o Intervallo di Cells
Se desideri formattare una cella o un intervallo di celle, Aspose.Cells fornisce il fileStileclasse. Puoi eseguire tutta la formattazione della cella o dell’intervallo di celle utilizzando questa classe. Di seguito sono riportate alcune delle cose relative alla formattazione che possono essere eseguite con la classe IStyle
- Imposta il colore di riempimento della cella
- Imposta il testo a capo della cella
- Imposta i bordi delle celle come i bordi superiore, sinistro, inferiore e destro, ecc.
- Imposta il colore del carattere, la dimensione del carattere, il nome del carattere, il carattere barrato, il grassetto, il corsivo, il sottolineato, ecc.
- Imposta l’allineamento orizzontale o verticale del testo su destra, sinistra, alto, basso, centro, ecc.
Se si desidera impostare lo stile di una singola cella, utilizzareICell->SetIStyle() metodo e se si desidera impostare lo stile di un intervallo di celle, utilizzareIRange->ApplicaIStyle()metodo.
Codice d’esempio
Il seguente codice di esempio formatta la cella C4 del foglio di lavoro in vari modi e lo screenshot mostra il filefile excel di output generato da esso per il vostro riferimento.
This file contains hidden or 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); |