当前位置:网站首页>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");
}
边栏推荐
- How to solve the poor sound quality of Vos?
- The latest query tracks the express logistics and analyzes the method of delivery timeliness
- How to learn automated testing in 2022? This article tells you
- 几款开源自动化测试框架优缺点对比你知道吗?
- With 27K successful entry ByteDance, this "software testing interview notes" has benefited me for life
- Investment should be calm
- In Oracle, start with connect by prior recursive query is used to query multi-level subordinate employees.
- If the position is absolute, touchablehighlight cannot be clicked - touchablehighlight not clickable if position absolute
- [pointer] solve the last person left
- [pointer] octal to decimal
猜你喜欢

Build your own application based on Google's open source tensorflow object detection API video object recognition system (I)

Software testing interview summary - common interview questions

几款开源自动化测试框架优缺点对比你知道吗?

后台登录系统,JDBC连接数据库,做小案例练习

Dlib detects blink times based on video stream

DVWA exercise 05 file upload file upload
![[Ogg III] daily operation and maintenance: clean up archive logs, register Ogg process services, and regularly back up databases](/img/31/875b08d752ecd914f4e727e561adbd.jpg)
[Ogg III] daily operation and maintenance: clean up archive logs, register Ogg process services, and regularly back up databases

数字电路基础(二)逻辑代数

安全测试入门介绍

The common methods of servlet context, session and request objects and the scope of storing data in servlet.
随机推荐
What is an index in MySQL? What kinds of indexes are commonly used? Under what circumstances will the index fail?
Pointer -- output all characters in the string in reverse order
STC-B学习板蜂鸣器播放音乐
[pointer] solve the last person left
自动化测试你必须要弄懂的问题,精品总结
Logstack introduction and deployment -- elasticstack (elk) work notes 019
The minimum sum of the last four digits of the split digit of leetcode simple problem
Function: calculates the number of uppercase letters in a string
C language learning summary (I) (under update)
基于485总线的评分系统双机实验报告
Global and Chinese market of barrier thin film flexible electronics 2022-2028: Research Report on technology, participants, trends, market size and share
Differences between select, poll and epoll in i/o multiplexing
1. Payment system
Pedestrian re identification (Reid) - data set description market-1501
王爽汇编语言学习详细笔记一:基础知识
Vysor uses WiFi wireless connection for screen projection_ Operate the mobile phone on the computer_ Wireless debugging -- uniapp native development 008
Pedestrian re identification (Reid) - Overview
Functions: Finding Roots of equations
Face and eye recognition based on OpenCV's own model
[pointer] find the length of the string