التنبيهات التالية ظهرت :
Warning [2] count(): Parameter must be an array or an object that implements Countable - Line: 864 - File: showthread.php PHP 7.4.33 (Linux)
File Line Function
/showthread.php 864 errorHandler->error



تقييم الموضوع :
  • 0 أصوات - بمعدل 0
  • 1
  • 2
  • 3
  • 4
  • 5
تصدير DataGridView الى xls
#1
طريقة سريعة جدا لتصدير DataGridView الى ملف xls
PHP كود :
Imports System.IO 
PHP كود :
Public Sub ExportToExcel(ByVal DGV As DataGridViewOptional OpenDialog As Boolean FalseOptional 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(FlNmFalse)
 
       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
                    
.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
                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
                    Application
.DoEvents()
 
                   .WriteLine("  <Cell ss:StyleID=""isi"">")
 
                   .WriteLine("  <Data ss:Type=""String"">{0}</Data>"DGV.Item(intColintRow).Value.ToString)
 
                   .WriteLine("  </Cell>")
 
               Next
                
.WriteLine("  </Row>")
 
           Next
            
.WriteLine("  </Table>")
 
           .WriteLine("  </Worksheet>")
 
           .WriteLine("</Workbook>")
 
           .Close()
 
           If OpenDialog Then
                Dim msg1
                msg1 
MsgBox("Save complete .. Do you want open file ?"MsgBoxStyle.YesNo MsgBoxStyle.Question"Export")
 
               If msg1 vbNo Then Exit Sub
                Process
.Start(FlNm)
 
           End If
 
       End With
    End Sub 
Wink
الرد }}}


الردود في هذا الموضوع
تصدير DataGridView الى xls - بواسطة HASAN6.0 - 26-03-16, 05:32 PM
RE: تصدير DataGridView الى xls - بواسطة A_Baidak - 07-04-16, 11:17 PM
RE: تصدير DataGridView الى xls - بواسطة IBRA939 - 28-07-17, 01:57 AM
RE: تصدير DataGridView الى xls - بواسطة walkady - 13-03-18, 01:47 AM
RE: تصدير DataGridView الى xls - بواسطة mo.fathi - 16-07-19, 11:40 PM
RE: تصدير DataGridView الى xls - بواسطة asemshahen5 - 17-07-19, 12:37 AM
RE: تصدير DataGridView الى xls - بواسطة mo.fathi - 19-07-19, 04:02 PM
RE: تصدير DataGridView الى xls - بواسطة asemshahen5 - 19-07-19, 04:19 PM
RE: تصدير DataGridView الى xls - بواسطة atefkhalf2004 - 24-06-22, 04:25 PM
RE: تصدير DataGridView الى xls - بواسطة asemshahen5 - 24-06-22, 09:09 PM
RE: تصدير DataGridView الى xls - بواسطة atefkhalf2004 - 25-06-22, 02:33 AM
RE: تصدير DataGridView الى xls - بواسطة asemshahen5 - 08-07-22, 05:25 PM
RE: تصدير DataGridView الى xls - بواسطة atefkhalf2004 - 08-07-22, 06:32 PM
RE: تصدير DataGridView الى xls - بواسطة atefkhalf2004 - 08-07-22, 08:45 PM
RE: تصدير DataGridView الى xls - بواسطة asemshahen5 - 08-07-22, 08:56 PM
RE: تصدير DataGridView الى xls - بواسطة atefkhalf2004 - 09-07-22, 02:45 AM
RE: تصدير DataGridView الى xls - بواسطة asemshahen5 - 09-07-22, 12:20 PM
RE: تصدير DataGridView الى xls - بواسطة atefkhalf2004 - 09-07-22, 01:30 PM
RE: تصدير DataGridView الى xls - بواسطة asemshahen5 - 09-07-22, 01:33 PM
RE: تصدير DataGridView الى xls - بواسطة atefkhalf2004 - 09-07-22, 06:05 PM
RE: تصدير DataGridView الى xls - بواسطة asemshahen5 - 09-07-22, 06:37 PM
RE: تصدير DataGridView الى xls - بواسطة atefkhalf2004 - 09-07-22, 07:21 PM
RE: تصدير DataGridView الى xls - بواسطة asemshahen5 - 09-07-22, 07:30 PM
RE: تصدير DataGridView الى xls - بواسطة atefkhalf2004 - 09-07-22, 11:12 PM
RE: تصدير DataGridView الى xls - بواسطة asemshahen5 - 12-07-22, 04:46 PM
RE: تصدير DataGridView الى xls - بواسطة atefkhalf2004 - 13-07-22, 12:16 AM
RE: تصدير DataGridView الى xls - بواسطة asemshahen5 - 14-07-22, 12:29 AM
RE: تصدير DataGridView الى xls - بواسطة Mohammed Nafa - 20-12-22, 11:40 PM


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


يقوم بقرائة الموضوع: بالاضافة الى ( 1 ) ضيف كريم