使用c#使excel列不可编辑

编程入门 行业动态 更新时间:2024-10-22 13:58:58
本文介绍了使用c#使excel列不可编辑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一张excel表。 想要使用c#使前3列可编辑并保持所有列不可编辑且空白(没有网格线)。请帮忙...

I have an excel sheet. Want to make first 3 columns editable and remaining all columns non editable and blank (without grid lines) using c#. Please help...

推荐答案

你可以用c#和interop做同样的事情,就像你用VBA或gui本身一样。 主要想法: - 从所有其他单元格中删除锁定 - 为所有其他单元格添加白色(不是无)边框 - 添加工作表或工作簿保护 这是我用宏录制器录制的: You can do with c# and interop the same things as you can do with VBA, or the gui itself. The main idea: - remove locking form all other cells - add white (not "none") borders to all other cells - add worksheet or workbook protection This is what I have recorded with macro recorder: Sub Makró2() Cells.Select Selection.Borders(xlDiagonalDown).LineStyle = xlNone Selection.Borders(xlDiagonalUp).LineStyle = xlNone With Selection.Borders(xlEdgeLeft) .LineStyle = xlContinuous .ThemeColor = 1 .TintAndShade = 0 .Weight = xlThin End With With Selection.Borders(xlEdgeTop) .LineStyle = xlContinuous .ThemeColor = 1 .TintAndShade = 0 .Weight = xlThin End With With Selection.Borders(xlEdgeBottom) .LineStyle = xlContinuous .ThemeColor = 1 .TintAndShade = 0 .Weight = xlThin End With With Selection.Borders(xlEdgeRight) .LineStyle = xlContinuous .ThemeColor = 1 .TintAndShade = 0 .Weight = xlThin End With With Selection.Borders(xlInsideVertical) .LineStyle = xlContinuous .ThemeColor = 1 .TintAndShade = 0 .Weight = xlThin End With With Selection.Borders(xlInsideHorizontal) .LineStyle = xlContinuous .ThemeColor = 1 .TintAndShade = 0 .Weight = xlThin End With Columns("A:C").Select Selection.Borders(xlDiagonalDown).LineStyle = xlNone Selection.Borders(xlDiagonalUp).LineStyle = xlNone With Selection.Borders(xlEdgeLeft) .LineStyle = xlContinuous .ColorIndex = xlAutomatic .TintAndShade = 0 .Weight = xlThin End With With Selection.Borders(xlEdgeTop) .LineStyle = xlContinuous .ColorIndex = xlAutomatic .TintAndShade = 0 .Weight = xlThin End With With Selection.Borders(xlEdgeBottom) .LineStyle = xlContinuous .ColorIndex = xlAutomatic .TintAndShade = 0 .Weight = xlThin End With With Selection.Borders(xlEdgeRight) .LineStyle = xlContinuous .ColorIndex = xlAutomatic .TintAndShade = 0 .Weight = xlThin End With With Selection.Borders(xlInsideVertical) .LineStyle = xlContinuous .ColorIndex = xlAutomatic .TintAndShade = 0 .Weight = xlThin End With With Selection.Borders(xlInsideHorizontal) .LineStyle = xlContinuous .ColorIndex = xlAutomatic .TintAndShade = 0 .Weight = xlThin End With Selection.Locked = False Selection.FormulaHidden = False ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True ActiveSheet.EnableSelection = xlUnlockedCells End Sub

播放它,如果这是你需要的,只需翻译成互操作。

Play it, and if this is what you need, simply translate to interop.

检查这些.. 如何通过C#代码创建excel单元ReadOnly [ ^ ] C#。 NET - 如何使一些excel文件列不可编辑 [ ^ ] Check these.. How to make a excel cell ReadOnly by C# code[^] C# .NET - How to make some excel file column non editable[^]

更多推荐

使用c#使excel列不可编辑

本文发布于:2023-11-23 01:26:43,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1619616.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:编辑   excel

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!