Private OpenFileDialog1
As
New OpenFileDialog
Private
Sub test()
OpenFileDialog1.Filter =
"
cfg file|*.srp.cfg
"
If OpenFileDialog1.ShowDialog() = DialogResult.OK
Then
MsgBox(OpenFileDialog1.FileName)
MsgBox(OpenFileDialog1.SafeFileName)
Else
Return
End
If
End Sub
'
在工做表中查找關鍵字,返回最後一個匹配項的單元格
Public
Function findLastCell(key
As
String)
As Excel.Range
Dim findResult
As Excel.Range = Cells.Find(key)
Dim lastRecord
As Excel.Range =
Nothing
If (findResult
IsNot
Nothing)
Then
Dim firstRecordRow = findResult.Row
Do
lastRecord = findResult
findResult = Cells.FindNext(findResult)
Loop
Until findResult
Is
Nothing
OrElse findResult.Row = firstRecordRow
End
If
Return lastRecord
End Function
'
設置單元格的格式
Private
Sub test()
With Globals.Sheet1
Dim sysKpiRow
As Excel.Range = .Range(.Cells(
0,
1), .Cells(
0,
10))
sysKpiRow.Interior.ColorIndex =
34
'
淺青綠,詳見下
sysKpiRow.Borders.LineStyle = Excel.XlLineStyle.xlContinuous
'
顯示邊框
sysKpiRow.Cells(
1).value =
"
系統KPI
"
sysKpiRow.Columns.AutoFit()
'
根據內容自動擴張列寬
'
range的offset仍然是等大小的range
Dim sysKpiVal
As Excel.Range = sysKpiRow.Offset(
1,
0)
sysKpiVal.Borders.LineStyle = Excel.XlLineStyle.xlContinuous
'
設置單元格,添加數據有效性,下拉框選擇yes和no
With sysKpiVal.Validation
.Add(Type:=Excel.XlDVType.xlValidateList, AlertStyle:=Excel.XlDVAlertStyle.xlValidAlertStop, _
Operator:=Excel.XlFormatConditionOperator.xlBetween, Formula1:=
"
yes,no
")
.IgnoreBlank =
True
.InCellDropdown =
True
.ShowInput =
True
.ShowError =
True
End
With
sysKpiVal.Value =
"
yes
"
'
統一設置默認值爲yes
End
With
End Sub
https://msdn.microsoft.com/en-us/library/cc296089%28v=office.12%29.aspx#xlDiscoveringColorIndex_ColorIndexProperty