Skip to content

Width calculation in column's setAutoSize() with wide-chars #443

@boxsnake

Description

@boxsnake

This is:

What is the expected behavior?

Each wide char should be ~2 normal-char-wide when using setAutoSize(true), e.g.
image

What is the current behavior?

Each wide char only takes one-char width when using setAutoSize(true).
image

What are the steps to reproduce?

Please provide a Minimal, Complete, and Verifiable example of code that exhibits the issue without relying on an external Excel file or a web server:

<?php
require __DIR__ . '/vendor/autoload.php';

use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx as XlsxWriter;

// Create new Spreadsheet object
$spreadsheet = new Spreadsheet();
$sheet       = $spreadsheet->getActiveSheet();

// add code that show the issue here...
// ... Get Data called `$data` (2D-array), each row has index `is_synced`
foreach($data as $i => $item) {
    $rowNum = $i + 1;
    $sheet->setCellValueExplicit("D{$rowNumber}", !empty($row['is_synced']) ? '已同步' : '未同步', \PhpOffice\PhpSpreadsheet\Cell\DataType::TYPE_STRING);
}

$writer = new XlsxWriter($spreadsheet);
$writer->save('php://output');

# Free Memory
$spreadsheet->disconnectWorksheets();
unset($spreadsheet);
exit;

Which versions of PhpSpreadsheet and PHP are affected?

PHP 7.0.12 (NTS)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions