我正在使用python脚本,它使用VLOOKUP
动态生成MS Excel文件。我现在几乎完成了我的任务,现在在生成的Excel文件中遇到了函数错误。函数SUMIF
和#NAME?
被错误地转换,当我手动替换单元格中的任何字符(在公式中)时,#!/usr/bin/env python
# -*- coding: latin-1 -*-
import xlsxwriter
workbook = xlsxwriter.Workbook('test.xlsx', {'strings_to_numbers': True})
worksheet1 = workbook.add_worksheet('Summary')
worksheet1.write_string('A1', 'Head A')
worksheet1.write_string('B1', 'Head B')
worksheet1.write_string('C1', 'Head C')
worksheet1.write_string('A2', '001')
worksheet1.write('B2', '1000')
worksheet1.write('C2', 'Tom')
worksheet1.write_string('A3', '002')
worksheet1.write('B3', '1050')
worksheet1.write('C3', 'Jerry')
worksheet1.write_string('A4', '001')
worksheet1.write('B4', '100')
worksheet1.write('C4', 'Tom')
worksheet1.write_string('A5', '002')
worksheet1.write('B5', '150')
worksheet1.write('C5', 'Jerry')
worksheet2 = workbook.add_worksheet('Test')
worksheet2.write_string('A1', 'Head A')
worksheet2.write_string('B1', 'Head B')
worksheet2.write_string('C1', 'Head C')
for i in range(2):
worksheet2.write_string('A%s' % (i + 2), str('%03d' % (i + 1)))
worksheet2.write_formula('B%s' % (i + 2), '=SUMIF(Summary.A2:A100,A%s,Summary.B2:B100)' % (i + 2))
worksheet2.write_formula('C%s' % (i + 2), '=VLOOKUP(A%s,Summary.A2:C100,3,0)' % (i + 2))
workbook.close()
错误消失并显示实际值。 python脚本的MWE粘贴在下面:
=SUMIF(Summary.A2:A100,A%s,Summary.B2:B100)
即使我在python脚本中提供=SUMIF(summary.a2:a100,a%s,summary.b2:b100)
,它在XLSX文件中显示为VLOOKUP
。 PHP
的情况也是如此。任何人都可以帮我解决这个问题。
答案 0 :(得分:2)
公式语法不正确。它应该是:
=SUMIF(Summary!A2:A100,...
即,您应该使用!
而不是.
。