Skip to content

csv导出时,长整数会被科学计数且精度丢失怎么办? #4083

Answered by limingxinleo
limingxinleo asked this question in Q&A
Discussion options

You must be logged in to vote
<?php

declare(strict_types=1);
/**
 * This file is part of Hyperf.
 *
 * @link     https://www.hyperf.io
 * @document https://hyperf.wiki
 * @contact  [email protected]
 * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
 */
namespace App\Service;

use Han\Utils\Service;
use Psr\Http\Message\ServerRequestInterface;

class ExcelService extends Service
{
    public function export(): string
    {
        $stream = fopen($file = BASE_PATH . '/' . uniqid() . '.csv', 'w');
        if (is_win()) {
            // 解决 Windows 下乱码的问题
            fwrite($stream, chr(0xEF) . chr(0xBB) . chr(0xBF));
        }

        fputcsv($stream, ['用户ID', '姓名', '年龄']);
        fputcsv($stream, [1, '小…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by limingxinleo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant