機能が足りない場合¶
xlwingsの機能が足りない場合には以下を行ってください:
Most importantly, open an issue on GitHub. Adding functionality should be user driven, so only if you tell us about what you're missing, it's eventually going to find its way into the library. By the way, we also appreciate pull requests!
Workaround: in essence, xlwings is just a smart wrapper around pywin32 on Windows and appscript on Mac. You can access the underlying objects by calling the
apiproperty:>>> sheet = xw.Book().sheets[0] >>> sheet.api # Windows (pywin32) <win32com.gen_py.Microsoft Excel 16.0 Object Library._Worksheet instance at 0x2260624985352> # macOS (appscript) app(pid=2319).workbooks['Workbook1'].worksheets[1]
This works accordingly for the other objects like
sheet.range('A1').apietc.元になっているオブジェクトのpywin32 (VBAとほぼ同じAPI) およびappscript (VBAとは違うAPI)を使えば、VBAで使えるほとんどすべての機能が利用できます。
apiを使う場合には、見た目が悪くなること意外に、 コードがプラットフォーム依存になってしまう (!) ことに注意してください。したがって、2.の代替手段を採る場合でも、 1.にあるようにissueをオープンし機能がライブラリー(クロスプラットフォームかつパイソニックなシンタックス)に取り込まれるようにしてください。
Example: Workaround to use VBA's Range.WrapText¶
# Windows
sheet['A1'].api.WrapText = True
# Mac
sheet['A1'].api.wrap_text.set(True)