我有一个用PhpSpreadsheet读写的Excel文件。我所有的表和引用在此过程中都消失了。是否需要将标志设置为true / false还是表仅仅是PhpSpreadsheet无法处理的标志?查看导出前后的屏幕截图。
我尝试了不同的真假组合,但没有setIncludeCharts(true);
和setPreCalculateFormulas(true)
的运气
这里显然没有我想念的东西吗?
require 'vendor/autoload.php';
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader('Xlsx');
$spreadsheet = $reader->load("template.xlsx");
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="result.xlsx"');
header('Cache-Control: max-age=0');
$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xlsx');
$writer->save('php://output');
exit;
如果error_reporting(0)
与它们有任何关系,我将用Notice: Undefined offset: 2 in
/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Calculation/Calculation.php
on line 3472
Warning: trim() expects parameter 1 to be string, array given in
/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Calculation/Calculation.php
on line 3680
禁止这些通知/警告。但是,那是在PhpSpreadsheet代码中,我真的不应该把它弄乱:
Fatal error: Uncaught PhpOffice\PhpSpreadsheet\Exception: Invalid cell coordinate 1))) in vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Cell/Coordinate.php:42 Stack trace: #0 vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Cell/Coordinate.php(111): PhpOffice\PhpSpreadsheet\Cell\Coordinate::coordinateFromString('1)))') #1 vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Cell/Coordinate.php(86): PhpOffice\PhpSpreadsheet\Cell\Coordinate::absoluteCoordinate('1)))') #2 vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Writer/Xlsx/Workbook.php(416): PhpOffice\PhpSpreadsheet\Cell\Coordinate::absoluteReference('1)))') #3 vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Writer/Xlsx/Workbook.php(267): PhpOffice\PhpSpreadsheet\Writer\Xlsx\Workbook->writeDefinedNameForPrintArea(Object(PhpOffice\PhpSpreadsheet\Shared\XMLWriter), Object(PhpOffice\PhpS in vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Cell/Coordinate.php on line 42
我还尝试了相同模板的不同版本,该版本给了我这个错误:
<body onload="hidebtn()"> <header class="topBar"> <ul class="nav nav-tabs row" id="myTab" role="tablist"> <li class="nav-item col"> <a class="nav-link active" id="home-tab" data-toggle="tab" href="#home" role="tab" aria-controls="home" aria-selected="true" style="padding-top: 20px; font-size: 14px; cursor: pointer;" onclick="chat()">Chat</a> </li> <li class="nav-item col"> <a class="nav-link" id="profile-tab" data-toggle="tab" href="#profile" role="tab" aria-controls="profile" aria-selected="false" style="padding-top: 20px; font-size: 14px; cursor: pointer;" onclick="ticketStatus()">Incident</a> </li> <li class="nav-item col"> <a class="nav-link" id="contact-tab" data-toggle="tab" href="#contact" role="tab" aria-controls="contact" aria-selected="false" style="padding-top: 20px; font-size: 14px; cursor: pointer;" onclick="ticketStatus()">Service Request</a> </li> </ul> </header><br><br> <div class="tab-content" id="myTabContent" style="overflow:hidden;"> <div class="tab-pane fade show active" id="home" role="tabpanel" aria-labelledby="home-tab"> <div class="container"> <div class="row h-100"> <div id="topButtons" class="card-body" style="padding: 0; margin-top: 12px; height: 80px;"></div> <div id="chatBody" class="card-body anyClass"> <p class="WC_message_fl"><img class="con_im" src="images\chatrobo.png"></p> <p class="WC_message_f"> Type your Questions & Start chatting </p> </br></br> </div> </div> </div> </div> <div class="tab-pane fade" id="profile" role="tabpanel" aria-labelledby="profile-tab" > </br></br> <p class="WC_message_fl" id='msg_table'></p> <div class="container" style="overflow-x:hidden;overflow-y:auto;height:84vh;"><div class="row" id="table"></div> </div> </div> <div class="tab-pane fade" id="contact" role="tabpanel" aria-labelledby="contact-tab" > </br></br> <p class="WC_message_fl" id='msg_sr_table'></p> <div class="container" style="overflow-x:hidden;overflow-y:auto;height:84vh;"><div class="row" id="sr_table"></div></div> </div> </div> <footer id="footerChtbt" style="position:fixed;bottom:0;right:0;left:0;height: 45px;line-height: 20px;background-color: #ECEFF1;font-size: 0.6rem;border-top: 1px solid #aaa;box-shadow: 0 1px 5px 0 #9B9B9B;"> <span id="Resp" style="color:blue; position: absolute; z-index: 1000; left: 8vw;"></span> <div class="container"> <div class="row"> <div class="col-10"> <input id="query" type="text" class="form-control" placeholder = 'Ask sth...'" onkeyup="pressedkey(event)" style="outline:0;box-shadow:none;font-size:14px;" required /> </div> <div class="col-2" style="padding: 0; margin-top: 2px;"> <img src="images/send_icon.svg" name="submitbtn" onClick="sendbtn()" style="cursor: pointer; width: 40px;"> </div> </div> </div> </footer>
答案 0 :(得分:0)
智能表在后台使用数据透视表。我发现解决这个问题的唯一方法是手工设置单元格的样式。
答案 1 :(得分:0)
正在处理同样的问题,除了像 Collie 提到的那样手动设置单元格样式之外,找不到任何解决方法。
我改为使用 OpenTBS 插件转移到 TinyButStrong:https://www.tinybutstrong.com/opentbs.php
这个插件允许我打开一个类似的 XLSX 文件作为你的屏幕截图,其中包含表格、下拉菜单和 PHP 样式,将其用作模板并编辑列/添加值而不会丢失任何内容,因为它使用的是不同的方法。>
当然,这不包括您可能需要从 PhpSpreadsheet 中获得的所有功能。但是对于简单的列/值编辑,这对我来说是一个不错的选择,而且它也非常轻量级。
希望对大家有所帮助。