Differenze tra le versioni di "Formattazione cella PHPExcel"
(→Formattazione del contenuto della cella) |
|||
(10 versioni intermedie di uno stesso utente non sono mostrate) | |||
Riga 1: | Riga 1: | ||
− | [[Libreria PHPExcel|← ritorno a Libreria PHPExcel]] [[Category:PHPExcel]] | + | [[Libreria PHPExcel|← ritorno a Libreria PHPExcel]] [[Category:PHPExcel]] | [[Utilizzo della libreria PHPExcel|← ritorno a Utilizzo della libreria PHPExcel]] {{private}} |
− | |||
− | [[Utilizzo della libreria PHPExcel|← ritorno a Utilizzo della libreria PHPExcel]] {{private}} | ||
+ | == Stile == | ||
Stile di default | Stile di default | ||
<pre> | <pre> | ||
− | (PHPExcel_Style) $style = ((PHPExcel) $ | + | (PHPExcel_Style) $style = ((PHPExcel) $xls)->getDefaultStyle() |
</pre> | </pre> | ||
− | |||
Stile della cella | Stile della cella | ||
<pre> | <pre> | ||
− | (PHPExcel_Style) $style = ((PHPExcel) $ | + | (PHPExcel_Style) $style = ((PHPExcel) $xls)->getStyle('A1') |
</pre> | </pre> | ||
== Stile del testo == | == Stile del testo == | ||
Grassetto | Grassetto | ||
− | $ | + | $xls->getActiveSheet()->getStyle( $cell )->getFont()->setBold( true ); |
+ | |||
+ | Ritorno a capo all'interno di una cella: | ||
+ | $xls->getActiveSheet()->getStyle( 'A1' )->getAlignment()->setWrapText( true ); | ||
+ | |||
+ | == Formattazione del contenuto della cella == | ||
+ | Formattazione cella per un numero a 2 decimali | ||
+ | $xls->getActiveSheet()->getStyle( $col.$row ) | ||
+ | ->getNumberFormat()->setFormatCode( \PHPExcel_Style_NumberFormat::FORMAT_NUMBER_00 ); | ||
+ | Formattazione libera dei numeri | ||
+ | $xls->getActiveSheet()->getStyle( 'G2' )->getNumberFormat()->setFormatCode( '#,##0.00' ); | ||
+ | $xls->getActiveSheet()->getStyle( 'G2' )->getNumberFormat()->setFormatCode( '0.00000' ); | ||
+ | |||
+ | Formattazione ore e minuti | ||
+ | $xls->getActiveSheet()->getStyle( $col.$row ) | ||
+ | ->getNumberFormat()->setFormatCode( '[H]:MM' ); | ||
+ | Alcuni formati identificati in costanti | ||
+ | PHPExcel_Style_NumberFormat::FORMAT_NUMBER | ||
+ | PHPExcel_Style_NumberFormat::FORMAT_NUMBER_00 | ||
+ | PHPExcel_Style_NumberFormat::FORMAT_DATE_DDMMYYYY | ||
+ | |||
+ | == Formattazione dimensione delle celle in base al contenuto == | ||
+ | Formattare la larghezza di una colonna in base alla dimensione del contenuto | ||
+ | $xls->getActiveSheet()->getColumnDimension( $col )->setAutoSize(true); | ||
+ | Ciclo sulle colonne compilate | ||
+ | <pre> | ||
+ | foreach( range( 'A', $this->getActiveSheet()->getHighestDataColumn() ) as $col ) | ||
+ | $xls->getActiveSheet()->getColumnDimension( $col )->setAutoSize(true); | ||
+ | </pre> | ||
== Gli stili applicabili alla cella == | == Gli stili applicabili alla cella == |
Versione attuale delle 15:31, 16 feb 2024
← ritorno a Libreria PHPExcel | ← ritorno a Utilizzo della libreria PHPExcel
Indice
Stile
Stile di default
(PHPExcel_Style) $style = ((PHPExcel) $xls)->getDefaultStyle()
Stile della cella
(PHPExcel_Style) $style = ((PHPExcel) $xls)->getStyle('A1')
Stile del testo
Grassetto
$xls->getActiveSheet()->getStyle( $cell )->getFont()->setBold( true );
Ritorno a capo all'interno di una cella:
$xls->getActiveSheet()->getStyle( 'A1' )->getAlignment()->setWrapText( true );
Formattazione del contenuto della cella
Formattazione cella per un numero a 2 decimali
$xls->getActiveSheet()->getStyle( $col.$row ) ->getNumberFormat()->setFormatCode( \PHPExcel_Style_NumberFormat::FORMAT_NUMBER_00 );
Formattazione libera dei numeri
$xls->getActiveSheet()->getStyle( 'G2' )->getNumberFormat()->setFormatCode( '#,##0.00' ); $xls->getActiveSheet()->getStyle( 'G2' )->getNumberFormat()->setFormatCode( '0.00000' );
Formattazione ore e minuti
$xls->getActiveSheet()->getStyle( $col.$row ) ->getNumberFormat()->setFormatCode( '[H]:MM' );
Alcuni formati identificati in costanti
PHPExcel_Style_NumberFormat::FORMAT_NUMBER PHPExcel_Style_NumberFormat::FORMAT_NUMBER_00 PHPExcel_Style_NumberFormat::FORMAT_DATE_DDMMYYYY
Formattazione dimensione delle celle in base al contenuto
Formattare la larghezza di una colonna in base alla dimensione del contenuto
$xls->getActiveSheet()->getColumnDimension( $col )->setAutoSize(true);
Ciclo sulle colonne compilate
foreach( range( 'A', $this->getActiveSheet()->getHighestDataColumn() ) as $col ) $xls->getActiveSheet()->getColumnDimension( $col )->setAutoSize(true);
Gli stili applicabili alla cella
$style->applyFromArray( array( 'alignment' => array( 'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_GENERAL = 'general' PHPExcel_Style_Alignment::HORIZONTAL_LEFT = 'left' PHPExcel_Style_Alignment::HORIZONTAL_RIGHT = 'right' PHPExcel_Style_Alignment::HORIZONTAL_CENTER = 'center' PHPExcel_Style_Alignment::HORIZONTAL_CENTER_CONTINUOUS = 'centerContinuous' PHPExcel_Style_Alignment::HORIZONTAL_JUSTIFY = 'justify' 'vertical' => PHPExcel_Style_Alignment::VERTICAL_BOTTOM = 'bottom' PHPExcel_Style_Alignment::VERTICAL_TOP = 'top' PHPExcel_Style_Alignment::VERTICAL_CENTER = 'center' PHPExcel_Style_Alignment::VERTICAL_JUSTIFY = 'justify' 'rotation' => (int) 'wrap' => (boolean) 'shrinkToFit' => (boolean) 'indent' => (int) ) 'borders' => array( 'allborders' => array( 'style' => PHPExcel_Style_Border::BORDER_NONE = 'none'; PHPExcel_Style_Border::BORDER_DASHDOT = 'dashDot'; PHPExcel_Style_Border::BORDER_DASHDOTDOT = 'dashDotDot'; PHPExcel_Style_Border::BORDER_DASHED = 'dashed'; PHPExcel_Style_Border::BORDER_DOTTED = 'dotted'; PHPExcel_Style_Border::BORDER_DOUBLE = 'double'; PHPExcel_Style_Border::BORDER_HAIR = 'hair'; PHPExcel_Style_Border::BORDER_MEDIUM = 'medium'; PHPExcel_Style_Border::BORDER_MEDIUMDASHDOT = 'mediumDashDot'; PHPExcel_Style_Border::BORDER_MEDIUMDASHDOTDOT = 'mediumDashDotDot'; PHPExcel_Style_Border::BORDER_MEDIUMDASHED = 'mediumDashed'; PHPExcel_Style_Border::BORDER_SLANTDASHDOT = 'slantDashDot'; PHPExcel_Style_Border::BORDER_THICK = 'thick'; PHPExcel_Style_Border::BORDER_THIN = 'thin'; 'color' => array( 'rgb' => PHPExcel_Style_Color::COLOR_BLACK = 'FF000000'; PHPExcel_Style_Color::COLOR_WHITE = 'FFFFFFFF'; PHPExcel_Style_Color::COLOR_RED = 'FFFF0000'; PHPExcel_Style_Color::COLOR_DARKRED = 'FF800000'; PHPExcel_Style_Color::COLOR_BLUE = 'FF0000FF'; PHPExcel_Style_Color::COLOR_DARKBLUE = 'FF000080'; PHPExcel_Style_Color::COLOR_GREEN = 'FF00FF00'; PHPExcel_Style_Color::COLOR_DARKGREEN = 'FF008000'; PHPExcel_Style_Color::COLOR_YELLOW = 'FFFFFF00'; PHPExcel_Style_Color::COLOR_DARKYELLOW = 'FF808000'; ) ) 'left' => // See 'allborders' 'top' => // See 'allborders' 'right' => // See 'allborders' 'bottom' => // See 'allborders' 'diagonal' => 'diagonaldirection' => ) 'fill' => array( 'type' => PHPExcel_Style_Fill::FILL_NONE = 'none'; PHPExcel_Style_Fill::FILL_SOLID = 'solid'; PHPExcel_Style_Fill::FILL_GRADIENT_LINEAR = 'linear'; PHPExcel_Style_Fill::FILL_GRADIENT_PATH = 'path'; PHPExcel_Style_Fill::FILL_PATTERN_DARKDOWN = 'darkDown'; PHPExcel_Style_Fill::FILL_PATTERN_DARKGRAY = 'darkGray'; PHPExcel_Style_Fill::FILL_PATTERN_DARKGRID = 'darkGrid'; PHPExcel_Style_Fill::FILL_PATTERN_DARKHORIZONTAL = 'darkHorizontal'; PHPExcel_Style_Fill::FILL_PATTERN_DARKTRELLIS = 'darkTrellis'; PHPExcel_Style_Fill::FILL_PATTERN_DARKUP = 'darkUp'; PHPExcel_Style_Fill::FILL_PATTERN_DARKVERTICAL = 'darkVertical'; PHPExcel_Style_Fill::FILL_PATTERN_GRAY0625 = 'gray0625'; PHPExcel_Style_Fill::FILL_PATTERN_GRAY125 = 'gray125'; PHPExcel_Style_Fill::FILL_PATTERN_LIGHTDOWN = 'lightDown'; PHPExcel_Style_Fill::FILL_PATTERN_LIGHTGRAY = 'lightGray'; PHPExcel_Style_Fill::FILL_PATTERN_LIGHTGRID = 'lightGrid'; PHPExcel_Style_Fill::FILL_PATTERN_LIGHTHORIZONTAL = 'lightHorizontal'; PHPExcel_Style_Fill::FILL_PATTERN_LIGHTTRELLIS = 'lightTrellis'; PHPExcel_Style_Fill::FILL_PATTERN_LIGHTUP = 'lightUp'; PHPExcel_Style_Fill::FILL_PATTERN_LIGHTVERTICAL = 'lightVertical'; PHPExcel_Style_Fill::FILL_PATTERN_MEDIUMGRAY = 'mediumGray'; 'rotation' => (double) 'startcolor' => // See 'borders' => 'allborders' => 'color' 'endcolor' => // See 'borders' => 'allborders' => 'color' 'color' => // See 'borders' => 'allborders' => 'color' ) 'font' => array( 'name' => 'Arial' 'Calibri' // etc. 'bold' => (boolean) 'italic' => (boolean) 'superScript' => (boolean) 'subScript' => (boolean) 'underline' => (boolean) 'strike' => (boolean) 'size' => (float) 'color' => // See 'borders' => 'allborders' => 'color' ) 'numberformat' => 'protection' => ) )