截取右键弹出的菜单

  1. 使用系统自带的截图工具:‌对于Windows 10用户,‌可以使用系统自带的截图工具。‌首先启动截图工具,‌点击“延时”并选择好时间(‌例如5秒)‌。‌然后立即点击鼠标右键或点击其他菜单。‌等待5秒时间到了,‌界面会变得模糊,‌这时鼠标会变成十字形。‌将鼠标移动到右键菜单左上角,‌按住鼠标左键向右下角拖动,‌直接选中整个菜单。‌选好菜单后松开手,‌右键菜单图片就会自动显示在截图工具上。‌最后按“Ctrl + S”保存好图片。‌

  2. 使用专门的截图工具

以下是使用VSTO开发EXCEL插件的代码,实现包含的功能步骤: ```csharp using System; using System.Linq; using Excel = Microsoft.Office.Interop.Excel; using Office = Microsoft.Office.Core; namespace ExcelAddIn1 { public partial class ThisAddIn { private void ThisAddIn_Startup(object sender, System.EventArgs e) { // 在启动时注册右键菜单项 this.Application.SheetBeforeRightClick += Application_SheetBeforeRightClick; } private void ThisAddIn_Shutdown(object sender, System.EventArgs e) { // 在关闭时取消注册右键菜单项 this.Application.SheetBeforeRightClick -= Application_SheetBeforeRightClick; } private void Application_SheetBeforeRightClick(object Sh, Excel.Range Target, ref bool Cancel) { // 右键菜单项:去除文本中所有的空格 Excel.Range selection = this.Application.Selection; if (selection.Columns.Count == 1 && selection.Rows.Count >= 1 && selection.Cells[1].Value is string) { Excel.Range textColumn = selection.EntireColumn; textColumn.Replace(" ", ""); } } public void AddNewSheet() { // 弹出对话框提示用户输入2个文本 string part = Microsoft.VisualBasic.Interaction.InputBox("请输入Part Code的前2位字母(限制2个字母):", "输入框1", ""); string serial = Microsoft.VisualBasic.Interaction.InputBox("请输入花纹块的循环排序规律(限制长度小于9的数字):", "输入框2", ""); // 从步骤a获得文本中截取2段文本 Excel.Range selection = this.Application.Selection; if (selection.Columns.Count == 1 && selection.Rows.Count >= 1 && selection.Cells[1].Value is string) { string originalText = selection.Cells[1].Value; int startIndex = originalText.IndexOf("01"); int endIndex = originalText.Length; for (int i = 1; i <= 9; i++) { int index = originalText.IndexOf(i.ToString()); if (index >= startIndex && index < endIndex) { endIndex = index; } } string firstText = originalText.Substring(startIndex + 2, endIndex - startIndex - 2); string secondText = originalText.Substring(endIndex); // 生成新sheet页 Excel.Workbook workbook = this.Application.ActiveWorkbook; Excel.Worksheet newSheet = workbook.Sheets.Add(); newSheet.Name = part + " " + serial; // 将2段文本粘贴到新sheet页的2列中 string[] firstArray = Enumerable.Repeat(firstText, 9).ToArray(); char[] serialArray = serial.ToCharArray(); Array.Sort(serialArray); string sortedSerial = new string(serialArray); string[] secondArray = Enumerable.Range(0, secondText.Length) .OrderBy(i => sortedSerial.IndexOf(serial[i % serial.Length])) .Select(i => secondText[i].ToString()) .ToArray(); newSheet.Range["A1"].Resize[firstArray.Length, 1].Value = firstArray; newSheet.Range["B1"].Resize[secondArray.Length, 1].Value = secondArray; } } } } ``` 此代码中,`AddNewSheet` 方法实现了要求的步骤b、c、d。可以在VSTO插件的任意位置调用该方法,例如在一个按钮的点击事件中调用。注意,要将此代码添加到插件的代码文件中,并在启动和关闭事件中注册和取消注册右键菜单项。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值