1
我正在使用一個Python腳本,它使用xlsxwriter
來即時生成MS Excel文件。現在我已經完成了我的任務,現在在生成的Excel文件中遇到函數錯誤。功能VLOOKUP
和SUMIF
被錯誤地轉換,當我手動替換單元格中的任何字符時(公式中),#NAME?
錯誤消失並顯示實際值。在python腳本的MWE下面粘貼:xlsxwriter:函數VLOOKUP,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()
即使我給=SUMIF(Summary.A2:A100,A%s,Summary.B2:B100)
在python腳本就顯示爲XLSX文件=SUMIF(summary.a2:a100,a%s,summary.b2:b100)
。 VLOOKUP
的情況也是如此。任何人都可以幫助我解決這個問題。
謝謝。這就像一個魅力。 – Jagath