【问题标题】:PHPExcel : How to get the cell text and not the formal without calculating the formals during runtimePHPExcel:如何在运行时不计算形式的情况下获取单元格文本而不是形式
【发布时间】:2013-05-17 15:15:05
【问题描述】:

我有一个包含 2 个工作表的 Excel 文件。 第一张纸有近 5000 行,对我来说没用。 第二张表有 25 行,只是需要的行,但这些行是从参考第一张表的公式中获得的。

现在的问题是我只使用 PHPexcel setLoadSheetsOnly() 加载第二张工作表以获得更好的性能。因此系统无法计算引用第一张表的公式。

我的要求是我只想阅读单元格文本(内容显示在单元格中,而不是公式中)。

我已经使用了 getFormattedValue() 和 getCalculatedValue() 但没有帮助。

是否有任何功能或任何方式可以让我只阅读单元格文本而无需考虑任何公式并且不加载第一张纸。

将不胜感激任何意见/想法/建议..

提前致谢。

【问题讨论】:

    标签: php phpexcel


    【解决方案1】:

    您应该使用getCalculatedValue() 方法:如果这不起作用,那么它会返回什么?

    但是如果公式依赖于另一张表中的数据,那么您需要加载另一张表,否则如何进行计算。

    另一个选项是getOldCalculatedValue() 方法;但这不能保证。

    编辑

    /**
     * Get old calculated value (cached)
     * This returns the value last calculated by MS Excel or whichever spreadsheet
     *    program was used to create the original spreadsheet file.
     * Note that this value is not guaranteed to refelect the actual calculated value
     *    because it is possible that auto-calculation was disabled in the original
     *    spreadsheet, and underlying data values used by the formula have changed
     *    since it was last calculated.
     */
    

    【讨论】:

    • 嗨,马克非常感谢您的快速回复。我已经尝试过了,但它给出了错误“致命错误:在非对象中调用成员函数 cellExists()”这是因为我没有加载第一张工作表,而第二张工作表中的公式正在使用第一张工作表中的单元格值。
    • getOldCalculatedValue() 似乎对我有用。我会在不同的细胞上试一试……
    • 当我使用 getCalculatedValue() 或 getFormattedValue() 时,它给出了以下错误错误说:(!)致命错误:在 C:\wamp 中的非对象上调用成员函数 cellExists() \www\testapp\application\third_party\PHPExcel\Calculation.php 在第 3241 行调用堆栈
    猜你喜欢
    • 2021-10-08
    • 2016-09-24
    • 1970-01-01
    • 2021-04-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多