コード例 #1
0
        /// <summary>
        /// 登录页面取公司(erp系统)列表
        /// </summary>
        public void GetCompany()
        {
            string          jsonstr   = "";
            List <MDataRow> RowList   = new List <MDataRow>();
            int             cmpLength = Convert.ToInt32(ConfigurationManager.AppSettings["cmpLength"]);

            for (int i = 1; i <= cmpLength; i++)
            {
                MDataRow MRow = new MDataRow();
                MRow.Add("value", ConfigurationManager.AppSettings.Keys[i].ToString().ToLower());
                MRow.Add("text", ConfigurationManager.AppSettings[i].ToString().ToLower());
                jsonstr += MRow.ToJson() + ",";
            }
            jsonstr    = "[" + jsonstr.Substring(0, jsonstr.Length - 1).Replace("[", "\"[").Replace("]", "]\"") + "]";
            jsonResult = jsonstr;
        }
コード例 #2
0
ファイル: ToDataTable.cs プロジェクト: swhhcf/DYLeader_1
        /// <summary>
        /// 从工作表中获取数据,转成DataTable
        /// </summary>
        /// <param name="sheet"></param>
        /// <param name="errorMsgList"></param>
        /// <param name="colNames"></param>
        /// <returns></returns>
        public static MDataTable GetFrom(ISheet sheet, out List <string> errorMsgList, string[] colNames = null)
        {
            errorMsgList = new List <string>();
            var dataTable = new MDataTable();
            int rowCount  = sheet.LastRowNum;

            if (rowCount <= 0)
            {
                errorMsgList.Add("没有数据,请检查");
                return(null);
            }
            var shtColName = sheet.GetRow(0);
            int colCount   = 0;

            while (shtColName.GetCell(colCount) != null && shtColName.GetCell(colCount).StringCellValue != "")
            {
                colCount++;
            }
            for (int i = 0; i < colCount; i++)
            {
                dataTable.Columns.Add(i.ToString());
            }
            for (int i = 1; i < rowCount + 1; i++)
            {
                var shtRow  = sheet.GetRow(i);
                var dataRow = new MDataRow(); // new object[rowCount];
                for (var j = 0; j < colCount; j++)
                {
                    var value = GetCellValue(shtRow.GetCell(j));
                    if (value == null)
                    {
                        errorMsgList.Add($"第 {i + 1} 行 第{j + 1}列 为公式,请修改。");
                    }
                    dataRow.Add(j.ToString(), value);
                    //dataRow[j] = shtRow.GetCell(j);
                }
                dataTable.Rows.Add(dataRow.GetItemValues());
            }
            SetDataTableColName(dataTable, shtColName, colNames, colCount);
            return(dataTable);
        }