11-12-23, 10:11 AM
(10-12-23, 05:12 PM)محمد العموري كتب : السلام عليكم كيف حالكم يا كرام
أريد كود لإرسال البيانات من الداتا جريد فيو بعد الفلترة إلى الوورد
PHP كود :
Imports Microsoft.Office.Interop.Word
Public Class Form1
Dim wordApp As Application
Dim doc As Document
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
' تهيئة Word
wordApp = New Application()
doc = wordApp.Documents.Add()
End Sub
Private Sub btnExportToWord_Click(sender As Object, e As EventArgs) Handles btnExportToWord.Click
ExportToWord(dataGridView1)
End Sub
Private Sub ExportToWord(dataGridView As DataGridView)
' إضافة العناوين الخاصة بالأعمدة إلى المستند Word
Dim table As Table = doc.Tables.Add(doc.Range, dataGridView.Columns.Count, 1)
For i As Integer = 1 To dataGridView.Columns.Count
table.Cell(1, i).Range.Text = dataGridView.Columns(i - 1).HeaderText
Next
' إضافة البيانات إلى المستند Word
For i As Integer = 0 To dataGridView.Rows.Count - 1
table.Rows.Add()
For j As Integer = 0 To dataGridView.Columns.Count - 1
table.Cell(i + 2, j + 1).Range.Text = dataGridView(j, i).Value.ToString()
Next
Next
End Sub
Private Sub Form1_FormClosing(sender As Object, e As FormClosingEventArgs) Handles MyBase.FormClosing
' إغلاق Word عند إغلاق النافذة
If wordApp IsNot Nothing Then
wordApp.Quit()
End If
End Sub
End Class

