Exemple #1
0
        public static string GetExcelData(ExcelTable table, DataTable data)
        {
            var jv = new JsonValue();

            for (var i = 0; i < data.Rows.Count; i++)
            {
                var row = new JsonValue();
                var ig  = false;
                foreach (var col in table.Cols)
                {
                    var v = data.Rows[i][col.ColIndex];
                    if (col.Name == "ID")
                    {
                        if (v is DBNull || Convert.ToInt32(v) == 0)
                        {
                            ig = true;
                            break;
                        }
                    }

                    switch (col.Type)
                    {
                    case "Int":
                        var valInt = 0;
                        try
                        {
                            valInt = Convert.ToInt32(v);
                        }
                        catch { }
                        row[col.Name] = valInt;

                        break;

                    case "Float":
                        var valFloat = 0f;
                        try
                        {
                            valFloat = Convert.ToSingle(v);
                        }
                        catch { }
                        row[col.Name] = valFloat;
                        break;

                    case "String":
                        row[col.Name] = v == null ? "" : v.ToString();
                        break;

                    case "DateTime":
                        row[col.Name] = v == null ? "" : v.ToString();
                        break;
                    }
                }
                if (!ig)
                {
                    jv.Append(row);
                }
                //BREAK;
            }
            return(JsonWriter.Write(jv));
        }