这是我的代码:
import xlsxwriter
for val in arr:
sheet.conditional_format('B2:B2000', {'type': 'text',
'criteria': 'containingwith',
'value': val,
'format': formatOk})
我的问题是:我如何得到确切的价值。例如:
如果我在excel中的值是:aaa,aab,aa。而我的val是:aa,所以结果只是aa。
和其他问题:我如何得到这部分我的专栏数:B2:B2000,并没有写一个随机值。
感谢。
答案 0 :(得分:0)
以下内容应该有效:
worksheet1.conditional_format('B2:K12', {'type': 'cell',
'criteria': '==',
'value': '"aa"',
'format': format1})
更新:工作示例:
import xlsxwriter
workbook = xlsxwriter.Workbook('conditional_format.xlsx')
worksheet = workbook.add_worksheet()
# Add a format.
my_format = workbook.add_format({'bg_color': '#FFC7CE',
'font_color': '#9C0006'})
# Add some data to the sheet.
data = [
['Foo', 'Mood', 'Fool', 'Foo'],
['Boo', 'Mood', 'Bool', 'Boo'],
['Goo', 'Good', 'Gool', 'Foo'],
['Foo', 'Food', 'Fool', 'Zoo'],
]
for row, row_data in enumerate(data):
worksheet.write_row(row, 0, row_data)
# Add a conditional format.
worksheet.conditional_format('A1:D4', {'type': 'cell',
'criteria': '==',
'value': '"Foo"',
'format': my_format})
# Close the file.
workbook.close()
输出: