تقييم الموضوع :
  • 0 أصوات - بمعدل 0
  • 1
  • 2
  • 3
  • 4
  • 5
[سؤال] طلب مساعدة vb.net: إرسال بيانات من داتاقريدفيو الى نمودج وورد
#3
تفضل يا عزيزي هذا صب لتصدير بيانات من الداتا جرد فيو للورد


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 : العنوان"
الرد }}}
تم الشكر بواسطة: elgokr , elgokr , dell , dell


الردود في هذا الموضوع
RE: طلب مساعدة vb.net: إرسال بيانات من داتاقريدفيو الى نمودج وورد - بواسطة aljzazy - 19-08-18, 11:11 PM


التنقل السريع :


يقوم بقرائة الموضوع: