⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mxexport.pas

📁 Export dbgrid to other doc
💻 PAS
📖 第 1 页 / 共 5 页
字号:
// ****************************************************************************
// * Export components for Delphi.
// ****************************************************************************
// * Copyright 2001-2008, Bitvad醩z Kft. All Rights Reserved.
// ****************************************************************************
// * This component can be freely used and distributed in commercial and
// * private environments, provied this notice is not modified in any way.
// ****************************************************************************
// * Feel free to contact me if you have any questions, comments or suggestions
// * at support@maxcomponents.net
// ****************************************************************************
// * Web page: www.maxcomponents.net
// ****************************************************************************
// * Description:
// *
// * The TmxExport is a 100% native VCL component to export tables, queries,
// * stringlists, etc. to different file formats.
// *
// ****************************************************************************

Unit mxExport;

Interface

{$I MAX.INC}

Uses
  Windows,
  Messages,
  SysUtils,
  Classes,
  Stdctrls,
  Comctrls,
  Graphics,
  Controls,
  Forms,
  Dialogs,
  Extctrls,
  ShellAPI,
  Clipbrd,
  mxNativeExcel,
{$IFNDEF NATIVEEXCEL_STANDARD}
  mxNativeExcel_Types,
{$ENDIF}
{$IFDEF DELPHI6_UP}
  Variants,
{$ENDIF}
  DB,
  grids,
  DBGrids,
  mxExportSelect,
  mxExportProgress;

{MXEXPORT.RES}// *** REMOVED IN 2.34 ***

// ************************************************************************
// ************************************************************************
// ************************************************************************

Const

  mxExportVersion = $0226;

// ************************************************************************
// ************************************************************************
// ************************************************************************

Resourcestring

  rsExportingStrings = 'Exporting Strings';
  rsExportingAny = 'Exporting...';
  rsExportingDataSet = 'Exporting DataSet';
  rsExportingListView = 'Exporting ListView';
  rsExportingDBGrig = 'Exporting DBGrid';
  rsExportingStringGrig = 'Exporting String Grid';
  rsFieldIsUnknown = '** UNKNOWN **';
  rsFieldIsBinary = '** BINARY **';
  rsNullValue = '** NULL **';
  rsTrue = 'True';
  rsFalse = 'False';
  rsExportCaption = 'Export';
  rsExport = '&Export';
  rsCancel = '&Cancel';
  rsCreated = 'Created:';
  rsProcessing = 'Processing...';
  rsSelectFormat = 'E&xport formats:';
  rsCopiedToClipboard = 'Data was copied to clipboard!';
  rsExportToFile = 'Export &to file';
  rsViewOnly = '&View only';
  rsTempPrefix = 'MX';
  rsStringGridHeader = 'Name %d';

  // *** Export types ***

  rsSelectHTML = 'HTML';
  rsSelectWord = 'Microsoft Word';
  rsSelectExcel = 'Microsoft Excel';
  rsSelectText = 'Text';
  rsSelectRTF = 'Rich Text';
  rsSelectComma = 'Comma-Separated Text';
  rsSelectTab = 'Tab-Separated Text';
  rsSelectDIF = 'Data Interchange Format';
  rsSelectSYLK = 'SYLK Format';
  rsSelectClipboard = 'Clipboard';

     // *** HTML Color Templates ***

  rsDefaultFontFace = 'Arial,Helvetica';

  rsStandard_BGCOLOR = '$00FFFFFF';
  rsStandard_TEXT = '$00000000';
  rsStandard_LINK = '$000000FF';
  rsStandard_ALINK = '$00FF0000';
  rsStandard_VLINK = '$00FFFF00';
  rsStandard_HEAD_BGCOLOR = '$00336699';
  rsStandard_HEAD_FONT_COLOR = '$00FFFFFF';
  rsStandard_TABLE_BGCOLOR = '$00FFFFCF';
  rsStandard_TABLE_ODD_BGCOLOR = '$00FFFFFF';
  rsStandard_TABLE_FONT_COLOR = '$00000000';
     // *** RTF cannot handle high color backgrounds ***
  rsStandard_RTF_HEAD_BGCOLOR = '$00800000';
  rsStandard_RTF_TABLE_BGCOLOR = '$00FFFFFF';
  rsStandard_RTF_TABLE_ODD_BGCOLOR = '$0000FF80';

  rsBW_BGCOLOR = '$00FFFFFF';
  rsBW_TEXT = '$00000000';
  rsBW_LINK = '$00AAAAAA';
  rsBW_ALINK = '$00BBBBBB';
  rsBW_VLINK = '$00DDDDDD';
  rsBW_HEAD_BGCOLOR = '$00000000';
  rsBW_HEAD_FONT_COLOR = '$00FFFFFF';
  rsBW_TABLE_BGCOLOR = '$00FFFFFF';
  rsBW_TABLE_ODD_BGCOLOR = '$00F3F3F3';
  rsBW_TABLE_FONT_COLOR = '$00000000';

  rsClassic_BGCOLOR = '$00339966';
  rsClassic_TEXT = '$00000000';
  rsClassic_LINK = '$000066CC';
  rsClassic_ALINK = '$00FF0000';
  rsClassic_VLINK = '$00923FC1';
  rsClassic_HEAD_BGCOLOR = '$00000000';
  rsClassic_HEAD_FONT_COLOR = '$00FF0000';
  rsClassic_TABLE_BGCOLOR = '$00006BCE';
  rsClassic_TABLE_ODD_BGCOLOR = '$00007AEC';
  rsClassic_TABLE_FONT_COLOR = '$00FFFFFF';
     // *** RTF cannot handle high color backgrounds ***
  rsClassic_RTF_TABLE_FONT_COLOR = '$00000000';
  rsClassic_RTF_HEAD_FONT_COLOR = '$000000FF';
  rsClassic_RTF_HEAD_BGCOLOR = '$00000000';
  rsClassic_RTF_TABLE_BGCOLOR = '$00FF0000';
  rsClassic_RTF_TABLE_ODD_BGCOLOR = '$00FF8080';

  rsColorful_BGCOLOR = '$00339966';
  rsColorful_TEXT = '$00000000';
  rsColorful_LINK = '$000066CC';
  rsColorful_ALINK = '$00FF0000';
  rsColorful_VLINK = '$00923FC1';
  rsColorful_HEAD_BGCOLOR = '$00CC0033';
  rsColorful_HEAD_FONT_COLOR = '$00FFFFFF';
  rsColorful_TABLE_BGCOLOR = '$00FFFFFF';
  rsColorful_TABLE_ODD_BGCOLOR = '$00FAF100';
  rsColorful_TABLE_FONT_COLOR = '$00FFFFFF';
     // *** RTF cannot handle high color backgrounds ***
  rsColorful_RTF_TABLE_FONT_COLOR = '$00000000';
  rsColorful_RTF_HEAD_BGCOLOR = '$000000FF';
  rsColorful_RTF_TABLE_BGCOLOR = '$00FFFFFF';
  rsColorful_RTF_TABLE_ODD_BGCOLOR = '$0000FF80';

  rsGray_BGCOLOR = '$00FFFFFF';
  rsGray_TEXT = '$00000000';
  rsGray_LINK = '$000000FF';
  rsGray_ALINK = '$00FF0000';
  rsGray_VLINK = '$00FFFF00';
  rsGray_HEAD_BGCOLOR = '$00808080';
  rsGray_HEAD_FONT_COLOR = '$00FFFFFF';
  rsGray_TABLE_BGCOLOR = '$00FFFFFF';
  rsGray_TABLE_ODD_BGCOLOR = '$00EEEEEE';
  rsGray_TABLE_FONT_COLOR = '$00000000';
     // *** RTF cannot handle high color backgrounds ***
  rsGray_RTF_HEAD_BGCOLOR = '$00808080';
  rsGray_RTF_TABLE_BGCOLOR = '$00FFFFFF';
  rsGray_RTF_TABLE_ODD_BGCOLOR = '$0080FF80';

  rsMsMoney_BGCOLOR = '$00FFFFFF';
  rsMsMoney_TEXT = '$00000000';
  rsMsMoney_LINK = '$000000FF';
  rsMsMoney_ALINK = '$00FF0000';
  rsMsMoney_VLINK = '$00AABBAA';
  rsMsMoney_HEAD_BGCOLOR = '$00CEC6B5';
  rsMsMoney_HEAD_FONT_COLOR = '$00000000';
  rsMsMoney_TABLE_BGCOLOR = '$00DEE7DE';
  rsMsMoney_TABLE_ODD_BGCOLOR = '$00FFFBF0';
  rsMsMoney_TABLE_FONT_COLOR = '$00000080';

  rsOlive_BGCOLOR = '$00FFFFFF';
  rsOlive_TEXT = '$005F605F';
  rsOlive_LINK = '$000000FF';
  rsOlive_ALINK = '$00FF0000';
  rsOlive_VLINK = '$00FFFF00';
  rsOlive_HEAD_BGCOLOR = '$00CFC890';
  rsOlive_HEAD_FONT_COLOR = '$00000000';
  rsOlive_TABLE_BGCOLOR = '$00FFFFFF';
  rsOlive_TABLE_ODD_BGCOLOR = '$00FFFFCF';
  rsOlive_TABLE_FONT_COLOR = '$00000000';

  rsDark_BGCOLOR = '$00317676';
  rsDark_TEXT = '$00FFE760';
  rsDark_LINK = '$00DDE760';
  rsDark_ALINK = '$00FFFF00';
  rsDark_VLINK = '$00CCCC39';
  rsDark_HEAD_BGCOLOR = '$003A9393';
  rsDark_HEAD_FONT_COLOR = '$00FFFFFF';
  rsDark_TABLE_BGCOLOR = '$00004040';
  rsDark_TABLE_ODD_BGCOLOR = '$00000000';
  rsDark_TABLE_FONT_COLOR = '$00FFFFFF';

     // *** Default file filters ***

  rsSaveTitle = 'Save document';
  rsFilterHTML = 'HTML Documents';
  rsFilterExcel = 'Excel Files';
  rsFilterWord = 'Word Documents';
  rsFilterText = 'Text Files';
  rsFilterComma = 'CSV (Comma delimited)';
  rsFilterTab = 'Text (Tab delimited)';
  rsFilterRTF = 'Rich Text Format';
  rsFilterDIF = 'Data Interchange Format';
  rsFilterSYLK = 'SYLK Files';

Type
// ************************************************************************
// ************************************************************************
// ************************************************************************

  TmxValues = Array Of Variant;

  TmxExportHTMLOptions = (
    hoShowGridLines,
    hoBoldHeaders,
    hoAutoLink,
    hoOddRowColoring,
    hoDisplayTitle );

  TmxExportHTMLOptionSet = Set Of TmxExportHTMLOptions;

  TmxExportRTFOptions = (
    roShowGridLines,
    roOddRowColoring );

  TmxExportRTFOptionSet = Set Of TmxExportRTFOptions;

  TmxExportExcelOptions = (
    reCellsAsText,
    reSetColumnWidths
{$IFDEF NATIVEEXCEL_STANDARD}
    ,
    reSetMargins,
    reUseBorders
{$ENDIF}
    );

  TmxExportExcelOptionSet = Set Of TmxExportExcelOptions;

{$IFDEF NATIVEEXCEL_STANDARD}
  TmxExcelVersion = (
    xls21,
    xls30,
    xls40,
    xls50 );
{$ENDIF}

  TmxExportOptions = (
    xoClipboardMessage,
    xoExportInvisibles,
    xoFooterLine,
    xoHeaderLine,
    xoRowNumbers,
    xoShowExportDate,
    xoShowHeader,
    xoShowProgress,
    xoSelectedRowsOnly,
    xoTruncate,
    xoUseAlignments );

  TmxExportOptionSet = Set Of TmxExportOptions;

  TmxExportType = (
    xtHTML,
    xtExcel,
    xtWord,
    xtTXT,
    xtCSV,
    xtTAB,
    xtRTF,
    xtDIF,
    xtSYLK,
    xtClipboard );

  TmxExportTypeSet = Set Of TmxExportType;

  TmxExportError = (
    xeInvalidFileName,
    xeFileExist,
    xeComponentIsNull,
    xeGeneralExportError,
    xeUserCancelled );

  TmxExportStyle = (
    xsFile,
    xsView );

  TmxHTMLColorTemplate = (
    ctStandard,
    ctBW,
    ctClassic,
    ctColorful,
    ctDark,
    ctGray,
    ctMSMoney,
    ctOlive,
    ctCustom );

  TmxRTFColorTemplate = (
    rtStandard,
    rtClassic,
    rtColorful,
    rtGray,
    rtCustom );

  TmxHTMLFont = (
    hfDefault,
    hfTable );

  TmxHTMLColor = (
    hcALINK,
    hcBGCOLOR,
    hcLINK,
    hcTEXT,
    hcVLINK,
    hcHEAD_BGCOLOR,
    hcHEAD_FONT_COLOR,
    hcTABLE_BGCOLOR,
    hcTABLE_ODD_BGCOLOR,
    hcTABLE_FONT_COLOR );

  TmxRTFColor = (
    rcTEXT,
    rcHEAD_FONT_COLOR,
    rcTABLE_FONT_COLOR,
    rcTABLE_BGCOLOR,
    rcTABLE_HEAD_BGCOLOR,
    rcTABLE_ODD_BGCOLOR );

  TmxHTMLExtension = (
    exHTM,
    exHTML );

  TmxFieldAlignment = (
    faDefault,
    faLeft,
    faRight,
    faCenter );

// ************************************************************************
// ************************************************************************
// ************************************************************************

  TEventOnGetHeader = Procedure( Sender: TObject; RecordCount: Cardinal; Var Header: String ) Of Object;
  TEventOnGetFooter = Procedure( Sender: TObject; RecordCount: Cardinal; Var Footer: String ) Of Object;
  TEventOnError = Procedure( Sender: TObject; Error: TmxExportError ) Of Object;
  TEventOnExport = Procedure( Sender: TObject; Current, Total: Cardinal; Values: TmxValues; Var CanExport: Boolean ) Of Object;
  TEventOnGetExtension = Procedure( Sender: TObject; Var Extension: String ) Of Object;
  TEventOnFileExist = Procedure( Sender: TObject; OutputFileName: String; Var CanOverWrite: Boolean ) Of Object;
  TEventOnGetExportInfo = Procedure( Sender: TObject; Var RecordCount: Cardinal; Var FieldCount: Integer ) Of Object;
  TEventOnGetFieldLength = Procedure( Sender: TObject; Index: Integer; Var FieldLength: Integer ) Of Object;
  TEventOnGetFieldName = Procedure( Sender: TObject; Index: Integer; Var FieldName: String ) Of Object;
  TEventOnGetExportData = Procedure( Sender: TObject; Index: Integer; Var Data: TmxValues ) Of Object;

// ************************************************************************
// ************************************************************************
// ************************************************************************

  TmxDocumentFilter = Class( TPersistent )
  Private

    FHTML: String;
    FExcel: String;
    FWord: String;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -