現在我只能讓細胞秀這樣enter image description here我如何使用Python與openpyxl旋轉90度的單元格?
,但我希望它這樣 enter image description here
如何與openpyxl辦呢?我已經搜索了很長時間,但我找不到它..
現在我只能讓細胞秀這樣enter image description here我如何使用Python與openpyxl旋轉90度的單元格?
,但我希望它這樣 enter image description here
如何與openpyxl辦呢?我已經搜索了很長時間,但我找不到它..
您需要配置特定單元格的alignment
屬性。你正在尋找的參數是textRotation
(這在你的情況下是180)。請看下面的例子:
from openpyxl import Workbook
from openpyxl.styles import Alignment
wb = Workbook()
ws1 = wb.active
ws1['A1'] = 'SPAMEGGS'
ws1['A1'].alignment = Alignment(textRotation=180)
wb.save(filename='path/to/the/file')
你可以閱讀有關這和其他選項here。
我試過這個,但沒有任何改變... –
@PaulChang:那是不可能的。你做錯了什麼。關閉excel/calc,運行代碼,再次打開並查看結果。確保你給出了正確的路徑,最好用'os.path.expanduser(r'my_path')'。 [Here](http://i.imgur.com/xXsymTU.png)是我的機器上的外觀。 – mentalita
非常感謝。 –
請提供您正在使用的代碼。 –