mk-j / PHP_XLSXWriter

Lightweight XLSX Excel Spreadsheet Writer in PHP
MIT License
1.84k stars 665 forks source link

Apply multiple style on one cell #297

Closed Dmo3 closed 1 year ago

Dmo3 commented 3 years ago

Hi,

Is there any option that allows me to specify the style for a specific word in the string of cell

Like this

italic with some bold text

?

Dobromir78 commented 3 years ago

I'd be grateful to learn the answer too...

askme-gpt commented 2 years ago
<?php
include_once("XlsWriter.class.php");

$header = [
    'created' => 'date',
    'product_id' => 'integer',
    'quantity' => '#,##0',
    'amount' => 'price',
    'description' => 'string',
    'tax' => '[$$-1009]#,##0.00;[RED]-[$$-1009]#,##0.00',
];
$data = [
    ['2015-01-01', 873, 1, '44.00', 'misc', '=D2*0.05'],
    ['2015-01-12', 324, 2, '88.00', 'none', '=D3*0.05'],
];

$writer = new XLSXWriter();
$styles = [
    'widths' => [3, 20, 30, 40],
    'font' => 'Arial', 'font-size' => 10,
    'font-style' => 'bold', 'fill' => '#eee',
    'halign' => 'center', 'border' => 'left,right,top,bottom',
];
$styles2 = [
    ['font' => 'Arial', 'font-size' => 10, 'font-style' => 'bold', 'halign' => 'left', 'border' => 'left,right,top,bottom', 'fill' => '#ffc'],
    ['fill' => '#fcf'],
    ['fill' => '#fcf'],
    ['fill' => '#fcf'],
    ['fill' => '#ccf'],
    ['fill' => '#cff'],
];

$writer->writeSheetHeader('Sheet1', $header,$styles);
foreach ($data as $row)
    $writer->writeSheetRow('Sheet1', $row, $styles2);
$writer->writeToFile('example1.xlsx');
mk-j commented 1 year ago

see examples/ex03-styles.php