'表格數(shù)據(jù)導(dǎo)到Txt
Private Sub ToolStripButtonExpTxt_Click(sender As Object, e As EventArgs) Handles ToolMain_ButtonExpTxt.Click
Dim cFileName As String = "D:\MyProg\" & "連板" & Date.Now.Month.ToString & Date.Now.Day.ToString & ".txt"
Dim oFile As New StreamWriter(cFileName)
Dim strTemp As String = Nothing
Try
For r = 0 To DGV_GpHqFind.RowCount - 1
strTemp = ""
For c = 0 To DGV_GpHqFind.Columns.Count - 1
strTemp &= DGV_GpHqFind(c, r).Value & ","
Next
oFile.WriteLine(strTemp)
Next
MsgBox("數(shù)據(jù)已導(dǎo)到:" & cFileName, 64, "信息提示")
oFile.Close()
Catch ex As Exception
MsgBox(ex.ToString, 48, "錯誤信息")
End Try
oFile = Nothing
End Sub
'表格數(shù)據(jù)導(dǎo)到Excel
Private Sub ToolStripButtonExpExcel_Click(sender As Object, e As EventArgs) Handles ToolMain_ButtonExpExcel.Click
Dim oExce As Excel.Application
Dim oWork As Excel.Workbook
Dim oSh As Excel.Worksheet
Dim oRng As Excel.Range
Try
Dim cTitle As String = "代碼,名稱,今開,昨收,今收,漲跌,漲幅%,最高,最低,成交量,成交額"
Dim aTitle As Array = cTitle.Split(",")
' Start Excel and get Application object.
oExce = CreateObject("Excel.Application")
oExce.Visible = True
' Add a new workbook.
oWork = oExce.Workbooks.Add
oSh = oWork.ActiveSheet
For c As Integer = 0 To aTitle.Length - 1
oSh.Cells(1, c + 1).Value = aTitle(c)
Next
oExce.ScreenUpdating = False
' Format A1:D1 as bold, vertical alignment = center.
oSh.Range("A:B").NumberFormatLocal = "@"
For r = 0 To Me.DGV_GpHqFind.RowCount - 1
For c = 0 To Me.DGV_GpHqFind.ColumnCount - 1
With oSh
If c < 2 Then
.Cells(r + 2, c + 1).Value = Me.DGV_GpHqFind.Item(c, r).Value.ToString
Else
.Cells(r + 2, c + 1).Value = Me.DGV_GpHqFind.Item(c, r).Value
End If
End With
Next
Next
With oSh.Range("A1", "K" & DGV_GpHqFind.RowCount + 1)
.Font.Name = "微軟雅黑"
.Font.Size = 11
End With
With oSh.Range("A1", "K1")
.Font.Bold = True
.VerticalAlignment = Excel.XlVAlign.xlVAlignCenter
.EntireColumn.AutoFit()
End With
oExce.ScreenUpdating = True
' Make sure Excel is visible and give the user control
' of Excel's lifetime.
' Release object references.
'oExce.Visible = True
oRng = Nothing
oSh = Nothing
oWork = Nothing
oExce.Quit()
oExce = Nothing
Catch ex As Exception
MsgBox(ex.ToString, 48, "錯誤信息")
End Try
End Sub