当前位置:网站首页>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");
}
边栏推荐
- [HCIA continuous update] working principle of static route and default route
- Function: string storage in reverse order
- The minimum number of operations to convert strings in leetcode simple problem
- Zhejiang University Edition "C language programming experiment and exercise guide (3rd Edition)" topic set
- Query method of database multi table link
- ByteDance ten years of experience, old bird, took more than half a year to sort out the software test interview questions
- Thinking about three cups of tea
- How to learn automated testing in 2022? This article tells you
- Global and Chinese market of portable and handheld TVs 2022-2028: Research Report on technology, participants, trends, market size and share
- Why can swing implement a form program by inheriting the JFrame class?
猜你喜欢

Dlib detects blink times based on video stream
![Transplant hummingbird e203 core to Da Vinci pro35t [Jichuang xinlai risc-v Cup] (I)](/img/85/d6b196f22b60ad5003f73eb8d8a908.png)
Transplant hummingbird e203 core to Da Vinci pro35t [Jichuang xinlai risc-v Cup] (I)

Statistics 8th Edition Jia Junping Chapter 4 Summary and after class exercise answers

Wang Shuang's detailed notes on assembly language learning I: basic knowledge

Quaternion -- basic concepts (Reprint)

Stc-b learning board buzzer plays music 2.0

The common methods of servlet context, session and request objects and the scope of storing data in servlet.

Software testing interview summary - common interview questions

Fundamentals of digital circuits (II) logic algebra

基于485总线的评分系统双机实验报告
随机推荐
My first blog
Global and Chinese markets of electronic grade hexafluorobutadiene (C4F6) 2022-2028: Research Report on technology, participants, trends, market size and share
Stc-b learning board buzzer plays music 2.0
Sorting odd and even subscripts respectively for leetcode simple problem
If the position is absolute, touchablehighlight cannot be clicked - touchablehighlight not clickable if position absolute
Logstack introduction and deployment -- elasticstack (elk) work notes 019
软件测试方法有哪些?带你看点不一样的东西
Wang Shuang's detailed notes on assembly language learning I: basic knowledge
In Oracle, start with connect by prior recursive query is used to query multi-level subordinate employees.
Keil5 MDK's formatting code tool and adding shortcuts
With 27K successful entry ByteDance, this "software testing interview notes" has benefited me for life
自动化测试中敏捷测试怎么做?
Why can swing implement a form program by inheriting the JFrame class?
[pointer] find the largest string
DVWA exercise 05 file upload file upload
Detailed introduction to dynamic programming (with examples)
Description of Vos storage space, bandwidth occupation and PPS requirements
China's county life record: go upstairs to the Internet, go downstairs' code the Great Wall '
Function: string storage in reverse order
Global and Chinese markets for GaN on diamond semiconductor substrates 2022-2028: Research Report on technology, participants, trends, market size and share