OneDriveおよびSharePoint¶
Since v0.27.4, xlwings works with locally synced files on OneDrive, OneDrive for Business, and SharePoint. Some constellations will work out-of-the-box, while others require you to edit the configuration via the xlwings.conf file (see User Config) or the workbook's xlwings.conf sheet (see Workbook Config).
注釈
This documentation is for OneDrive and SharePoint files that are synced to a local folder. This means that both, the Excel and Python file, need to show the green check mark in the File Explorer/Finder as status---a cloud icon will not work. If, in turn, you are looking for the documentation to run xlwings with Excel on the web, see xlwings Server.
問題が発生した場合の簡単な回避策は以下:
Disable the
ADD_WORKBOOK_TO_PYTHONPATHsetting (either via the checkbox on the Ribbon or via the settings in thexlwings.confsheet).Add the directory of your Python source file to the
PYTHONPATH---again, either via Ribbon orxlwings.confsheet.
PROバージョンであれば、これらの問題を回避するために、代わりにコードを埋め込むことも可能です。
もう少し柔軟性を持たせたい場合は、以下の解決策に従ってください。
OneDrive(個人用)¶
WindowsとmacOSでは、デフォルトの設定がそのまま機能します。エラーメッセージが表示された場合は、OneDriveのローカル ルート ディレクトリへの正しいパスを指定して、次の設定を追加してください。可能であれば、 (例に示すように)環境変数を使用して、設定が同じの異なるユーザー間で設定が機能するようにします:
Windows (Example):
|
ONEDRIVE_CONSUMER_WIN|%USERPROFILE%\OneDrive|macOS (Example):
|
ONEDRIVE_CONSUMER_MAC|$HOME/OneDrive|
OneDrive for Business¶
Windows: デフォルトの設定で動作します。エラーメッセージが表示された場合は、OneDrive for Businessのローカル ルート ディレクトリへの正しいパスを指定して、次の設定を追加してください。可能であれば、 (例に示すように)環境変数を使用して、設定が同じの異なるユーザー間で設定が機能するようにします:
|
ONEDRIVE_COMMERCIAL_WIN|%USERPROFILE%\OneDrive - My Company LLC|macOS: macOSでは 常に 、OneDrive for Businessのローカル ルート ディレクトリへの正しいパスを指定して、次の設定を追加してください。可能であれば、 (例に示すように)環境変数を使用して、設定が同じの異なるユーザー間で設定が機能するようにします:
|
ONEDRIVE_COMMERCIAL_MAC|$HOME/OneDrive - My Company LLC|
SharePoint(オンラインおよびオンプレミス)¶
Windowsでは、 ときどき SharePointのローカル ルート フォルダの位置を、OneDriveの環境変数から取得できます。しかし、ほとんどの場合は以下の設定を行う必要があります(macOSでは必須です):
Windows:
|
SHAREPOINT_WIN|%USERPROFILE%\My Company LLC|macOS:
|
SHAREPOINT_MAC|$HOME/My Company LLC|
実装の詳細と制限事項¶
A lot of the xlwings functionality depends on the workbook's FullName property (via VBA/COM) that returns the local path of the file unless it is saved on OneDrive, OneDrive for Business or SharePoint with AutoSave enabled. In this case, it returns a URL instead.
OneDriveとOneDrive for BusinessのURLは、対応するローカル ファイルにかなり簡単に変換できます。ただし、ローカル ドライブのルート ディレクトリを知る必要がありますが、Windowsでは、通常、OneDriveの環境変数から取得できます。macOSではこれらが存在しないため、OneDriveのルート ディレクトリを取得する必要があります。Windowsでは、SharePointのルートディレクトリも環境変数から得られることがありますが、保証されているわけではありません。macOSの場合は、常に取得する必要があります。
SharePoint, unfortunately, allows you to map the drives locally in any way you want and there's no way to reliably get the local path for these files. On Windows, xlwings first checks the registry for the mapping. If this doesn't work, xlwings checks if the local path is mapped by using the defaults and if the file can't be found, it checks all existing local files on SharePoint. If it finds one with the same name, it'll use this. If, however, it finds more than one with the same name, you will get an error message. In this case, you can either rename the file to something unique across all the locally synced SharePoint files or you can change the SHAREPOINT_WIN/MAC setting to not stop at the root folder but include additional folders. As an example, assume you have the following file structure on your local SharePoint:
My Company LLC/
└── sitename1/
└── myfile.xlsx
└── sitename2 - Documents/
└── myfile.xlsx
In this case, you could either rename one of the files, or you could add a path that goes beyond the root folder (preferably under the xlwings.conf sheet):
| SHAREPOINT_WIN | %USERPROFILE%/My Company LLC/sitename2 - Documents |