当前位置:网站首页>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");
}
边栏推荐
- [pointer] solve the last person left
- C language learning summary (I) (under update)
- To brush the video, it's better to see if you have mastered these interview questions. Slowly accumulating a monthly income of more than 10000 is not a dream.
- Global and Chinese market of pinhole glossmeter 2022-2028: Research Report on technology, participants, trends, market size and share
- The four connection methods of JDBC are directly coded
- What is an index in MySQL? What kinds of indexes are commonly used? Under what circumstances will the index fail?
- UCORE lab1 system software startup process experimental report
- 几款开源自动化测试框架优缺点对比你知道吗?
- Pedestrian re identification (Reid) - Overview
- [pointer] find the length of the string
猜你喜欢
In Oracle, start with connect by prior recursive query is used to query multi-level subordinate employees.
[HCIA continuous update] advanced features of routing
Investment operation steps
[200 opencv routines] 98 Statistical sorting filter
Dlib detects blink times based on video stream
Build your own application based on Google's open source tensorflow object detection API video object recognition system (I)
What is an index in MySQL? What kinds of indexes are commonly used? Under what circumstances will the index fail?
ucore lab6 调度器 实验报告
1. Payment system
Daily code 300 lines learning notes day 9
随机推荐
CSAPP Shell Lab 实验报告
[oiclass] maximum formula
Currently, mysql5.6 is used. Which version would you like to upgrade to?
Software testing interview summary - common interview questions
Zhejiang University Edition "C language programming experiment and exercise guide (3rd Edition)" topic set
ucore lab5用户进程管理 实验报告
几款开源自动化测试框架优缺点对比你知道吗?
JDBC 的四种连接方式 直接上代码
[200 opencv routines] 98 Statistical sorting filter
Leetcode simple question: check whether the numbers in the sentence are increasing
The minimum number of operations to convert strings in leetcode simple problem
[oiclass] share prizes
The minimum sum of the last four digits of the split digit of leetcode simple problem
STC-B学习板蜂鸣器播放音乐
How to transform functional testing into automated testing?
Keil5 MDK's formatting code tool and adding shortcuts
Fundamentals of digital circuits (I) number system and code system
My first blog
Iterators and generators
Fundamentals of digital circuits (II) logic algebra