runliuv

runliuv@cnblogs

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
string path = openFileDialog1.FileName;
                try
                {
                    DataTable dt = ExcelHelper.ExcelInput(path);

                    int appidIndex = -1;
                    int shopidIndex = -1;
                    int storeidIndex = -1;


                    for (int i = 0; i < dt.Columns.Count; i++)
                    {
                        string colNmaeL = dt.Columns[i].ColumnName.ToLower();
                        if (colNmaeL.Contains("app") && colNmaeL.Contains("id"))
                            appidIndex = i;

                        if (colNmaeL.Contains("shop") && colNmaeL.Contains("id"))
                            shopidIndex = i;

                        if (colNmaeL.Contains("store") && colNmaeL.Contains("id"))
                            storeidIndex = i;
                    }

                    List<SHOPID> lstShopids = new List<SHOPID>();

                    string firstAppId = string.Empty;
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        DataRow dr = dt.Rows[i];
                        SHOPID si = new SHOPID();
                        if(dr[appidIndex]!=null&&!string.IsNullOrEmpty(dr[appidIndex].ToString()))
                            firstAppId = dr[appidIndex].ToString();
                        si.appid = firstAppId;

                        si.storeid = dr[storeidIndex].ToString();
                        si.shopid = dr[shopidIndex].ToString();

                        lstShopids.Add(si);
                    }

                    dataGridView1.DataSource = lstShopids;

                    MessageBox.Show("abc");
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }

-

posted on 2016-11-03 20:04  runliuv  阅读(302)  评论(0编辑  收藏  举报