簡體   English   中英

使用xlsxwriter條件格式化(公式)后刪除列

[英]Delete column after conditional formatting (formula) using xlsxwriter

我有一個列(列V),我曾經使用引擎xlsxwriter有條件地格式化另一列(列U)。

所以我有這個:

# Light yellow fill with dark yellow text.
format1 = workbook.add_format({'bg_color':   '#FFEB9C'})

# Light red fill with dark red text.
format2 = workbook.add_format({'bg_color':   '#FFC7CE',
                           'font_color': '#9C0006'})


worksheet.conditional_format('U2:U1000', {'type': 'formula', 
                                 'criteria': '=V2>25',
                                 'format': format1})

worksheet.conditional_format('U2:U1000', {'type': 'formula',  
                                 'criteria': '=V2<-20',
                                 'format': format2})

因此,現在在使用條件格式突出顯示列U之后,我要刪除列V(但保持突出顯示不變)。 有沒有辦法在xlsxwriter中做到這一點?

因為它是使用公式的條件格式,所以刪除引用的列將刪除引用的內容並“破壞”公式。

您可以使用以下代碼來隱藏V列。

worksheet.set_column('V:V', None, None, {'hidden': True})

如果您需要隱藏單個列,則需要將其設置為“ V:V”

http://xlsxwriter.readthedocs.io/example_hide_row_col.html

如果我們在談論數字公式,我將復制然后“粘貼值”以刪除公式。 據我所知,Excel中沒有一種方法可以在不復制條件公式的情況下復制和粘貼格式。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM