php - 使用 Spout 写入从 Excel 读取的数据失败

标签 php excel

我正在使用 Spout 读取 excelsheet 并直接将此数据写入表中会导致错误。

Trying to add a value with an unsupported type: object in vendor/box/spout/src/Spout/Writer/XLSX/Internal/Worksheet.php on line 231

有人有解决办法吗?

$reader = ReaderFactory::create(Type::XLSX);
$reader->open($sFileNameExcel);

$writer = WriterFactory::create(Type::XLSX);
$writer->openToFile($sWritePath.$sWriteFileName);

foreach ($reader->getSheetIterator() as $sheet) 
{
    if ($sheet->getName()=='mysheet')
    {
        foreach ($sheet->getRowIterator() as $row) 
        {
            $writer->addRow($row);
        }
    }
}

$writer->close();
$reader->close();

我的数据由字符串、整数和 double 字段组成。

最佳答案

您正在阅读的表格可能包含日期。但作者无法解释日期,因此会出现错误。

尝试以这种方式配置您的阅读器:在调用 open 之前 $reader->setShouldFormatDates(true);

关于php - 使用 Spout 写入从 Excel 读取的数据失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49073610/

相关文章:

vba - MS Excel 2003 - 处理形状时 Excel VBA 中的简单取消选择问题

python - 如何将数据从 excel 列提取到 Python 列表中?

vba - 在excel vba数组中查找唯一日期

arrays - 为什么 Excel.Range.Group 的 Periods 参数需要一个数组?

php - 按 bool 值排序

php - 从命令行在我的网站上运行 .php 脚本

php - Symfony2 形成部分绑定(bind)

Excel 比较列表 2(当前)与列表 1(现有)的重复项和新项

PHP file_exists 或 is_file 在 NFS 文件 (EC2) 上无法正确回答 10-20s

javascript - 我正在尝试使用 Ajax 将数据发送到另一个页面