تقييم الموضوع :
  • 0 أصوات - بمعدل 0
  • 1
  • 2
  • 3
  • 4
  • 5
[VB.NET] تصدير الداتاجريد فيو للاكسيل
#5
(18-08-21, 12:20 AM)يونس علي كتب :
السلام عليكم ورحمة الله وبركاتة وبعد 
لقد قمت بتعديل بسيط بلكود



كود :
Private Sub ExportToExcel_click(sender As Object, e As EventArgs)

       Dim dgv As New DataGridView

       dgv = Me.DGVUSERS

       dgv.Columns(1).Visible = False

       ExportToExcel(dgv, True)

   End Sub


وهذا الكود بعد التعديل 


كود :
Sub ExportToExcel(ByVal DGV As DataGridView, Optional ByVal OpenDialog As Boolean = False, Optional ByVal SameColumnsWidth As Boolean = True)
       Dim FlNm As String = ""
       Dim sv As New SaveFileDialog
       sv.FileName = "Excel.xls"
       sv.Filter = "|*.xls"
       If sv.ShowDialog <> DialogResult.OK Then Exit Sub
       FlNm = sv.FileName
       Dim fs As New StreamWriter(FlNm, False)
       With fs
           .WriteLine("<?xml version=""1.0""?>")
           .WriteLine("<?mso-application progid=""Excel.Sheet""?>")
           .WriteLine("<Workbook xmlns=""urn:schemas-microsoft-com:office:spreadsheet"">")
           .WriteLine("  <Styles>")
           .WriteLine("  <Style ss:ID=""hdr"">")
           .WriteLine("  <Alignment ss:Horizontal=""Center""/>")
           .WriteLine("  <Borders>")
           .WriteLine("    <Border ss:Position=""Left"" ss:LineStyle=""Continuous"" ss:Weight=""1""/>")
           .WriteLine("    <Border ss:Position=""Right"" ss:LineStyle=""Continuous"" ss:Weight=""1""/>")
           .WriteLine("    <Border ss:Position=""Top"" ss:LineStyle=""Continuous"" ss:Weight=""1""/>")
           .WriteLine("  </Borders>")
           .WriteLine("  <Font ss:FontName=""Calibri"" ss:Size=""11"" ss:Bold=""1""/>") 'SET FONT
           .WriteLine("  </Style>")
           .WriteLine("  <Style ss:ID=""ksg"">")
           .WriteLine("  <Alignment ss:Vertical=""Bottom""/>")
           .WriteLine("  <Borders/>")
           .WriteLine("  <Font ss:FontName=""Calibri""/>") 'SET FONT
           .WriteLine("  </Style>")
           .WriteLine("  <Style ss:ID=""isi"">")
           .WriteLine("  <Alignment ss:Horizontal=""Center"" ss:Vertical=""Bottom""/>")
           .WriteLine("  <Borders>")
           .WriteLine("    <Border ss:Position=""Bottom"" ss:LineStyle=""Continuous"" ss:Weight=""1""/>")
           .WriteLine("    <Border ss:Position=""Left"" ss:LineStyle=""Continuous"" ss:Weight=""1""/>")
           .WriteLine("    <Border ss:Position=""Right"" ss:LineStyle=""Continuous"" ss:Weight=""1""/>")
           .WriteLine("    <Border ss:Position=""Top"" ss:LineStyle=""Continuous"" ss:Weight=""1""/>")
           .WriteLine("  </Borders>")
           .WriteLine("  <Font ss:FontName=""Calibri"" ss:Size=""10""/>")
           .WriteLine("  </Style>")
           .WriteLine("  </Styles>")
           .WriteLine("  <Worksheet ss:Name=""sheet1"">")
           .WriteLine("  <Table>")
           If SameColumnsWidth Then
               For i = 0 To DGV.ColumnCount - 1
                   If i > 4 Then Continue For '
                   If DGV.Columns(i).Visible = True Then


                       .WriteLine("  <Column ss:AutoFitWidth=""0"" ss:Width=""" & DGV.Columns(i).Width & """ />") '
                   End If
               Next
           End If
           .WriteLine("  <Row ss:StyleID=""ksg"">")
           For i As Integer = 0 To DGV.Columns.Count - 1
               If i > 4 Then Continue For '

               If DGV.Columns(i).Visible = True Then

                   Application.DoEvents()
                   .WriteLine("  <Cell ss:StyleID=""hdr"">")
                   .WriteLine("    <Data ss:Type=""String"">{0}</Data>", DGV.Columns.Item(i).HeaderText)
                   .WriteLine("  </Cell>")

               End If

           Next
           .WriteLine("  </Row>")

           For intRow As Integer = 0 To DGV.RowCount - 1

               Application.DoEvents()

               .WriteLine("  <Row ss:StyleID=""ksg"" ss:utoFitHeight =""0"">")

               For intCol As Integer = 0 To DGV.Columns.Count - 1
                   If intCol > 4 Then Continue For '                  

                   Application.DoEvents()

                   If DGV.Columns(intCol).Visible = True Then

                       .WriteLine("  <Cell ss:StyleID=""isi"">")

                       .WriteLine("  <Data ss:Type=""String"">{0}</Data>", DGV.Item(intCol, intRow).Value.ToString)

                       .WriteLine("  </Cell>")

                   End If
               Next
               .WriteLine("  </Row>")
           Next
           .WriteLine("  </Table>")
           .WriteLine("  </Worksheet>")
           .WriteLine("</Workbook>")
           .Close()
           If OpenDialog Then
               Dim msg1
               msg1 = MsgBox("The file has been saved successfully Do you want to open the file after saving ?", MsgBoxStyle.YesNo + MsgBoxStyle.Question, "Successfully exported")
               If msg1 = vbNo Then Exit Sub
               Process.Start(FlNm)
           End If
       End With
   End Sub

فعلا حل المشكلة مكنتش بفكر في الحل دة نهائي الف شكر ..
الرد }}}
تم الشكر بواسطة: asemshahen5 , يونس علي


الردود في هذا الموضوع
RE: تصدير الداتاجريد فيو للاكسيل - بواسطة احمد 2021 - 18-08-21, 04:54 PM

المواضيع المحتمل أن تكون متشابهة .
الموضوع : الكاتب الردود : المشاهدات : آخر رد
  كيف يمكن تصدير ascx كملف dll justforit 1 139 06-12-25, 12:33 AM
آخر رد: salamandal
  تصدير البيانات إلى ملف RTF مصمم هاوي 4 841 15-08-25, 04:13 PM
آخر رد: أبو خالد الشكري
  كيف اضف عدد النسخ فى كود تصدير التقرير الى PDF new_programer 1 372 17-03-25, 12:26 AM
آخر رد: princelovelorn
  عند تصدير التاريخ للإكسل يظهر معه الوقت علماُ لم اسجل الوقت. أبووسم2 2 377 24-09-24, 10:21 PM
آخر رد: أبووسم2
  رسالة و تلوين خلية الداتاجريد العيدروس 8 746 17-05-24, 10:12 PM
آخر رد: justforit
  حل مشكلة في تصدير ملف كريستال ريبورت إلى PDF صالح عبدالله 7 720 02-05-24, 08:36 PM
آخر رد: صالح عبدالله
  سؤال عن تصدير فورم الى ملف pdf ابو انس 0 625 21-09-23, 10:28 PM
آخر رد: ابو انس
  حذف هذه العلامة " " من الداتاجريد mohameed2015 3 788 03-04-23, 06:01 AM
آخر رد: سعود
  رسالة Out Of Range مع الداتاجريد ADAM12 1 604 11-02-23, 03:53 AM
آخر رد: Taha Okla
  [VB.NET] عند تصدير البيانات من DataGridView1 لملف Excel MOHAMMED ALZWI 2 714 22-12-22, 10:58 AM
آخر رد: MOHAMMED ALZWI

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


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