Example #1
0
    public static void DownloadXLSX(string docId, Action <string> callback, string fileName = "tmpXLSX")
    {
        string url =
            "https://docs.google.com/spreadsheets/d/" + docId + "/export?format=xlsx";
        UnityWebRequest www = UnityWebRequest.Get(url);

        string savePath = string.Format("{0}/{1}.xlsx", GameConstant.ExcelSourceFolder, fileName);
        var    dh       = new DownloadHandlerFile(savePath);

        dh.removeFileOnAbort = true;
        www.downloadHandler  = dh;

        UnityWebRequestAsyncOperation asyncOperation = www.SendWebRequest();

        asyncOperation.completed += (async) =>
        {
            if (www.isNetworkError || www.isHttpError)
            {
                Debug.Log(www.error);
            }
            else
            {
                Debug.Log("Download success! File at:" + savePath);
                dh.Dispose();
                callback(savePath);
                www.Dispose();
            }
        };
    }