ช่วยหน่อยครับ DataGridView แสดงข้อมูลหมด แต่เวลา export to excel ข้อมูลไม่ตรงกันครับ
1.ตัวที่ครอบสีแดง B D K ผมใช้เครื่องมือใน datagridviwe เพิ่มเอานะครับ Null value= (แต่ใน excel ไมแสดงครับ)
2.ตัวที่ครอบสีแดง E F G เป็นวันที่นะครับ ผมก็ใช้ Format datagrid เหมือนกันครับ yyyyMMdd แต่ใน excel ไม่ตรงกันครับ
พอจะมีวิธีช่วยไหมครับหรือผมทำผิดวิธี
Code (VB.NET)
Public Class Goods_Receipt_PO
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim EndDate As Date = DateTimePicker2.Value.Date.AddDays(1)
Me.NY_VWRUBBERRECBindingSource.Filter = "recinsdate >= '" & DateTimePicker1.Value.Date.ToString("s") & "' AND recinsdate <'" & EndDate.ToString("s") & "'"
Console.WriteLine(Me.NY_VWRUBBERRECBindingSource.Filter)
' Me.StudentBindingSource.Filter = "TO_DAY >= '" & DateTimePicker1.Value.ToString("s") & "' AND TO_DAY <= '" & DateTimePicker2.Value.ToString("s") & "'"
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim xlApp As Microsoft.Office.Interop.Excel.Application
Dim xlWorkBook As Microsoft.Office.Interop.Excel.Workbook
Dim xlWorkSheet As Microsoft.Office.Interop.Excel.Worksheet
Dim misValue As Object = System.Reflection.Missing.Value
Dim i As Integer
Dim j As Integer
xlApp = New Microsoft.Office.Interop.Excel.Application
xlWorkBook = xlApp.Workbooks.Add(misValue)
xlWorkSheet = xlWorkBook.Sheets("sheet1")
For i = 0 To NY_VWRUBBERRECDataGridView.RowCount - 1
For j = 0 To NY_VWRUBBERRECDataGridView.ColumnCount - 1
For k As Integer = 1 To NY_VWRUBBERRECDataGridView.Columns.Count
xlWorkSheet.Cells(1, k) = NY_VWRUBBERRECDataGridView.Columns(k - 1).HeaderText
xlWorkSheet.Cells(i + 2, j + 1) = NY_VWRUBBERRECDataGridView(j, i).Value()
Next
Next
Next
xlWorkSheet.SaveAs("D:\cbexcel.xlsx")
xlWorkBook.Close()
xlApp.Quit()
releaseObject(xlApp)
releaseObject(xlWorkBook)
releaseObject(xlWorkSheet)
Dim res As MsgBoxResult
res = MsgBox("Process completed, Would you like to open file?", MsgBoxStyle.YesNo)
If (res = MsgBoxResult.Yes) Then
Process.Start("d:\cbexcel.xlsx")
End If
End Sub
Private Sub releaseObject(ByVal obj As Object)
Try
System.Runtime.InteropServices.Marshal.ReleaseComObject(obj)
obj = Nothing
Catch ex As Exception
obj = Nothing
Finally
GC.Collect()
End Try
End Sub
Private Sub Goods_Receipt_PO_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'NyrubberDataSet.NY_VWRUBBERREC' table. You can move, or remove it, as needed.
Me.NY_VWRUBBERRECTableAdapter.Fill(Me.NyrubberDataSet.NY_VWRUBBERREC)
End Sub
End Class