تقييم الموضوع :
  • 0 أصوات - بمعدل 0
  • 1
  • 2
  • 3
  • 4
  • 5
[VB.NET] تصدير الداتاجريد فيو للاكسيل
#1
السلام عليكم ورحمة الله بركاتة 

لدي فنكشن اقوم بتصدير البيانات من الداتاجريد فيو الي الاكسيل من خلالها 

تعمل جيد ا .
المشكلة اني لا اريد تصدير كل الاعمدة اريد تحديد اعمدة معينة لكي يتم تصديرها لاكسيل وليس كل الاعمدة 

حاولت استبعاد اعمدة بتجاهل رقم العمود مثلا العمود رقم اربعة ولم تفلح الطريقة معي ..

كود :
Public 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("  <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'
                   .WriteLine("  <Column ss:Width=""" & DGV.Columns(i).Width & """/>")

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


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

           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()



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


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

                           .WriteLine("  </Cell>")

               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
الرد }}}
تم الشكر بواسطة: ابراهيم ايبو


الردود في هذا الموضوع
تصدير الداتاجريد فيو للاكسيل - بواسطة احمد 2021 - 15-08-21, 12:49 AM

المواضيع المحتمل أن تكون متشابهة .
الموضوع : الكاتب الردود : المشاهدات : آخر رد
  كيف يمكن تصدير ascx كملف dll justforit 1 138 06-12-25, 12:33 AM
آخر رد: salamandal
  تصدير البيانات إلى ملف RTF مصمم هاوي 4 841 15-08-25, 04:13 PM
آخر رد: أبو خالد الشكري
  كيف اضف عدد النسخ فى كود تصدير التقرير الى PDF new_programer 1 371 17-03-25, 12:26 AM
آخر رد: princelovelorn
  عند تصدير التاريخ للإكسل يظهر معه الوقت علماُ لم اسجل الوقت. أبووسم2 2 375 24-09-24, 10:21 PM
آخر رد: أبووسم2
  رسالة و تلوين خلية الداتاجريد العيدروس 8 743 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 787 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 711 22-12-22, 10:58 AM
آخر رد: MOHAMMED ALZWI

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


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