منتدى فيجوال بيسك لكل العرب | منتدى المبرمجين العرب

نسخة كاملة : طلب مساعدة vb.net: إرسال بيانات من داتاقريدفيو الى نمودج وورد
أنت حالياً تتصفح نسخة خفيفة من المنتدى . مشاهدة نسخة كاملة مع جميع الأشكال الجمالية .
السلام  عليكم أطلب مساعدة الخبراء عندي تطبيق أريد إرسال بيانات من داتاقريد فيو(رقم العميل , لقب العميل ، إسم العميل) الى نمودج وورد بحيث .: 
كل سطر من الداتاقريد فيو يرسل الى صفحة من نمودج وورد, لينتج عندي ملف واحد عدد صفحاته يساوي عدد أسطر الداتاقريد فيو , بيانات كل عميل في صفحة باستعمال bookmarks

وشكرا
أحد الخيارات المطروحة هي تصميم تقرير ثم تصديره الى ملف وورد بالكود دون عرضه
بالتالي لا داعي لتصميم قالب وورد بل سيكون كل التصميم في التقرير نفسه

عموما هذا خيار متعب نوعا ما يمكنك اللجوء له في حالة فشلت في تطبيق أي حلول أخرى
يوجد في المنتدى موضوع به روابط لفيديوهات عربية على يوتيوب تشرح فكرة قوالب الوورد
لم أجد الموضوع لذلك اقترح ان تبحث عنه
تفضل يا عزيزي هذا صب لتصدير بيانات من الداتا جرد فيو للورد


PHP كود :
'Imports Microsoft.Office.Interop
'
Imports Microsoft.Office.Interop.Word
Public Sub ExportToWord(ByVal dgv As DataGridViewHeading As String)
 
       Dim oWord As Word.Application DirectCast(CreateObject("Word.Application"), Word.Application)
 
       Dim oDoc As Word.Document oWord.Documents.Add()
 
       'Insert a paragraph at the beginning of the document.
        Dim oPara1 As Word.Paragraph
        oPara1 = oDoc.Content.Paragraphs.Add
        oPara1.Range.Text =  Heading  
        oPara1.Alignment = WdParagraphAlignment.wdAlignParagraphCenter
        oPara1.Range.InsertParagraphAfter()
        '
-------------------------
 
       Dim headers = (From ch In dgv.Columns _
                      Let header 
DirectCast(DirectCast(chDataGridViewColumn).HeaderCellDataGridViewColumnHeaderCell_
                      Select header
.Value).ToArray()
 
       Dim headerText() As String = Array.ConvertAll(headers, Function(vv.ToString)
 
       Dim items() = (From r In dgv.Rows Let row DirectCast(rDataGridViewRowWhere Not row.IsNewRow _
         Select 
(From cell In row.Cells Let c DirectCast(cellDataGridViewCellSelect c.Value).ToArray()).ToArray()
 
       Dim table As String String.Join(vbTabheaderText) & Environment.NewLine
        For Each a In items
            Dim t
() As String = Array.ConvertAll(a, Function(vv.ToString)
 
           table &= String.Join(vbTabt) & Environment.NewLine
        Next
        table 
table.TrimEnd(CChar(Environment.NewLine))
 
       Clipboard.SetText(table)
 
       Dim oTable As Word.Table oDoc.Tables.Add(oDoc.Bookmarks.Item("\endofdoc").Rangeitems.Count 1headers.Count)
 
       oTable.Range.Paste()
 
       oTable.TableDirection WdTableDirection.wdTableDirectionRtl
        
'make the first row bold, fs 14 + change textcolor
        oTable.Rows.Item(1).Range.Font.Bold = &H98967E
        oTable.Rows.Item(1).Range.Font.Size = 14
        oTable.Rows.Item(1).Range.Font.Color = Word.WdColor.wdColorWhite
        '
change backcolor of first row
        oTable
.Rows.Item(1).Range.Shading.Texture Word.WdTextureIndex.wdTextureNone
        oTable
.Rows.Item(1).Range.Shading.ForegroundPatternColor Word.WdColor.wdColorAutomatic
        oTable
.Rows.Item(1).Range.Shading.BackgroundPatternColor Word.WdColor.wdColorPaleBlue
        oTable
.Borders.OutsideColor Word.WdColor.wdColorBlack
        oTable
.Borders.OutsideLineStyle Word.WdLineStyle.wdLineStyleSingle
        oTable
.Borders.InsideColor Word.WdColor.wdColorBlack
        oTable
.Borders.InsideLineStyle Word.WdLineStyle.wdLineStyleSingle
        oWord
.Visible True
    End Sub 


ثم قم باستدعاء الصب في الحدث الذي تريده مع تغيير اسم الداتا جرد فيو لاسم الداتا جرد فيو في مشروعك

PHP كود :
ExportToWord(dgv_Customers,"Heading : العنوان"
جزاك الله خير