| |

VerySource

 Forgot password?
 Register
Search
View: 1703|Reply: 11

How to print out the data in the DataGrid

[Copy link]

2

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 Denmark

Post time: 2020-1-3 18:10:01
| Show all posts |Read mode
Just make a print button, click to print the data in the DataGrid, but I don't know how to do it, I hope to know the details ~~~
Reply

Use magic Report

0

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-1-6 17:42:01
| Show all posts
If not, export the data of DATAGRID to EXCEL,

This one is easier.
Reply

Use magic Report

0

Threads

3

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-8-20 19:30:01
| Show all posts
wkiss007


   
If not, export the data of DATAGRID to EXCEL,

This one is easier.

  

How should I export to Excel???
Reply

Use magic Report

0

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-8-20 19:45:01
| Show all posts
JastPrint service
Reply

Use magic Report

0

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-8-20 20:45:01
| Show all posts
Public Sub ExportToExcel()
        If DataGrid1.VisibleRowCount> 0 Then
            Try
                Dim ds As New DataSet
                ds = DataGrid1.DataSource
                Dim i, j As Integer
                Dim rows As Integer = ds.Tables(0).Rows.Count
                Dim cols As Integer = ds.Tables(0).Columns.Count
                Dim DataArray(rows-1, cols-1) As String
                For i = 0 To rows-1
                    For j = 0 To cols-1
                        If ds.Tables(0).Rows(i).Item(j) Is System.DBNull.Value Then
                        Else
                            DataArray(i, j) = ds.Tables(0).Rows(i).Item(j)
                        End If
                    Next
                Next
                Dim myExcel As Excel.Application = New Excel.Application
                myExcel.Application.Workbooks.Add(True)
                myExcel.Visible = True
                For j = 0 To cols-1
                    myExcel.Cells(1, j + 1) = ds.Tables(0).Columns(j).ColumnName
                Next
                myExcel.Range("A2").Resize(rows, cols).Value = DataArray
            Catch exp As Exception
                MessageBox.Show("Data export failed! Please check whether Excel has been installed", Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning)
            End Try
        Else
            MessageBox.Show("No data!", Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Information)
        End If
    End Sub
Reply

Use magic Report

0

Threads

3

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-8-20 21:15:01
| Show all posts
Dim myExcel As Excel.Application = New Excel.Application

Why does the "Excel.Application" in the previous sentence report an error? ? The system prompts me that the type is not defined. .
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-8-20 22:15:01
| Show all posts
Have you installed Excel? Or installed without references!
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-8-20 22:45:01
| Show all posts
LZ needs to be quoted. Quote EXCEL in the header of the file
Reply

Use magic Report

0

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-8-22 19:15:01
| Show all posts
Http://blog.CSDN.net/conduct 556/archive/2007/03/26/1541891.aspx
Reply

Use magic Report

0

Threads

3

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-8-23 13:00:01
| Show all posts
LZ needs to be quoted. Quote EXCEL in the header of the file

___________________


How do you cite? ? ? ? ?
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list