PHPSpreadsheet 无法保存从模板加载的折线图(被 'another user' 锁定)
PHPSpreadsheet Fails to Save Line Chart Loaded From Template (Locked by 'another user')
我 运行 遇到一个问题,phpspreadsheet 不会从我用作模板的 xlsx 文件中写出折线图。
我在打开电子表格时收到两条错误消息:
We found a problem with some content in 'Hello World.xlsx'. Do you want us to try to recover as much as we can? If you trust the source of the workbook, click Yes
Hello World.xlsx is locked for editing
by 'another user'
Open 'Read-Only' or click 'Notify' to open read-only and receive notification when the document is no longer in use.
<?php
// ... snip
$reader = IOFactory::createReader($inputFileType);
$reader->setIncludeCharts(true);
$spreadsheet = $reader->load($inputFileName);
// ... snip
// populate chart data
$sheet = $spreadsheet->getSheetByName('Ratios');
// reverse order, so populate "backwards"
for($endingRow = 14; ($endingRow > 1) && ($row = $last13Ratios->nextRecord()); $endingRow--) {
$sheet->setCellValue('A'.$endingRow, $row->date);
$sheet->setCellValue('B'.$endingRow, $row->percent60/100);
$sheet->setCellValue('C'.$endingRow, $row->percent90/100);
$helper->log(print_r($row));
}
// ... snip
$writer = new XlsxWriter($spreadsheet);
$writer->setIncludeCharts(true);
$callStartTime = microtime(true);
$writer->save($saveFileName);
$helper->logWrite($writer, $saveFileName, $callStartTime);
$spreadsheet->disconnectWorksheets();
die();
如果我在模板中放入假数据,它似乎可以工作。但我不想要假数据,以防出现问题。没有信息总比错误信息好。
简短的回答是在模板中用于数据的部分的左上角单元格中放置一个 space '
。
请注意,数据类型似乎有所不同,另外:日期而不是字符串将失败。
一定要用单引号指定为字符串,否则保存时excel会忽略space
我 运行 遇到一个问题,phpspreadsheet 不会从我用作模板的 xlsx 文件中写出折线图。
我在打开电子表格时收到两条错误消息:
We found a problem with some content in 'Hello World.xlsx'. Do you want us to try to recover as much as we can? If you trust the source of the workbook, click Yes
Hello World.xlsx is locked for editing
by 'another user'
Open 'Read-Only' or click 'Notify' to open read-only and receive notification when the document is no longer in use.
<?php
// ... snip
$reader = IOFactory::createReader($inputFileType);
$reader->setIncludeCharts(true);
$spreadsheet = $reader->load($inputFileName);
// ... snip
// populate chart data
$sheet = $spreadsheet->getSheetByName('Ratios');
// reverse order, so populate "backwards"
for($endingRow = 14; ($endingRow > 1) && ($row = $last13Ratios->nextRecord()); $endingRow--) {
$sheet->setCellValue('A'.$endingRow, $row->date);
$sheet->setCellValue('B'.$endingRow, $row->percent60/100);
$sheet->setCellValue('C'.$endingRow, $row->percent90/100);
$helper->log(print_r($row));
}
// ... snip
$writer = new XlsxWriter($spreadsheet);
$writer->setIncludeCharts(true);
$callStartTime = microtime(true);
$writer->save($saveFileName);
$helper->logWrite($writer, $saveFileName, $callStartTime);
$spreadsheet->disconnectWorksheets();
die();
如果我在模板中放入假数据,它似乎可以工作。但我不想要假数据,以防出现问题。没有信息总比错误信息好。
简短的回答是在模板中用于数据的部分的左上角单元格中放置一个 space '
。
请注意,数据类型似乎有所不同,另外:日期而不是字符串将失败。
一定要用单引号指定为字符串,否则保存时excel会忽略space