数据网格导出为 pdf

发布于 2024-07-21 05:26:34 字数 35 浏览 13 评论 0原文

如何将 DBgrid 上显示的数据导出到 pdf 文件?

how can I can export the data shown on a DBgrid to a pdf file?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

柳若烟 2024-07-28 05:26:34

那么,DBGrid 中显示的数据是由附加到该 dbgrid 的数据集提供的,因此将 DBGrid 中的数据导出到 PDF 意味着将数据集中的数据导出到 PDF。

最简单的选择是使用报告工具。 Delphi 有许多不同的报告工具可用,例如 Rave Report、FastReport、Report Builder、QuickReport 等。

此类工具可让您根据数据设计打印报告,并允许您打印报告或将其导出为 HTML、DOC、PDF 等格式。 Rave Report 随 Delphi 一起提供,您可以免费使用它。 我个人喜欢 FastReport 并在我的应用程序中使用它。

另一种选择是,如果你在目标系统上安装了虚拟PDF打印机,你可以选择它作为你的打印机,并使用Delphi的TPrinter类直接在打印机画布上书写,你的虚拟PDF打印机将为你制作一个PDF文件而不是将数据打印在纸上。

第三种选择是使用专门为 PDF 操作而构建的第三方组件,让您可以在应用程序中创建或编辑 PDF 文件。

问候

Well, data being shown in a DBGrid is provided by the dataset attached to that dbgrid, so exporting data in DBGrid to PDF means exporting data in your dataset to PDF.

The easiest option is to use a Reporting tool. There are many different reporting tools available for Delphi e.g. Rave Report, FastReport, Report Builder, QuickReport, and so on.

Such tools let you to design a printing report from your data, and let you to either print the report or export it to formats like HTML, DOC, PDF, and so on. Rave Report is shipped with Delphi and you can use it for free. I personally like FastReport and use it in my applications.

Another option is that, if you have a virtual PDF printer installed on the target system, you can select it as your printer and use Delphi's TPrinter class to write directly on printer canvas, and your virtual PDF printer will make a PDF file for you rather than printing your data on paper.

A third option is to use third-party components which are specifically built for PDF manipulation and let you to create or edit PDF files in your application.

Regards

流星番茄 2024-07-28 05:26:34

Delphi 的 Scalabium 导出套件(包括 2009)支持多种导出格式,包括 PDF 和其他带有 和 的办公格式没有 OLE。 导出组件可与 TDBGrid 和 TDataSet 后代一起使用。

它可以以非可视方式使用,但也提供可配置的导出向导。 我们成功地将它用于从 Delphi 7 到 2009 的应用程序套件迁移。

The Scalabium Export suite for Delphi (including 2009) supports many export formats, including PDF and other office formats with and without OLE. The export components can be used with TDBGrid and TDataSet descendants.

It can be used non-visual but also offers configurable export wizards. We successfully use it in a application suite migration from Delphi 7 to 2009.

她如夕阳 2024-07-28 05:26:34

尝试 EMS 高级数据导出 VCL

http://sqlmanager.net/en/products/tools/advancedexport< /a>

  • 数据(数据集)导出为 17 种最流行的格式:MS Access、MS Excel、MS Word、Open XML 格式、开放文档格式 (ODF)、RTF、HTML、XML、PDF、TXT、DBF、CSV、SYLK、 DIF、LaTeX、SQL 和 Windows 剪贴板
  • Borland Delphi 5-7、2005、2006、CodeGear Delphi 2007、2009 和 Borland C++ Builder 5-6、CodeGear C++ Builder 2007、2009 支持
  • 导出 Unicode 数据。 手动预设导出数据的文本编码(UTF-8、UTF-16/UCS-2、UTF-32/UCS-4、Latin1、Latin2、Latin5、Latin7 等)
  • 保存数据以供将来查看、修改、打印或网络发布
  • 易于使用的向导允许您的最终用户快速导出数据
  • 针对每种数据格式的强大导出选项
  • 100% 原生 Delphi 代码
  • 无需额外的库或软件即可操作
  • 详细的帮助系统和演示应用程序
  • 强大的组件和属性编辑器
  • 设置用户格式分别针对每个字段
  • 多语言支持

try EMS Advanced Data Export VCL

http://sqlmanager.net/en/products/tools/advancedexport

  • Data (Datasets) export into 17 most popular formats: MS Access, MS Excel, MS Word, Open XML Format, Open Document Format (ODF), RTF, HTML, XML, PDF, TXT, DBF, CSV, SYLK, DIF, LaTeX, SQL and Windows Clipboard
  • Borland Delphi 5-7, 2005, 2006, CodeGear Delphi 2007, 2009 and Borland C++ Builder 5-6, CodeGear C++ Builder 2007, 2009 support
  • Export of Unicode data. Manually preset text encoding for exported data (UTF-8, UTF-16/UCS-2, UTF-32/UCS-4, Latin1, Latin2, Latin5, Latin7 and more)
  • Saving data for future viewing, modification, printing or web publication
  • Easy-to-use wizard allows your end-users to export data quickly
  • Powerful export options for each data format
  • 100% native Delphi code
  • No additional libraries or software required to operate
  • Detailed help system and demo application
  • Powerful components and properties editors
  • Setting the user formats for each field separately
  • Multilanguage support
绻影浮沉 2024-07-28 05:26:34

您可以自己迭代数据并使用优秀的导出VCL eDocEngine
来自诺斯替斯。 它还连接到报告工具和其他组件。

You may iterate through the data yourself and use excellent exporting VCL eDocEngine
from Gnostice. It also connects to reporting tools, and other components.

誰ツ都不明白 2024-07-28 05:26:34
Public Sub ExportDataTableToPDF(ByVal dtImport As DataTable)
    Dim strQuery As String = "select er_num,er_shortd,er_longd,er_severity from mv_error"
    Dim doc As New Document(iTextSharp.text.PageSize.LETTER, 10, 10, 42, 35)
    Try

        '====================================================================
        'Dim str As String = DateTime.Now.ToString("yyyyMMddHHmmssff")
        'Dim sWebSettingPath As String = ConfigurationSettings.AppSettings("ExptLoctPath")
        'Dim str1 As String = "E:\ExportPdf_File"
        'Dim WorkingFile As String
        'Dim s As String
        'If (Directory.Exists(sWebSettingPath)) Then
        '    s = "already exists"
        '    WorkingFile = Path.Combine(sWebSettingPath, "" & str & " DataTestData.pdf")
        'Else
        '    Dim ss As String = "C:\ReportPDF"
        '    WorkingFile = Path.Combine(str1, "" & str & " DataTestData.pdf")
        '    Directory.CreateDirectory(ss)
        'End If


        '====================================================================

        'Folder Exists in Particular folder or not cheak ifnot create a folder
        Dim strDateTime As String = DateTime.Now.ToString("yyyyMMddHHmmssff")
        Dim sWebSettingPath As String = ConfigurationSettings.AppSettings("ExptLoctPath")
        Dim str1 As String = "E:\ExportPdf_File"
        Dim WorkingFile As String
        Dim s As String
        If (Directory.Exists(sWebSettingPath)) Then
            s = "already exists"
            WorkingFile = Path.Combine(sWebSettingPath, "" & strDateTime & "_DataTestData.pdf")
        Else
            Dim sWebStingNotPath As String = "C:\ReportPDFTest"
            Directory.CreateDirectory(sWebStingNotPath)
            WorkingFile = Path.Combine(sWebStingNotPath, "" & strDateTime & " DataTestData.pdf")

        End If
        '====================================================================

        Dim fs As New FileStream(WorkingFile, FileMode.Create, FileAccess.Write, FileShare.None)


        'Create Document class object and set its size to letter and give space left, right, Top, Bottom Margin
        PdfWriter.GetInstance(doc, fs)
        ' Dim wri As PdfWriter = PdfWriter.GetInstance(doc, New FileStream("C:\Documents and Settings\lessly.l\Desktop\iTextSharp\Test11.pdf", FileMode.Create))
        doc.Open()
        'Open Document to write
        Dim font8 As Font = FontFactory.GetFont("ARIAL", 7)

        'Write some content
        Dim paragraph As New Paragraph("Team :: CataPult")

        Dim dt As DataTable = dtImport

        If dt IsNot Nothing Then
            'Craete instance of the pdf table and set the number of column in that table
            Dim PdfTable As New PdfPTable(dt.Columns.Count)


            Dim PdfPCell As PdfPCell = Nothing
            Dim pdfrow As PdfPRow = Nothing


            For column As Integer = 0 To dt.Columns.Count - 1

                PdfTable.HeaderRows = dt.Columns.Count


                PdfPCell = New PdfPCell(New Phrase(New Chunk(dt.Columns(column).Caption.ToString().ToUpper, New Font(Font.HELVETICA, 8.0F, Font.BOLD, Color.WHITE))))
                PdfPCell.BackgroundColor = New Color(System.Drawing.ColorTranslator.FromHtml("#66CCFF"))

                PdfTable.AddCell(PdfPCell)

            Next

            'Each Row Values added

            For rows As Integer = 0 To dt.Rows.Count - 1
                For column As Integer = 0 To dt.Columns.Count - 1
                    PdfTable.HeaderRows = dt.Columns.Count
                    PdfPCell = New PdfPCell(New Phrase(New Chunk(dt.Rows(rows)(column).ToString(), font8)))
                    PdfTable.AddCell(PdfPCell)
                Next
            Next

            PdfTable.SpacingBefore = 15.0F
            ' Give some space after the text or it may overlap the table
            doc.Add(paragraph)
            ' add paragraph to the document
            ' add pdf table to the document
            doc.Add(PdfTable)

        End If
    Catch docEx As DocumentException
        'handle pdf document exception if any
    Catch ioEx As IOException
        ' handle IO exception
    Catch ex As Exception
        ' ahndle other exception if occurs
    Finally
        'Close document and writer

        doc.Close()
    End Try
End Sub
Public Sub ExportDataTableToPDF(ByVal dtImport As DataTable)
    Dim strQuery As String = "select er_num,er_shortd,er_longd,er_severity from mv_error"
    Dim doc As New Document(iTextSharp.text.PageSize.LETTER, 10, 10, 42, 35)
    Try

        '====================================================================
        'Dim str As String = DateTime.Now.ToString("yyyyMMddHHmmssff")
        'Dim sWebSettingPath As String = ConfigurationSettings.AppSettings("ExptLoctPath")
        'Dim str1 As String = "E:\ExportPdf_File"
        'Dim WorkingFile As String
        'Dim s As String
        'If (Directory.Exists(sWebSettingPath)) Then
        '    s = "already exists"
        '    WorkingFile = Path.Combine(sWebSettingPath, "" & str & " DataTestData.pdf")
        'Else
        '    Dim ss As String = "C:\ReportPDF"
        '    WorkingFile = Path.Combine(str1, "" & str & " DataTestData.pdf")
        '    Directory.CreateDirectory(ss)
        'End If


        '====================================================================

        'Folder Exists in Particular folder or not cheak ifnot create a folder
        Dim strDateTime As String = DateTime.Now.ToString("yyyyMMddHHmmssff")
        Dim sWebSettingPath As String = ConfigurationSettings.AppSettings("ExptLoctPath")
        Dim str1 As String = "E:\ExportPdf_File"
        Dim WorkingFile As String
        Dim s As String
        If (Directory.Exists(sWebSettingPath)) Then
            s = "already exists"
            WorkingFile = Path.Combine(sWebSettingPath, "" & strDateTime & "_DataTestData.pdf")
        Else
            Dim sWebStingNotPath As String = "C:\ReportPDFTest"
            Directory.CreateDirectory(sWebStingNotPath)
            WorkingFile = Path.Combine(sWebStingNotPath, "" & strDateTime & " DataTestData.pdf")

        End If
        '====================================================================

        Dim fs As New FileStream(WorkingFile, FileMode.Create, FileAccess.Write, FileShare.None)


        'Create Document class object and set its size to letter and give space left, right, Top, Bottom Margin
        PdfWriter.GetInstance(doc, fs)
        ' Dim wri As PdfWriter = PdfWriter.GetInstance(doc, New FileStream("C:\Documents and Settings\lessly.l\Desktop\iTextSharp\Test11.pdf", FileMode.Create))
        doc.Open()
        'Open Document to write
        Dim font8 As Font = FontFactory.GetFont("ARIAL", 7)

        'Write some content
        Dim paragraph As New Paragraph("Team :: CataPult")

        Dim dt As DataTable = dtImport

        If dt IsNot Nothing Then
            'Craete instance of the pdf table and set the number of column in that table
            Dim PdfTable As New PdfPTable(dt.Columns.Count)


            Dim PdfPCell As PdfPCell = Nothing
            Dim pdfrow As PdfPRow = Nothing


            For column As Integer = 0 To dt.Columns.Count - 1

                PdfTable.HeaderRows = dt.Columns.Count


                PdfPCell = New PdfPCell(New Phrase(New Chunk(dt.Columns(column).Caption.ToString().ToUpper, New Font(Font.HELVETICA, 8.0F, Font.BOLD, Color.WHITE))))
                PdfPCell.BackgroundColor = New Color(System.Drawing.ColorTranslator.FromHtml("#66CCFF"))

                PdfTable.AddCell(PdfPCell)

            Next

            'Each Row Values added

            For rows As Integer = 0 To dt.Rows.Count - 1
                For column As Integer = 0 To dt.Columns.Count - 1
                    PdfTable.HeaderRows = dt.Columns.Count
                    PdfPCell = New PdfPCell(New Phrase(New Chunk(dt.Rows(rows)(column).ToString(), font8)))
                    PdfTable.AddCell(PdfPCell)
                Next
            Next

            PdfTable.SpacingBefore = 15.0F
            ' Give some space after the text or it may overlap the table
            doc.Add(paragraph)
            ' add paragraph to the document
            ' add pdf table to the document
            doc.Add(PdfTable)

        End If
    Catch docEx As DocumentException
        'handle pdf document exception if any
    Catch ioEx As IOException
        ' handle IO exception
    Catch ex As Exception
        ' ahndle other exception if occurs
    Finally
        'Close document and writer

        doc.Close()
    End Try
End Sub
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文