我试图用phpexcel从某个源加载一个excel文件。我无法控制这些excel文件是如何生成的,它们需要使用phpexcel自动打开,而无需人工交互(重新保存文件等)。
我得到以下错误:
致命错误:未捕获异常“exception”,在第418行的c:\ path\to\phpexcel\worksheet.php中显示消息“在工作表标题中找到无效字符”
错误发生在load()行,使用以下代码打开文件:

$reader = PHPExcel_IOFactory::createReader('Excel5');
$excel = $reader->load($filename_xls);

单子标题与我们无关,所以可以忽略它吗?所以忽略了错误?

最佳答案

我们这样做是为了让事情暂时解决。这可能是可怕的坏,我不会真的建议其他人这样做,但嘿,它应该为我们工作!
在phpexcel的1.7.8版本上,在/Classes/PHPExcel/Worksheet.php周围的line 414中-将checkSheetTitle()函数替换为以下项:

private static function _checkSheetTitle($pValue)
{
    // Some of the printable ASCII characters are invalid:  * : / \ ? [ ]
    if (str_replace(self::$_invalidCharacters, '', $pValue) !== $pValue) {
        //throw new Exception('Invalid character found in sheet title');

        //Hack to remove bad characters from sheet name instead of throwing an exception
        return str_replace(self::$_invalidCharacters, '', $pValue);
    }

    // Maximum 31 characters allowed for sheet title
    if (PHPExcel_Shared_String::CountCharacters($pValue) > 31) {
        throw new Exception('Maximum 31 characters allowed in sheet title.');
    }

    return $pValue;
}

07-24 09:38
查看更多