Example #1
0
        private static void CreateData(XSheet srcSheet, ExcelWorksheet excelSheet)
        {
            for (var rowIndex = 0; rowIndex < srcSheet.Rows.Count; rowIndex++)
            {
                var row = srcSheet.Rows[rowIndex];

                for (var colIndex = 0; colIndex < row.Cells.Count; colIndex++)
                {
                    var sourceCell = row.Cells[colIndex];
                    var excelCell  = excelSheet.Cells[rowIndex + 1, colIndex + 1];

                    excelCell.Value = sourceCell.Value;

                    if (!string.IsNullOrWhiteSpace(sourceCell.NumberFormat))
                    {
                        if (decimal.TryParse(sourceCell.Value, out var decimalValue))
                        {
                            excelCell.Value = decimalValue;
                        }

                        excelCell.Style.Numberformat.Format = sourceCell.NumberFormat;
                    }
                }
            }
        }
Example #2
0
 /// <summary>
 /// Initializes the <see cref="XSheet"/> class.
 /// </summary>
 static XSheet()
 {
     Instance = new XSheet();
 }
Example #3
0
File: XRes.cs Project: oathx/myactx
    /// <summary>
    /// Dos the load async.
    /// </summary>
    /// <returns>The load async.</returns>
    /// <param name="path">Path.</param>
    /// <param name="type">Type.</param>
    /// <param name="callback">Callback.</param>
    private static IEnumerator  DoLoadAsync(string path, System.Type type, System.Action <Object> callback)
    {
        if (string.IsNullOrEmpty(path))
        {
            GLog.LogError("[XRes::Load] sent empty/null path!");
            yield break;
        }

        string name = path.ToLower();

        UnityEngine.Object obj = Find(name);
        if (!obj)
        {
            XSheet.XAssetInfo info = XSheet.Instance.Find(name);
            if (info != null)
            {
                switch (info.locationType)
                {
                case XSheet.XLocationType.Resource:
                    ResourceRequest request = null;
                    if (type == typeof(XBufferAsset))
                    {
                        request = Resources.LoadAsync <TextAsset>(name);
                        yield return(request);

                        XBufferAsset asset = ScriptableObject.CreateInstance <XBufferAsset>();
                        asset.init((TextAsset)request.asset);
                        obj = asset;
                    }
                    else
                    {
                        request = Resources.LoadAsync(name, type);
                        yield return(request);

                        obj = request.asset;
                    }
                    break;

                case XSheet.XLocationType.Bundle:
                    yield return(XBundleManager.Instance.LoadAssetAsync(info,
                                                                        type, delegate(Object result) { obj = result; }));

                    break;

                case XSheet.XLocationType.Data:
                    string fileUrl    = XSheet.GetLocalFileUrl(System.IO.Path.Combine(Application.persistentDataPath, info.fullName));
                    WWW    fileLoader = new WWW(fileUrl);
                    yield return(fileLoader);

                    if (!string.IsNullOrEmpty(fileLoader.error))
                    {
                        XBufferAsset asset = ScriptableObject.CreateInstance <XBufferAsset>();
                        asset.init(
                            fileLoader.bytes
                            );

                        if (type == typeof(Texture2D))
                        {
                            Texture2D texture = new Texture2D(1, 1);
                            texture.LoadImage(asset.bytes);

                            obj = texture;
                        }
                        else
                        {
                            obj = asset;
                        }
                    }
                    break;

                case XSheet.XLocationType.Streaming:
                    string streamUrl = XSheet.GetLocalFileUrl(System.IO.Path.Combine(Application.streamingAssetsPath, info.fullName));
                    if (Application.platform != RuntimePlatform.Android)
                    {
                        streamUrl = XSheet.GetLocalFileUrl(streamUrl);
                    }

                    WWW streamLoader = new WWW(streamUrl);
                    yield return(streamLoader);

                    if (!string.IsNullOrEmpty(streamLoader.error))
                    {
                        XBufferAsset asset = ScriptableObject.CreateInstance <XBufferAsset>();
                        asset.init(
                            streamLoader.bytes
                            );

                        if (type == typeof(Texture2D))
                        {
                            Texture2D texture = new Texture2D(1, 1);
                            texture.LoadImage(asset.bytes);
                            obj = texture;
                        }
                        else
                        {
                            obj = asset;
                        }
                    }
                    break;
                }
            }
            else
            {
                ResourceRequest request = Resources.LoadAsync(name, type);
                yield return(request);

                obj = request.asset;
            }

            if (!obj)
            {
                if (info != null)
                {
                    GLog.LogError("[XRes.Load] Can't find {0} in Location({1})", name, info.locationType);
                }
                else
                {
                    GLog.LogError("[XRes.Load] Can't find {0} in Resources", name);
                }
            }
        }

        callback(obj);
    }