【发布时间】:2016-10-12 10:00:07
【问题描述】:
我有一个问题,在 excel 中一列包含一个唯一编号,格式为:mmdd 后跟序列号 01,02.. 例如:101201(10:月,12:今天的日期,01:第一个条目), 101202。 现在,我需要的是我在 vb.net 中的表格应该采用最后输入的数据(例如:101202)检查它是否是今天的日期。如果是,则应加 1 并在消息框中显示。(是,则应显示 101203)。如果不是,那么它应该取当前日期并从 01 开始(如果是 101301,则日期是 2016 年 10 月 13 日)。 我设法从前一行获取数据。但是我应该如何用日期检查它? 请帮忙!
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
xlWorkBook = xlApp.Workbooks.Open("C:\Users\Desktop\testing.xlsx")
'xlApp.Visible = True
xlWorkSheet = xlWorkBook.Sheets("Sheet1")
Dim row As Long
row = 1
With xlWorkSheet
While .Cells(row, 2).value IsNot Nothing
row = row + 1
End While
'MsgBox(row - 1)
End With
Dim r As Excel.Range
Dim t As String = Format(Today, "MMdd")
If xlWorkSheet.Cells(row - 1, 4).value Is Nothing Then
Me.txtQuote.Text = t & "01"
Else
r = xlWorkSheet.Cells(row - 1, 4)
Me.txtQuote.Text = (r.Value + 1)
End If
'this is wrong and I know it's wrong
If r.Value = Date.Today Then
MsgBox("true")
Else
MsgBox("false")
End If
End Sub
【问题讨论】:
标签: excel vb.net date visual-studio-2013 excel-2013