Bonjour, voilà mon problème : La référence d'objet n'est pas définie à une instance d'un objet.
Je suis bloqué, j'essais de recopier mon datagridview dans un pdf voilà mon code :
déclaration :
Lee reste :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11 Imports MySql.Data.MySqlClient Imports MySql.Data.Types Imports System Imports System.Data Imports System.Data.OleDb Imports System.Text Imports System.IO Imports iTextSharp.text.pdf Imports iTextSharp.text Imports iTextSharp.text.html Imports iTextSharp.text.html.simpleparser
Pouvez-vous m'aider svp, je ne comprend pas ce type d'erreur.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click Dim pdfTable As New PdfPTable(Dtgdv_ticket.ColumnCount) pdfTable.DefaultCell.Padding = 3 pdfTable.WidthPercentage = 30 pdfTable.HorizontalAlignment = Element.ALIGN_LEFT pdfTable.DefaultCell.BorderWidth = 1 For Each column As DataGridViewColumn In Dtgdv_ticket.Columns Dim cell As New PdfPCell(New Phrase(column.HeaderText)) cell.BackgroundColor = New iTextSharp.text.BaseColor(240, 240, 240) pdfTable.AddCell(cell) Next For Each row As DataGridViewRow In Dtgdv_ticket.Rows For Each cell As DataGridViewCell In row.Cells pdfTable.AddCell(cell.Value.ToString()) Next Next Dim folderPath As String = "C:\Users\degecom\Desktop\test1\test.pdf" If Not Directory.Exists(folderPath) Then Directory.CreateDirectory(folderPath) End If Using stream As New FileStream(folderPath & "DataGridViewExport.pdf", FileMode.Create) Dim pdfDoc As New Document(PageSize.A2, 10.0F, 10.0F, 10.0F, 0.0F) PdfWriter.GetInstance(pdfDoc, stream) pdfDoc.Open() pdfDoc.Add(pdfTable) pdfDoc.Close() stream.Close() End Using AxAcroPDF1.src = "C:\Users\degecom\Desktop\test1\test.pdf" End Sub
La ligne de l'erreur est à la n*16
Partager