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

设置样式报错 #133

Closed needrunning closed 5 years ago

needrunning commented 5 years ago

插件版本 version 1.2.4

代码如下

$fileHandle = $this->handle->getHandle();
        $alignStyle = \Vtiful\Kernel\Format::align(
            $fileHandle,
            \Vtiful\Kernel\Format::FORMAT_ALIGN_CENTER,
            \Vtiful\Kernel\Format::FORMAT_ALIGN_VERTICAL_CENTER
        );
        foreach ($styles as $key => $width) {
            $this->handle->setColumn($key, (int) $width, $alignStyle);
            $this->handle->setColumn($key, (int) $width, $alignStyle);
        }

        $format    = new \Vtiful\Kernel\Format($fileHandle);
        $boldStyle = $format->bold()->toResource();
        $colorStyle = $format->color(\Vtiful\Kernel\Format::COLOR_ORANGE)->toResource();

分别报错

  $format    = new \Vtiful\Kernel\Format($fileHandle);
 "Vtiful\\Kernel\\Format::bold() expects exactly 1 parameter, 0 given"

$colorStyle = $format->color(\Vtiful\Kernel\Format::COLOR_ORANGE)->toResource();
Call to undefined method Vtiful\\Kernel\\Format::color()
viest commented 5 years ago

@needrunning 请问你使用的版本是?

needrunning commented 5 years ago

@needrunning 请问你使用的版本是?

扩展是按照文档安装最新的 如何查看版本?

viest commented 5 years ago

@needrunning

通过 git 拉取安装,还是通过 PECL ?

needrunning commented 5 years ago

两个方式都用过,一样的提示。

发自我的iPhone

------------------ 原始邮件 ------------------ 发件人: viest notifications@github.com 发送时间: 2019年6月30日 15:26 收件人: viest/php-ext-excel-export php-ext-excel-export@noreply.github.com 抄送: needrunning 610212129@qq.com, Mention mention@noreply.github.com 主题: 回复:[viest/php-ext-excel-export] 设置样式报错 (#133)

@needrunning

通过 git 拉取安装,还是通过 PECL ?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

viest commented 5 years ago

color 在 master 分支已经修改为 fontColor

viest commented 5 years ago

文档正在修改,并于今晚发布 1.2.5

needrunning commented 5 years ago

color 在 master 分支已经修改为 fontColor

    $format    = new \Vtiful\Kernel\Format($fileHandle);
    $colorStyle = $format->fontColor(\Vtiful\Kernel\Format::COLOR_ORANGE)->toResource();

这样修改后提示

Call to undefined method Vtiful\Kernel\Format::fontColor()

需要重新更新扩展吧?

viest commented 5 years ago

@needrunning 正在发布 1.2.5

viest commented 5 years ago

@needrunning

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

1.2.5 已发布,请使用 pecl install xlswriter 进行安装

needrunning commented 5 years ago

on my MAC PHP7

Build process completed successfully Installing '/usr/local/Cellar/php@7.2/7.2.18/pecl/20170718/xlswriter.so' install ok: channel://pecl.php.net/xlswriter-1.2.5 Extension xlswriter enabled in php.ini

code

public function style(array $styles) { $fileHandle = $this->handle->getHandle(); $alignStyle = \Vtiful\Kernel\Format::align( $fileHandle, \Vtiful\Kernel\Format::FORMAT_ALIGN_CENTER, \Vtiful\Kernel\Format::FORMAT_ALIGN_VERTICAL_CENTER ); foreach ($styles as $key => $width) { $this->handle->setColumn($key, (int) $width, $alignStyle); }

    $format = new \Vtiful\Kernel\Format($fileHandle);
    $colorStyle = $format->fontColor(\Vtiful\Kernel\Format::COLOR_ORANGE)->toResource();

}

ERROR

Non-static method Vtiful\Kernel\Format::align()

viest commented 5 years ago

align is not a static method, please new a format object.

$format     = new \Vtiful\Kernel\Format($fileHandle);
$alignStyle = $format
    ->align(Format::FORMAT_ALIGN_CENTER, Format::FORMAT_ALIGN_VERTICAL_CENTER)
    ->toResource();
needrunning commented 5 years ago

align is not a static method, please new a format object.

$format     = new \Vtiful\Kernel\Format($fileHandle);
$alignStyle = $format
    ->align(Format::FORMAT_ALIGN_CENTER, Format::FORMAT_ALIGN_VERTICAL_CENTER)
    ->toResource();

OK that is OK

but another error code

$this->handle->header($header)->data($data);
        $fileHandle = $this->handle->getHandle();
        $format = new \Vtiful\Kernel\Format($fileHandle);
        $colorStyle = $format->fontColor(0xFF0000)->toResource();
        $boldStyle = $format->bold()->toResource();

error Call to undefined method Vtiful\Kernel\Format::fontColor()

I found that it is incorrect about color setting

viest commented 5 years ago

@needrunning

php --ri xlswriter

# You can get this output
xlswriter

xlswriter support => enabled
Version => 1.2.5
bundled libxlsxwriter version => 0.7.9

Please attach your output.