当前位置:网站首页>A method and implementation of using VSTO to prohibit excel cell editing
A method and implementation of using VSTO to prohibit excel cell editing
2022-07-06 15:09:00 【Nonsense】
Ideas
- Whenever the protected cell is selected , Make it unselected
- The protected cell cannot get the focus , That is, you cannot edit
Realization
- Implement logic that cannot be selected
/** * When protected range By selected When , mandatory select To a certain goal range * protectedSheet The protected sheet * currentSheet Current sheet * protectedRanges The protected range list * currentRange At present select Of range * destinationRange The goal is range, Be preposed select Of range */
public static void ForceSelect(string protectedSheet, Excel.Worksheet currentSheet,
List<string> protectedRanges, string currentRange, string destinationRange)
{
if (currentSheet.Name.Equals(protectedSheet) && protectedRanges.Contains(currentRange))
{
currentSheet.Range[destinationRange].Select();
}
}
- register “SheetSelectionChange” event
/** * Registration events : Implementation cells are not editable */
public void RegisterSheetSelectionChange()
{
ExcelApp.SheetSelectionChange += ExcelApp_SheetSelectionChange;
}
private void ExcelApp_SheetSelectionChange(object Sh, Excel.Range Target)
{
Excel.Worksheet sheet = (Excel.Worksheet)Target.Parent;
string address = Target.Address.Replace("$", "");
List<string> protectedRanges = new List<string>();
protectedRanges.Add("B1");
protectedRanges.Add("B2");
WorksheetHandler.ForceSelect("sheetName", sheet, protectedRanges, address, "A1");
}
边栏推荐
- Sorting odd and even subscripts respectively for leetcode simple problem
- In Oracle, start with connect by prior recursive query is used to query multi-level subordinate employees.
- Login the system in the background, connect the database with JDBC, and do small case exercises
- 1. Payment system
- JDBC 的四种连接方式 直接上代码
- Thinking about three cups of tea
- [issue 18] share a Netease go experience
- [oiclass] share prizes
- What level do 18K test engineers want? Take a look at the interview experience of a 26 year old test engineer
- 转行软件测试必需要知道的知识
猜你喜欢

Leetcode simple question: check whether the numbers in the sentence are increasing

C language do while loop classic Level 2 questions
转行软件测试必需要知道的知识

全网最详细的postman接口测试教程,一篇文章满足你

Nest and merge new videos, and preset new video titles
![Cadence physical library lef file syntax learning [continuous update]](/img/0b/75a4ac2649508857468d9b37703a27.jpg)
Cadence physical library lef file syntax learning [continuous update]

基于485总线的评分系统双机实验报告

Cc36 different subsequences
软件测试面试要问的性能测试术语你知道吗?

HackTheBox-Emdee five for life
随机推荐
Video scrolling subtitle addition, easy to make with this technique
转行软件测试必需要知道的知识
Function: calculates the number of uppercase letters in a string
ucore lab1 系统软件启动过程 实验报告
Detailed introduction to dynamic programming (with examples)
JDBC 的四种连接方式 直接上代码
Face and eye recognition based on OpenCV's own model
Emqtt distribution cluster and node bridge construction
Login the system in the background, connect the database with JDBC, and do small case exercises
Database monitoring SQL execution
Opencv recognition of face in image
Using flask_ Whooshalchemyplus Jieba realizes global search of flask
Function: find 1-1/2+1/3-1/4+1/5-1/6+1/7-... +1/n
UCORE lab7 synchronous mutual exclusion experiment report
Daily code 300 lines learning notes day 9
Oracle foundation and system table
UCORE lab1 system software startup process experimental report
Leetcode simple question: check whether the numbers in the sentence are increasing
Express
CSAPP Shell Lab 实验报告