当前位置:网站首页>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");
}
边栏推荐
- Differences between select, poll and epoll in i/o multiplexing
- Expanded polystyrene (EPS) global and Chinese markets 2022-2028: technology, participants, trends, market size and share Research Report
- Report on the double computer experiment of scoring system based on 485 bus
- Mysql的事务
- Iterators and generators
- [pointer] find the length of the string
- What are the business processes and differences of the three basic business modes of Vos: direct dial, callback and semi direct dial?
- Statistics 8th Edition Jia Junping Chapter 1 after class exercises and answers summary
- How to solve the poor sound quality of Vos?
- The number of reversing twice in leetcode simple question
猜你喜欢
The common methods of servlet context, session and request objects and the scope of storing data in servlet.
软件测试行业的未来趋势及规划
Opencv recognition of face in image
China's county life record: go upstairs to the Internet, go downstairs' code the Great Wall '
How to learn automated testing in 2022? This article tells you
The minimum number of operations to convert strings in leetcode simple problem
Leetcode simple question: check whether two strings are almost equal
UCORE lab1 system software startup process experimental report
STC-B学习板蜂鸣器播放音乐
Wang Shuang's detailed learning notes of assembly language II: registers
随机推荐
C language learning summary (I) (under update)
The salary of testers is polarized. How to become an automated test with a monthly salary of 20K?
Global and Chinese markets for GaN on diamond semiconductor substrates 2022-2028: Research Report on technology, participants, trends, market size and share
MySQL development - advanced query - take a good look at how it suits you
[pointer] solve the last person left
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.
Practical cases, hand-in-hand teaching you to build e-commerce user portraits | with code
Using flask_ Whooshalchemyplus Jieba realizes global search of flask
Expanded polystyrene (EPS) global and Chinese markets 2022-2028: technology, participants, trends, market size and share Research Report
Opencv recognition of face in image
The minimum number of operations to convert strings in leetcode simple problem
Pointer -- eliminate all numbers in the string
Database monitoring SQL execution
[issue 18] share a Netease go experience
安全测试入门介绍
Function: find 1-1/2+1/3-1/4+1/5-1/6+1/7-... +1/n
"If life is just like the first sight" -- risc-v
自动化测试中敏捷测试怎么做?
遇到程序员不修改bug时怎么办?我教你
Face and eye recognition based on OpenCV's own model