منتدى فيجوال بيسك لكل العرب | منتدى المبرمجين العرب
اكسيل مع datagridview - نسخة قابلة للطباعة

+- منتدى فيجوال بيسك لكل العرب | منتدى المبرمجين العرب (http://vb4arb.com/vb)
+-- قسم : قسم لغة الفيجوال بيسك VB.NET (http://vb4arb.com/vb/forumdisplay.php?fid=182)
+--- قسم : قسم اسئلة VB.NET (http://vb4arb.com/vb/forumdisplay.php?fid=183)
+--- الموضوع : اكسيل مع datagridview (/showthread.php?tid=22277)



اكسيل مع datagridview - محمود صالح - 27-10-17

سلام عليكم 
ده كود لتصدير بيانات الى الاكسيل
                           Dim MsExcel = CreateObject("Excel.Application")
                                                            MsExcel.Workbooks.Add()
            MsExcel.Cells(0 + 1).Value = DGV1.Columns(0).HeaderText
            MsExcel.Cells(1 + 1).Value = DGV1.Columns(1).HeaderText
            MsExcel.Cells(2 + 1).Value = DGV1.Columns(2).HeaderText
            MsExcel.Cells(3 + 1).Value = DGV1.Columns(3).HeaderText
       
                                            For I As Integer = 0 To DGV1.Rows.Count - 1
            MsExcel.Cells(I + 2, 1).Value = DGV1.Rows(I).Cells(0).Value
            MsExcel.Cells(I + 2, 2).Value = DGV1.Rows(I).Cells(1).Value
            MsExcel.Cells(I + 2, 3).Value = DGV1.Rows(I).Cells(2).Value
            MsExcel.Cells(I + 2, 4).Value = DGV1.Rows(I).Cells(3).Value
                                                                                                      Next
                                                                                                                                                                                                                                     MsExcel.Visible = True
 كل ما اريده هو عكس الكود لاستيراد من ملف الاكسيل
بس من خلال هذا الاكود وليس طريقة اخرى
هل ممكن


RE: اكسيل مع datagridview - a.ahmed - 27-10-17

PHP كود :
Dim MsExcel CreateObject("Excel.Application")
MsExcel.Workbooks.Open("d:\book1.xlsx")

DGV1.Columns(0).HeaderText MsExcel.Cells(1).Value
DGV1
.Columns(1).HeaderText MsExcel.Cells(1).Value
DGV1
.Columns(2).HeaderText MsExcel.Cells(1).Value
DGV1
.Columns(3).HeaderText MsExcel.Cells(1).Value

DGV1
.Rows.Clear()
Dim I As Integer 0
Do
 
   If MsExcel.Cells(21).Value "" Then Exit Do
 
   DGV1.RowCount DGV1.RowCount 1
    DGV1
.Rows(I).Cells(0).Value MsExcel.Cells(21).Value
    DGV1
.Rows(I).Cells(1).Value MsExcel.Cells(22).Value
    DGV1
.Rows(I).Cells(2).Value MsExcel.Cells(23).Value
    DGV1
.Rows(I).Cells(3).Value MsExcel.Cells(24).Value
    I 
1
Loop

MsExcel
.Quit() 

    Updated


RE: اكسيل مع datagridview - محمود صالح - 27-10-17

(27-10-17, 07:38 PM)a.ahmed كتب :
PHP كود :
Dim MsExcel CreateObject("Excel.Application")
MsExcel.Workbooks.Add()
Dim xlWorkBook MsExcel.Workbooks.Open("d:\book1.xlsx")

DGV1.Columns(0).HeaderText MsExcel.Cells(1).Value
DGV1
.Columns(1).HeaderText MsExcel.Cells(1).Value
DGV1
.Columns(2).HeaderText MsExcel.Cells(1).Value
DGV1
.Columns(3).HeaderText MsExcel.Cells(1).Value

Dim I 
As Integer 0
DGV1
.Rows.Clear()
Do
 
   If MsExcel.Cells(21).Value "" Then Exit Do
 
   DGV1.RowCount DGV1.RowCount 1
    DGV1
.Rows(I).Cells(0).Value MsExcel.Cells(21).Value
    DGV1
.Rows(I).Cells(1).Value MsExcel.Cells(22).Value
    DGV1
.Rows(I).Cells(2).Value MsExcel.Cells(23).Value
    DGV1
.Rows(I).Cells(3).Value MsExcel.Cells(24).Value
    I 
1
Loop

xlWorkBook
.Close()
MsExcel.Quit() 

تسلم يا كبير