本文介绍了此代码从串行端口发送数据并保存在Excel中.如何更改此代码以保存在sql表中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
       Data = SerialPort1.ReadExisting
       If Data <> "" Then
           temp = Data.Length
           If counter = 1 Then

               ExcelApp = New Excel.Application
               ExcelBook = ExcelApp.Workbooks.Add(MisValue)
               ExcelSheet = ExcelBook.Sheets("sheet1")



               ExcelSheet.Cells(1, 1) = "No"
               ExcelSheet.Cells(1, 2) = "Date"
               ExcelSheet.Cells(1, 3) = "Time"
               ExcelSheet.Cells(1, 4) = "Idnumber"
               ExcelSheet.Cells(1, 5) = "NameIn"
               ExcelSheet.Cells(1, 6) = "StatusOut"
               FileName = "RekodKeluarMasuk"
               ExcelBook.SaveAs(TbFileLoc.Text & FileName & ".xls")

           End If

           ExcelSheet.Cells(counter + 1, 1) = counter
           ExcelSheet.Cells(counter + 1, 2) = DateString
           ExcelSheet.Cells(counter + 1, 3) = TimeString
           If Data = "OUT" Then
               ExcelSheet.Cells(counter + 1, 6) = Data
           Else
               ExcelSheet.Cells(counter + 1, 5) = "=" & Chr(34) & Data.Substring(11, temp - 11) & Chr(34) 
               ExcelSheet.Cells(counter + 1, 4) = "=" & Chr(34) & Data.Substring(0, 10) & Chr(34) 'id

           End If

           ExcelSheet.Columns.AutoFit()
           ExcelBook.Save()

推荐答案



这篇关于此代码从串行端口发送数据并保存在Excel中.如何更改此代码以保存在sql表中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 18:47