XLSXWriter 和 Excel "=FILTER()" 函数?
XLSXWriter and Excel "=FILTER()" Function?
我使用 XLSXWriter 成功创建了许多 Excel 工作簿。现在,我正在尝试将 Excel 的一个新(截至 2019 年)FILTER 函数放入一个单元格中:
=FILTER(A19:B90,B19:B90=E19)
当我打开工作簿时,Excel 给我这个错误对话框:
工作簿打开,但单元格中是“0”而不是 FILTER 函数。
但是如果我手动将完全相同的过滤函数粘贴到同一个单元格中,它就可以工作了!
我正在创建的所有其他公式都按预期工作,如果我使用 XLSXWriter 将通用函数放入我希望过滤器进入的同一单元格中,例如=100 *5
,也行。
XLSXWriter 在使用 =FILTER()
函数时是否存在错误?
这有点奇怪。来自 Formulas added in Excel 2010 and later 上的 XlsxWriter 文档:
Excel 2010 and later added functions which weren’t defined in the original file specification. These functions are referred to by Microsoft as future functions. Examples of these functions are ACOT
, CHISQ.DIST.RT
, CONFIDENCE.NORM
, STDEV.P
, STDEV.S
and WORKDAY.INTL
.
When written using write_formula()
these functions need to be fully qualified with a _xlfn.
(or other) prefix as they are shown the list below. For example:
worksheet.write_formula('A1', '=_xlfn.STDEV.S(B1:B10)')
They will appear without the prefix in Excel
但是,这个公式有一个 _xlfn._xlws.
前缀并且也是一个数组公式,所以你必须这样做:
import xlsxwriter
workbook = xlsxwriter.Workbook('test.xlsx')
worksheet = workbook.add_worksheet()
worksheet.write_array_formula('C1:D72',
'=_xlfn._xlws.FILTER(A19:B90,B19:B90=E19)')
workbook.close()
输出:
XlsxWriter 输出和 Excel 之间的一个区别是,它将数组公式显示为 {FILTER(...)}
,带有数组公式的典型大括号,但 Excel 没有吨。但是,我认为该公式按预期工作。您可以在更复杂的例子中尝试验证。
更新:
此公式之所以与其他Excel公式不同,是因为它是Excel365中新增的Dynamic array functions之一。
我使用 XLSXWriter 成功创建了许多 Excel 工作簿。现在,我正在尝试将 Excel 的一个新(截至 2019 年)FILTER 函数放入一个单元格中:
=FILTER(A19:B90,B19:B90=E19)
当我打开工作簿时,Excel 给我这个错误对话框:
工作簿打开,但单元格中是“0”而不是 FILTER 函数。
但是如果我手动将完全相同的过滤函数粘贴到同一个单元格中,它就可以工作了!
我正在创建的所有其他公式都按预期工作,如果我使用 XLSXWriter 将通用函数放入我希望过滤器进入的同一单元格中,例如=100 *5
,也行。
XLSXWriter 在使用 =FILTER()
函数时是否存在错误?
这有点奇怪。来自 Formulas added in Excel 2010 and later 上的 XlsxWriter 文档:
Excel 2010 and later added functions which weren’t defined in the original file specification. These functions are referred to by Microsoft as future functions. Examples of these functions are
ACOT
,CHISQ.DIST.RT
,CONFIDENCE.NORM
,STDEV.P
,STDEV.S
andWORKDAY.INTL
.
When written using
write_formula()
these functions need to be fully qualified with a_xlfn.
(or other) prefix as they are shown the list below. For example:
worksheet.write_formula('A1', '=_xlfn.STDEV.S(B1:B10)')
They will appear without the prefix in Excel
但是,这个公式有一个 _xlfn._xlws.
前缀并且也是一个数组公式,所以你必须这样做:
import xlsxwriter
workbook = xlsxwriter.Workbook('test.xlsx')
worksheet = workbook.add_worksheet()
worksheet.write_array_formula('C1:D72',
'=_xlfn._xlws.FILTER(A19:B90,B19:B90=E19)')
workbook.close()
输出:
XlsxWriter 输出和 Excel 之间的一个区别是,它将数组公式显示为 {FILTER(...)}
,带有数组公式的典型大括号,但 Excel 没有吨。但是,我认为该公式按预期工作。您可以在更复杂的例子中尝试验证。
更新:
此公式之所以与其他Excel公式不同,是因为它是Excel365中新增的Dynamic array functions之一。