zoukankan      html  css  js  c++  java
  • c#dev操作读取excel方法

    一:使用spreadsheetControl1 方法

    1:打开excel;

      private void barButtonItem1_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
            {
                //if (Convert.ToInt32(trv_menu.SelectedNode.Tag) == 0)
                //{
                //    MessageBox.Show("请先选择业务", "提示信息", MessageBoxButtons.OK);
                //    return;
                //}
                OpenFileDialog openFileDialog1 = new OpenFileDialog();
                openFileDialog1.Filter = "(*.xls)|*.xls|(*.xlsx)|*.xlsx|(*.csv)|*.csv";
                openFileDialog1.RestoreDirectory = true;
                if (openFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    spreadsheetControl1.LoadDocument(openFileDialog1.FileName);
                }
                spreadsheetControl1.ReadOnly = true;
            }

    2:读取按行读取excel 处理每行中列的数值

     private void barButtonItem2_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
            {
             
              //    status1.Visible = true;
                //读取Excele方法  
                //当前数据行数  
                int rowCount = spreadsheetControl1.ActiveWorksheet.Cells.CurrentRegion.RowCount;
                //当前数据列数  
                int columnCount = spreadsheetControl1.ActiveWorksheet.Cells.CurrentRegion.ColumnCount;
                if (rowCount == 1 && columnCount == 1)
                {
                    MessageBox.Show("内容不能为空", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                for (int i = 0; i < rowCount; i++)
                {
                    string sr = spreadsheetControl1.ActiveWorksheet.Cells[i, 0].Value.ToString();
                    if (sr == "")
                    {
                        //  blankcount++;
                        blankcountEvent(this, e);
                   //     btnblank.Text = blankcount.ToString(); ;
                        continue;
                    }
                    //for (int j = 0; j < columnCount; j++)
                    //{
                    string zyzsId = spreadsheetControl1.ActiveWorksheet.Cells[i, 0].Value.ToString();  //这里取的是指定列的值. 第一列,第六列和第七列 然后做上传
                    string parentId = spreadsheetControl1.ActiveWorksheet.Cells[i, 5].Value.ToString();
                    string parentName = spreadsheetControl1.ActiveWorksheet.Cells[i, 6].Value.ToString();
                    string ip= "192.168.1.115";
                    //}
                    string url = "xxxxxxxxxx" + parentName;
                    string data =""/;
                    string result = HttpPost(url, data);
                     if(result=="ok")
                    {
                      //  successcount++;
                        successcountEvent(this, e);
                 //       btnupsuccount.Text= successcount.ToString();
                    }
                    else if(result == "fail")
                    {
                        //    failedcount++;
                        failedcountEvent(this, e);
               //         btnfailedcount.Text = failedcount.ToString();
                    }
    
                }
            }

    总结:由于数据倒入到spreadsheetControl1  显示在窗体中没有实际操作,占用了资源.在上传时有卡顿现象,卡顿也有其他原因.总之这种是现实方式方式不值得推荐.

    二:文件文件名加载到gridcontrol中 ,显示进度的方式

  • 相关阅读:
    人工智能,人工神经网络,机器学习,深度学习,卷积神经网络 时间线与内在联系(转载)
    基于spark logicplan的表血缘关系解析实现
    spark ml pipeline构建机器学习任务
    常用特征离散化方法
    spark sql插入表时的文件个数研究
    Spark累加器(Accumulator)
    java中使用URLClassLoader访问外部jar包的java类
    Scala里面的排序函数的使用
    Spark获取DataFrame中列的几种姿势--col,$,column,apply
    spark.sql.shuffle.partitions和spark.default.parallelism的区别
  • 原文地址:https://www.cnblogs.com/zuochanzi/p/7560140.html
Copyright © 2011-2022 走看看