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

posted on   荣锋亮  阅读(699)  评论(0编辑  收藏  举报

编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示