gpt4 book ai didi

PHPSpreadsheet - 如何创建一个额外的标签?

转载 作者:行者123 更新时间:2023-12-03 16:13:52 25 4
gpt4 key购买 nike

我在我的 php 代码中创建了一个带有一个选项卡的 excel 文件并为其命名。
我使用的代码是这样的:

// CREATE PHPSPREADSHEET OBJECT
require "../vendor/autoload.php";
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
use PhpOffice\PhpSpreadsheet\Worksheet\Drawing;

// CREATE A NEW SPREADSHEET + POPULATE DATA
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->setTitle('Batch');

但是如何创建另一个名称的第二个选项卡?

[解决了]
// CREATE A NEW SPREADSHEET + POPULATE DATA
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->setTitle('Batch');
// Add some data
$spreadsheet->createSheet();
// Add some data
$spreadsheet->setActiveSheetIndex(1) ->setCellValue('A1', 'world!');
// Rename worksheet
$spreadsheet->getActiveSheet()->setTitle('URL Removed');
// Set active sheet index to the first sheet, so Excel opens this as the first sheet
$spreadsheet->setActiveSheetIndex(0);

最佳答案

您可以添加一个额外的选项卡,如下所示:

$spreadsheet->createSheet();
// Zero based, so set the second tab as active sheet
$spreadsheet->setActiveSheetIndex(1)
$spreadsheet->getActiveSheet()->setTitle('Second tab');

如果您愿意, you can read more here .

关于PHPSpreadsheet - 如何创建一个额外的标签?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54736333/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com