php - PHP Com Excel 应用过滤器
问题描述
我正在用 com 打开 excel,它工作正常,但是我无法同时将两个过滤器应用于同一列。这是代码:
$excel = new COM("excel.application") or die("Unable to instanciate excel");
$excel->Visible = 1;
$excel->DisplayAlerts = 1;
$wb = $excel->Workbooks->Open($dataFile);
$sheet = $wb->Worksheets(1);
// apply filters
$sheet->range("AS1")->AutoFilter(45, '<>'); // works with single filter
但是,当我想同时将两个过滤器应用于同一列时,它不起作用:
$sheet->range("AS1")->AutoFilter(45, '<> AND > 0'); // DOES NOT WORK
我的猜测是AND
,我应该使用实际的 excel 常量,而不是在上面的语句中使用文字字符串,Excel.XlAutoFilterOperator.xlAnd
但我无法得到它。
任何帮助将不胜感激。
解决方案
好吧想通了,我必须传递额外的参数:
define('xlAnd', 1);
$sheet->range("AS1")->AutoFilter(45, '<>', xlAnd, '> 0');
推荐阅读
- javascript - 为什么我的文字没有显示在中心?
- java - 即使在应用约束后如何查看丢失的按钮?
- python - 为什么这个高阶函数在 mypy 中不通过静态类型检查?
- kubernetes - 部署在同一个 kubernetes 命名空间中的 Apache Ignite 节点不加入同一个集群
- angular - 离子标签 - 角度路由器更改 url 但不更改视图
- python - 通过异步 websocket 客户端与 websocket 服务器保持连接
- python-3.x - 为什么我会得到
而不是数字/字符串 - javascript - 如何使用计数器打破循环
- python - 错误:在 _update_shadow self._shadow = App.get_running_app().theme_cls.quad_shadow
- json - 如何获取嵌套的 JSON 键值然后分配给变量?