zoukankan      html  css  js  c++  java
  • vsto excel 任务窗体操作

    1. 开发环境visual studio 2010

    2. office 2007

    代码:

    1.任务窗体

    代码:

     partial class ActionsPaneControl1 : UserControl
        {
            System.Data.DataTable dt = new System.Data.DataTable();
            System.Data.DataTable dm = new System.Data.DataTable();
            ufsea.SEAOrganizationService service = new ufsea.SEAOrganizationService();
            public ActionsPaneControl1()
            {
                InitializeComponent();
            }

            private void button1_Click(object sender, EventArgs e)
            {
                dataGridView1.AutoGenerateColumns = false;
                dt = CusdbCommon.XMLHelper.XmlDeserializeUnicode(service.GetCorporationListOfGuFen());
                dataGridView1.DataSource = dt;

            }

            private void button3_Click(object sender, EventArgs e)
            {
                Worksheet workbook = (Worksheet)Globals.ThisWorkbook.Worksheets[1];
                DataGridViewSelectedRowCollection selectlist = dataGridView1.SelectedRows;
                int counts = selectlist.Count;
                List<OrgInfo> list = new List<OrgInfo>();
            
                foreach (DataGridViewRow item in selectlist)
                {
                  
                    OrgInfo data = new OrgInfo();
                    data.name = item.Cells[1].Value.ToString();
                    data.area= item.Cells[2].Value.ToString();
                    data.code = item.Cells[3].Value.ToString();
                    list.Add(data);
                 
                }
                Globals.Sheet1.list1.DataSource = list;
            }

            private void button4_Click(object sender, EventArgs e)
            {
                Worksheet workbook = (Worksheet)Globals.ThisWorkbook.Worksheets[1];
                DataGridViewSelectedRowCollection selectlist = dataGridView1.SelectedRows;
                int counts = selectlist.Count;
                int index = 4;
                foreach (DataGridViewRow item in selectlist)
                {
                 
                        Range myRange = (Microsoft.Office.Interop.Excel.Range)workbook.Cells[index, 3];
                        myRange.Value = item.Cells[1].Value.ToString();
                        Range myRange1 = (Microsoft.Office.Interop.Excel.Range)workbook.Cells[index, 4];
                        myRange1.Value = item.Cells[2].Value.ToString();
                        Range myRange2 = (Microsoft.Office.Interop.Excel.Range)workbook.Cells[index, 5];
                        myRange2.Value = item.Cells[3].Value.ToString();
                        index++;

                  
                }
               
            }
        }

    2. excel 页面控件

    3. 测试结果页面:

  • 相关阅读:
    正则表达式
    DNS协议相关命令 dig
    Linux下 redsocks + iptables + socks5 实现全局代理
    Kotlin native 初心
    Kotlin 初心
    XMLHttpRequest2 实现AJAX跨域请求
    CSS、JavaScript 初心
    jQuery 初心
    java.lang.ClassNotFoundException 解决方案
    CPU 负荷过重时邮件报警
  • 原文地址:https://www.cnblogs.com/rongfengliang/p/3741190.html
Copyright © 2011-2022 走看看