当前位置:网站首页>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");
}
边栏推荐
- Should wildcard import be avoided- Should wildcard import be avoided?
- Public key box
- ByteDance ten years of experience, old bird, took more than half a year to sort out the software test interview questions
- STC-B学习板蜂鸣器播放音乐2.0
- HackTheBox-Emdee five for life
- ucore lab8 文件系统 实验报告
- What are the business processes and differences of the three basic business modes of Vos: direct dial, callback and semi direct dial?
- Login the system in the background, connect the database with JDBC, and do small case exercises
- Oracle foundation and system table
- 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.
猜你喜欢
Transplant hummingbird e203 core to Da Vinci pro35t [Jichuang xinlai risc-v Cup] (I)
About the garbled code problem of superstar script
Fundamentals of digital circuits (I) number system and code system
MySQL数据库(四)事务和函数
STC-B学习板蜂鸣器播放音乐
Stc-b learning board buzzer plays music
“Hello IC World”
接口测试面试题及参考答案,轻松拿捏面试官
Rearrange spaces between words in leetcode simple questions
Four methods of exchanging the values of a and B
随机推荐
软件测试面试回答技巧
Thinking about three cups of tea
How to transform functional testing into automated testing?
Common Oracle commands
“Hello IC World”
Leetcode simple question: check whether two strings are almost equal
Global and Chinese market of goat milk powder 2022-2028: Research Report on technology, participants, trends, market size and share
UCORE lab7 synchronous mutual exclusion experiment report
ucore lab2 物理内存管理 实验报告
王爽汇编语言学习详细笔记一:基础知识
With 27K successful entry ByteDance, this "software testing interview notes" has benefited me for life
Description of Vos storage space, bandwidth occupation and PPS requirements
自动化测试中敏捷测试怎么做?
Fundamentals of digital circuits (II) logic algebra
软件测试工作太忙没时间学习怎么办?
Face and eye recognition based on OpenCV's own model
Report on the double computer experiment of scoring system based on 485 bus
Statistics 8th Edition Jia Junping Chapter 2 after class exercises and answer summary
[pointer] the array is stored in reverse order and output
[Ogg III] daily operation and maintenance: clean up archive logs, register Ogg process services, and regularly back up databases