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. 测试结果页面:

  • 相关阅读:
    为什么全局变量一定要初始化?
    SecureCRT 使用密钥登录 Ubuntu
    ubuntu samba 服务器搭建
    Linux 软硬链接的区别及目录权限对软硬链接的影响
    【转载】解析 java 按值传递还是按引用传递
    (转)如何学好C语言
    (转)五个方法成为更好的程序员
    (转)SQLite数据库的加密
    鸟哥Linux私房菜(基础篇)——第十一章:认识与学习Bash
    鸟哥Linux私房菜(基础篇)——第五章:首次登入与在线求助 man page笔记
  • 原文地址:https://www.cnblogs.com/rongfengliang/p/3741190.html
Copyright © 2011-2022 走看看