乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      MyXls 導(dǎo)入EXECL到listview

       悟靜 2012-05-12
      myxls很好用,最近做項(xiàng)目發(fā)現(xiàn)myxls導(dǎo)出EXCLE的解釋很多而如何將excel導(dǎo)入到winform中dataview或者listview中的介紹很少,研究了2天。寫點(diǎn)代碼給大家分享下


       private void button1_Click(object sender, EventArgs e)
              {
                  System.Windows.Forms.OpenFileDialog ofd = new OpenFileDialog();
                  if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                  {
                      textBoxReadFile.Text = ofd.FileName;
                      button1_Click(null, null);
                  }
              }

          private void button2_Click(object sender, EventArgs e)
              {


                  string fileName = textBoxReadFile.Text;
                  if (!File.Exists(fileName))
                  {
                      MessageBox.Show(string.Format("{0} not found!", fileName));
                      return;
                  }
             
           XlsDocument xls = new XlsDocument(@fileName);//打開EXCLE
                
               
                  //獲得Excel中的指定一個工作頁
                
                  Worksheet sheet = xls.Workbook.Worksheets[0];
                  //讀取數(shù)據(jù) 循環(huán)每sheet工作頁的第5行開始
               
          
                  for (int i = 5; i < sheet.Rows.Count; i++)
                  {
                     


                             //讀取第一行第一列
                            zid = Convert.ToString(sheet.Rows[ushort.Parse(i.ToString())].GetCell(1).Value); 
                  
                    
                                 ListViewItem lv1 = new ListViewItem(zid);
          //    第一行第5列
                                 j = Convert.ToString(sheet.Rows[ushort.Parse(i.ToString())].GetCell(5).Value);
                            lv1.SubItems.Add(j);
                      
                            listview1.Items.Add(lv1);

                          
                      
                     

                    
                  
                  }
              }

             

          

          }
      標(biāo)簽: MyXLS

      代碼片段(1)

      [代碼] [C#]代碼

      01 private void button1_Click(object sender, EventArgs e)
      02        {
      03            System.Windows.Forms.OpenFileDialog ofd = new OpenFileDialog();
      04            if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
      05            {
      06                textBoxReadFile.Text = ofd.FileName;
      07                button1_Click(null, null);
      08            }
      09        }
      10  
      11    private void button2_Click(object sender, EventArgs e)
      12        {
      13  
      14  
      15            string fileName = textBoxReadFile.Text;
      16            if (!File.Exists(fileName))
      17            {
      18                MessageBox.Show(string.Format("{0} not found!", fileName));
      19                return;
      20            }
      21         
      22     XlsDocument xls = new XlsDocument(@fileName);//打開EXCLE
      23            
      24           
      25            //獲得Excel中的指定一個工作頁
      26            
      27            Worksheet sheet = xls.Workbook.Worksheets[0];
      28            //讀取數(shù)據(jù) 循環(huán)每sheet工作頁的第5行開始
      29           
      30      
      31            for (int i = 5; i < sheet.Rows.Count; i++)
      32            {
      33                 
      34  
      35  
      36                       //讀取第一行第一列
      37                      zid = Convert.ToString(sheet.Rows[ushort.Parse(i.ToString())].GetCell(1).Value); 
      38              
      39                
      40                           ListViewItem lv1 = new ListViewItem(zid);
      41    //    第一行第5列
      42                           j = Convert.ToString(sheet.Rows[ushort.Parse(i.ToString())].GetCell(5).Value);
      43                      lv1.SubItems.Add(j);
      44                  
      45                      listview1.Items.Add(lv1);
      46  
      47                      
      48                  
      49                 
      50  
      51                
      52              
      53            }
      54        }
      55  
      56         
      57  
      58      
      59  
      60    }

        本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊一鍵舉報(bào)。
        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評論

        發(fā)表

        請遵守用戶 評論公約

        類似文章 更多