viest / php-ext-xlswriter

🚀 PHP Extension for creating and reader XLSX files.
https://xlswriter.viest.me
BSD 2-Clause "Simplified" License
2.26k stars 233 forks source link

Cells format features #115

Closed sirhvd closed 5 years ago

sirhvd commented 5 years ago

How can I format a specific cell?

Ex: Number format, percent format, color, font style only for a specific cell, ...

Thank you for the great excel lib.

viest commented 5 years ago

examples:

use Vtiful\Kernel\Excel;
use Vtiful\Kernel\Format;

$excel = new \Vtiful\Kernel\Excel([
    'path' => './'
]);

$excelObject = $excel->fileName('tutorial.xlsx');
$excelHandle = $excelObject->getHandle();

// new format object
$format = new Format($excelHandle);

// set format
$formatResource = $format->bold()
    ->italic()
    ->color(Format::COLOR_ORANGE)
    ->number('#,##0')
    ->toResource();

// insert data
$filePath = $excelObject->header(['name', 'balance'])
    ->data([
        ['viest', 1000],
        ['wjx',   100000]
    ])
    ->setColumn('B:B', 50, $formatResource)  // set format
    ->output();

image

I hope this example will help you.

sirhvd commented 5 years ago

Thank you. This will help me a lot. But can I ask you for the newest php_xlswriter.dll file? I'm tried to follow your compile instruction from https://github.com/viest/php-ext-excel-export/blob/master/README_zh.md but it's can't compile. It's told me "xlswriter not enabled, xlsxwriter.lib or headers not found" Thank you.

viest commented 5 years ago

Your platform is Windows or Linux?

sirhvd commented 5 years ago

I'm using Windows PHP 7.1.

viest commented 5 years ago

Please download 1.2.4 at PECL.

PECL is building, just a moment, please.

https://pecl.php.net/package/xlswriter

sirhvd commented 5 years ago

Really thank for your time. Can I ask you how to compile this on windows? So I can build myself, I don't want to waste your time for this. Thank you.

viest commented 5 years ago

https://github.com/viest/php-ext-excel-export/wiki/0%E3%80%81Install#windows