Dbgrideh's ingress and egress

Source: Internet
Author: User

{*************************************** ****************}
{}
{Export tdbgrideh data}
{}
{Copyright (c) 2007 Yunan studio}
{}
{*************************************** ****************}

Unit uexport;

Interface

Uses
Dbgridehimpexp, dbgrideh, sysutils, dialogs, comobj, ActiveX, variants, DB,
Formwait, windows, graphics;

Procedure expdbgrideh (Grid: tdbgrideh; openexcel: Boolean = true );
Procedure impdbgrideh (Grid: tdbgrideh );

Implementation

// ================================================ ==========================================================
// Added the progress bar display by cxg 10:08:09
// ================================================ ==========================================================

Procedure impdbgrideh (Grid: tdbgrideh );
VaR
Opendialog: topendialog;
Begin
If (not assigned (GRID) or (not grid. datasource. dataset. Active) then
Exit;
Opendialog: = topendialog. Create (NiL );
Try
Opendialog. filter: = 'text file | *. txt ';
Opendialog. filterindex: = 1;
If opendialog. Execute then
Begin
Showwaittext ('Please wait ');
Loaddbgridehfromimportfile (tdbgridehimportastext,
Grid, opendialog. filename, true );
End;
Finally
Opendialog. Free;
Showwaittext ();
End;
End;

Procedure expdbgrideh (Grid: tdbgrideh; openexcel: Boolean = true );
VaR
Expclass: tdbgridehexportclass;
Ext: string;
Savedialog: tsavedialog;
Excelapp: variant;
Begin
If (not assigned (GRID) or (not grid. datasource. dataset. Active)
Or (grid. datasource. dataset. isempty) Then exit;
Savedialog: = tsavedialog. Create (NiL );
Try
Savedialog. filename: = 'file 1 ';
Savedialog. filter: = 'excel spreadsheet | *. xls | HTML webpage | *. htm | text file | *. txt | csv'
+ '| *. CSV | Rich RTF Text | *. rtf ';
Savedialog. filterindex: = 1;
If savedialog. Execute then
Begin
Showwaittext ('Please wait ');
Try
Case savedialog. filterindex
1: Begin expclass: = tdbgridehexportasxls; Ext: = 'xls '; end;
2: Begin expclass: = tdbgridehexportashtml; Ext: = 'htm'; end;
3: Begin expclass: = tdbgridehexportastext; Ext: = 'txt '; end;
4: Begin expclass: = tdbgridehexportascsv; Ext: = 'csv'; end;
5: Begin expclass: = tdbgridehexportasrtf; Ext: = 'text'; end;
Else
Expclass: = nil; Ext: = '';
End;
If expclass <> nil then
Begin
If uppercase (copy (savedialog. filename,
Length (savedialog. filename)-2, 3) <> uppercase (EXT) then
Savedialog. filename: = savedialog. filename + '.' + ext;
Savedbgridehtoexportfile (expclass, grid, savedialog. filename, true );

If savedialog. filterindex = 1 then
Begin
If openexcel then
Begin
Excelapp: = createoleobject ('excel. application ');
Excelapp. Visible: = true;
Excelapp. workbooks. Add;
Excelapp. workbooks. Open (savedialog. filename );
Excelapp. activesheet. pagesetup. printgridlines: = true;
// Excelapp. activesheet. pagesetup. centerheader: = 'yunnan studio ';
Excelapp. activesheet. pagesetup. centerfooter: = 'page & P ';
Excelapp. activesheet. Rows [1]. Font. Name: = 'body ';
Excelapp. activesheet. Rows [1]. Font. Color: = clblue;
// Excelapp. activesheet. Rows [1]. Font. Bold: = true;
End;
End;
// The Excel column starts from 1, and the dbgrideh column starts from 0
// The column width in Excel is measured in characters, and the column width in dbgrideh is different.
End;
Finally
Showwaittext ();
End;
End;
Finally
Freeandnil (savedialog );
End;
End;

End.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.