PHP_XLSXWriter icon indicating copy to clipboard operation
PHP_XLSXWriter copied to clipboard

Apply multiple style on one cell

Open Dmo3 opened this issue 4 years ago • 2 comments

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

?

Dmo3 avatar Jan 14 '21 12:01 Dmo3

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

Dobromir78 avatar May 20 '21 14:05 Dobromir78

<?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');

askme-gpt avatar Jun 24 '22 03:06 askme-gpt

see examples/ex03-styles.php

mk-j avatar May 31 '23 22:05 mk-j