使用c#使excel列不可编辑 [英] Make excel columns non editable using c#
本文介绍了使用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列不可编辑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文