在C#中的Excel VSTO选择性粘贴 [英] Paste Special in C# vsto Excel

查看:647
本文介绍了在C#中的Excel VSTO选择性粘贴的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在C#VSTO Excel应用程序的工作。



每当用户糊状的东西从其他Excel模板Excel工作表,也粘贴单元格的格式与细胞一起在Excel模板中的数据。我想避免这种情况。
所以我用Google搜索&放大器;我碰到长期粘贴特殊。



选择性粘贴仅粘贴内容,不会改变当前工作表的格式。



我要介绍的粘贴在我的VSTO应用特殊选项。



我在这里有代码

  Application.OnKey(^ v,PasteSpecV); 



但其不工作...
任何一个可以帮助我?


解决方案

  1. 下载DLL从 http://globalmousekeyhook.codeplex.com/

  2. 添加引用MouseKeyboardActivityMonitor.dll

     私人KeyboardHookListener k_keyListener; 

    私人无效ThisWorkbook_Startup(对象发件人,发送System.EventArgs)
    {
    k_keyListener =新KeyboardHookListener(新AppHooker());
    k_keyListener.Enabled = TRUE;
    k_keyListener.KeyDown + =新KeyEventHandler(k_keyListener_KeyDown);
    }

    无效k_keyListener_KeyDown(对象发件人,发送KeyEventArgs E)
    {
    如果(Control.ModifierKeys == Keys.Control)如果
    (即邀请码== Keys.V)
    {
    表actSht = ActiveSheet为表;
    范围RNG = actSht.Application.Selection的范围;
    如果(MessageBox.Show(您只粘贴值。你要继续吗?,粘贴确认,MessageBoxButtons.YesNo,MessageBoxIcon.Question)== DialogResult.Yes)
    {
    rng.PasteSpecial(XlPasteType.xlPasteValues,XlPasteSpecialOperation.xlPasteSpecialOperationNone,假的,假的);
    }
    e.Handled = TRUE;
    }
    }



I am working on the C# vsto Excel application.

Whenever user pastes something in the excel template from another excel sheet,it also pastes Cell format along with the cell data in the excel template. I want to avoid this. So i googled & i came across term paste special.

Paste special will only paste the contents and will no alter the format of the current sheet.

I want to introduce paste special option in my vsto application.

I have code here,

   Application.OnKey("^v", "PasteSpecV");

but its not working... can any one help me with this ?

解决方案

  1. Download dll From http://globalmousekeyhook.codeplex.com/
  2. Add Reference MouseKeyboardActivityMonitor.dll

        private KeyboardHookListener k_keyListener;
    
        private void ThisWorkbook_Startup(object sender, System.EventArgs e)
        {
            k_keyListener = new KeyboardHookListener(new AppHooker());
            k_keyListener.Enabled = true;
            k_keyListener.KeyDown += new KeyEventHandler(k_keyListener_KeyDown);
        }
    
        void k_keyListener_KeyDown(object sender, KeyEventArgs e)
        {
            if (Control.ModifierKeys == Keys.Control)
                if (e.KeyCode == Keys.V)
                {
                    Worksheet actSht = ActiveSheet as Worksheet;
                    Range rng = actSht.Application.Selection as Range;
                    if (MessageBox.Show("You are about to paste values only. Do you want to continue?", "Paste Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        rng.PasteSpecial(XlPasteType.xlPasteValues, XlPasteSpecialOperation.xlPasteSpecialOperationNone, false, false);
                    }
                    e.Handled = true;
                }
        }
    

这篇关于在C#中的Excel VSTO选择性粘贴的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆