DBgrid に表示されているデータを PDF ファイルにエクスポートするにはどうすればよいですか?
5 に答える
DBGridに表示されるデータは、そのdbgridに接続されたデータセットによって提供されるため、DBGridのデータをPDFにエクスポートすることは、データセットのデータをPDFにエクスポートすることを意味します。
最も簡単なオプションは、レポートツールを使用することです。Delphiで使用できるさまざまなレポートツールがあります。たとえば、Rave Report、FastReport、Report Builder、QuickReportなどです。
このようなツールを使用すると、データから印刷レポートを設計し、レポートを印刷するか、HTML、DOC、PDFなどの形式にエクスポートすることができます。Rave ReportはDelphiに同梱されており、無料で使用できます。私は個人的にFastReportが好きで、アプリケーションで使用しています。
もう1つのオプションは、ターゲットシステムに仮想PDFプリンターがインストールされている場合、それをプリンターとして選択し、DelphiのTPrinterクラスを使用してプリンターキャンバスに直接書き込むことができます。仮想PDFプリンターは、代わりにPDFファイルを作成します。データを紙に印刷するよりも。
3番目のオプションは、PDF操作用に特別に構築されたサードパーティコンポーネントを使用して、アプリケーションでPDFファイルを作成または編集できるようにすることです。
よろしく
Delphi 用のScalabium Export スイート (2009 を含む) は、OLE の有無にかかわらず、PDF やその他のオフィス形式を含む、多くのエクスポート形式をサポートしています。エクスポート コンポーネントは、TDBGrid および TDataSet の子孫で使用できます。
非ビジュアルで使用できますが、構成可能なエクスポート ウィザードも提供します。Delphi 7 から 2009 へのアプリケーション スイートの移行で、これをうまく使用しています。
EMS Advanced Data Export VCL を試す
http://sqlmanager.net/en/products/tools/advancedexport
- データ (データセット) を 17 の最も一般的な形式にエクスポート: MS Access、MS Excel、MS Word、Open XML 形式、Open Document Format (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 など)
- 将来の表示、変更、印刷、または Web 公開のためのデータの保存
- 使いやすいウィザードにより、エンドユーザーはデータをすばやくエクスポートできます
- 各データ形式の強力なエクスポート オプション
- 100% ネイティブの Delphi コード
- 操作に追加のライブラリやソフトウェアは不要
- 詳細なヘルプ システムとデモ アプリケーション
- 強力なコンポーネントおよびプロパティ エディター
- 各フィールドの個別のユーザー フォーマットの設定
- 多言語サポート
自分でデータを反復処理し、Gnostice からの優れたエクスポート VCL eDocEngine を使用できます。また、レポート ツールやその他のコンポーネントにも接続します。
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