تقييم الموضوع :
  • 0 أصوات - بمعدل 0
  • 1
  • 2
  • 3
  • 4
  • 5
تعديل كود تصدير الداتاغريد الى Pdf
#3
يعطيك الصحة أخي ، تتبعت الفيديو لكن لم ينجح معي نقل الكتابة من التكست بكس الى ملف الـ PDF

 هذا نفس كود الفيديو ، فقط في الفيديو يستعمل تكست بوكس 2 مسار الملف المصدر و انا في مشروعي لا استعمل تكست بوكس 2 الملف انا اختار اين احفضه ، هل من الممكن تصحيح الكود  بارك الله فيك أو من احد الاخوة جزاهم الله كل خير


كود :
Imports System.Data.Odbc ' import namespaces ODBC class
Imports iTextSharp.text ' import namespaces .net pdf library
Imports iTextSharp.text.pdf
Imports System.IO
Public Class Form1
   Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
       openconnection() ' open our connection
       Dim da As OdbcDataAdapter ' declaration data adapter
       Dim dt As DataTable ' declaration data table
       da = New OdbcDataAdapter("SELECT idsiswa,nama,nis,tempatlahir,alamat FROM biodata", connection)
       dt = New DataTable
       da.Fill(dt)
       DataGridView1.DataSource = dt ' bind data table into datagridview
       DataGridView1.Refresh()
       connection.Close() ' close our connection
       da.Dispose()
       'configuration fo save file dialog
       SaveFileDialog1.FileName = ""
       SaveFileDialog1.Filter = "PDF (*.pdf)|*.pdf"
       TextBox1.Text = "" ' for title
       TextBox2.Text = "" ' for file locations
   End Sub
   Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
       SaveFileDialog1.FileName = ""
       If SaveFileDialog1.ShowDialog = DialogResult.OK Then
           ' declaration textbox2 to save file dialog name
           TextBox2.Text = SaveFileDialog1.FileName
       End If
   End Sub
   Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
       ' you must import itextsharp namespace into our form
       ' download links is available in the descriptions
       Dim Paragraph As New Paragraph ' declaration for new paragraph
       Dim PdfFile As New Document(PageSize.A4, 40, 40, 40, 20) ' set pdf page size
       PdfFile.AddTitle(TextBox1.Text) ' set our pdf title
       Dim Write As PdfWriter = PdfWriter.GetInstance(PdfFile, New FileStream(TextBox2.Text, FileMode.Create))
       PdfFile.Open()

       ' declaration font type
       Dim pTitle As New Font(iTextSharp.text.Font.FontFamily.TIMES_ROMAN, 14, iTextSharp.text.Font.BOLD, BaseColor.BLACK)
       Dim pTable As New Font(iTextSharp.text.Font.FontFamily.TIMES_ROMAN, 12, iTextSharp.text.Font.NORMAL, BaseColor.BLACK)

       ' insert title into pdf file
       Paragraph = New Paragraph(New Chunk(TextBox1.Text, pTitle))
       Paragraph.Alignment = Element.ALIGN_CENTER
       Paragraph.SpacingAfter = 5.0F

       ' set and add page with current settings
       PdfFile.Add(Paragraph)

       ' create data into table
       Dim PdfTable As New PdfPTable(DataGridView1.Columns.Count)
       ' setting width of table
       PdfTable.TotalWidth = 500.0F
       PdfTable.LockedWidth = True

       Dim widths(0 To DataGridView1.Columns.Count - 1) As Single
       For i As Integer = 0 To DataGridView1.Columns.Count - 1
           widths(i) = 1.0F
       Next

       PdfTable.SetWidths(widths)
       PdfTable.HorizontalAlignment = 0
       PdfTable.SpacingBefore = 5.0F

       ' declaration pdf cells
       Dim pdfcell As PdfPCell = New PdfPCell

       ' create pdf header
       For i As Integer = 0 To DataGridView1.Columns.Count - 1

           pdfcell = New PdfPCell(New Phrase(New Chunk(DataGridView1.Columns(i).HeaderText, pTable)))
           ' alignment header table
           pdfcell.HorizontalAlignment = PdfPCell.ALIGN_LEFT
           ' add cells into pdf table
           PdfTable.AddCell(pdfcell)
       Next

       ' add data into pdf table
       For i As Integer = 0 To DataGridView1.Rows.Count - 2

           For j As Integer = 0 To DataGridView1.Columns.Count - 1
               pdfcell = New PdfPCell(New Phrase(DataGridView1(j, i).Value.ToString(), pTable))
               PdfTable.HorizontalAlignment = PdfPCell.ALIGN_LEFT
               PdfTable.AddCell(pdfcell)
           Next
       Next
       ' add pdf table into pdf document
       PdfFile.Add(PdfTable)
       PdfFile.Close() ' close all sessions

       ' show message if hasben exported
       MessageBox.Show("PDF format success exported !", "Informations", MessageBoxButtons.OK, MessageBoxIcon.Information)

   End Sub

   Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
       Me.Close()
   End Sub
------------------------
منكم أتعلم
------------------------

الرد }}}
تم الشكر بواسطة:


الردود في هذا الموضوع
RE: تعديل كود تصدير الداتاغريد الى Pdf - بواسطة sofiane-phy - 19-12-19, 12:11 AM

المواضيع المحتمل أن تكون متشابهة .
الموضوع : الكاتب الردود : المشاهدات : آخر رد
  كيف يمكن تصدير ascx كملف dll justforit 1 136 06-12-25, 12:33 AM
آخر رد: salamandal
  [VB.NET] مساعدة تعديل على الكود ZEEN4ZEEN 2 215 08-10-25, 02:20 PM
آخر رد: salamandal
  تصدير البيانات إلى ملف RTF مصمم هاوي 4 832 15-08-25, 04:13 PM
آخر رد: أبو خالد الشكري
  تعديل كود تحديث البيانات مصمم هاوي 1 788 26-04-25, 06:07 PM
آخر رد: مصمم هاوي
  تعديل على استدعاء الدرجات حسب الاختيار مصمم هاوي 11 1,010 15-04-25, 06:16 PM
آخر رد: princelovelorn
  ارجو تعديل الكود بواستطة الاجراء المخزن new_programer 3 678 03-04-25, 02:44 PM
آخر رد: princelovelorn
  كيف اضف عدد النسخ فى كود تصدير التقرير الى PDF new_programer 1 368 17-03-25, 12:26 AM
آخر رد: princelovelorn
  تعديل مسار مكان حفظ النسخة الاحتياطية مصمم هاوي 6 823 02-03-25, 01:06 PM
آخر رد: atefkhalf2004
  محتاج تعديل على كود الحذف new_programer 2 653 17-02-25, 06:50 PM
آخر رد: new_programer
  ارجو تعديل الكود جلب البيانات عن طريق اجراء مخزن - مرفق مثال new_programer 0 621 05-02-25, 01:51 AM
آخر رد: new_programer

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


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