3 回答

TA貢獻(xiàn)1793條經(jīng)驗(yàn) 獲得超6個(gè)贊
不要使用范圍()。當(dāng)單元格超出 Z 時(shí),它將不起作用。請(qǐng)改用
foreach ($sheet->getColumnIterator() as $column) { $sheet->getColumnDimension($column->getColumnIndex())->setAutoSize(true); }

TA貢獻(xiàn)1848條經(jīng)驗(yàn) 獲得超10個(gè)贊
對(duì)于電子表格,答案是:
require 'vendor/autoload.php';
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
use PhpOffice\PhpSpreadsheet\IOFactory;
foreach (range('A','B') as $col) {
$sheet->getColumnDimension($col)->setAutoSize(true);
}

TA貢獻(xiàn)1865條經(jīng)驗(yàn) 獲得超7個(gè)贊
稍微修改一下,不需要您知道電子表格中有多少列:
foreach (range('A', $sheet->getHighestColumn()) as $col) {
$sheet->getColumnDimension($col)->setAutoSize(true);
}
- 3 回答
- 0 關(guān)注
- 396 瀏覽
添加回答
舉報(bào)