Jump to content

Export information to excel


AndersonSOS

Recommended Posts

Hello friends I would like information if there is any way to export information in a query, grid or dataset to excel in unigui. I have a report generation screen that is viewed in Fast Report and the client wants to export to excel, but the native delphi options that work with error unit COMobj. If someone has an example I thank you very much

Hello friends I would like information if there is any way to export information in a query, grid or dataset to excel in unigui. I have a report generation screen that is viewed in Fast Report and the client wants to export to excel, but the native delphi options that work with error unit COMobj. If someone has an example I thank you very much

Link to comment
Share on other sites

I installed the SMSExport package and put the components SMEDatasetDataEngine1 and SMExportToXLS but when I enter the screen that includes these components it gives the message:
Raised exception class EConvertError with message 'Can not assign a nil to TFont'

Please any tips?

Thank you

Link to comment
Share on other sites

This is how  I have it set up.

 

The user-visible form has a button, its click creates a filename and invokes the execute method of the SME Export which is on the MainModule.

 
procedure TfrmSQLRes.btn2ExcelClick(Sender: TObject);
 var fname : string;
begin
 fname := makeFilename('.XLS');  // construct an appropriate filename
                                 // NB this is the initial unigui-server copy before sending to users machine
 unimainmodule.SMExportToXLS1.filename := fname;
 unimainmodule.SMExportToXLS1.Execute;
end;
 
The properties of the export component are
object SMExportToXLS1: TSMExportToXLS
    AnimatedStatus = False
    DataFormats.DateOrder = doDMY
    DataFormats.DateSeparator = '/'
    DataFormats.TimeSeparator = ':'
    DataFormats.FourDigitYear = True
    DataFormats.LeadingZerosInDate = True
    DataFormats.ThousandSeparator = ','
    DataFormats.DecimalSeparator = '.'
    DataFormats.CurrencyString = #163
    DataFormats.BooleanTrue = 'True'
    DataFormats.BooleanFalse = 'False'
    DataFormats.UseRegionalSettings = False
    KeyGenerator = 'Some String thast describes your app'
    Options = [soUseFieldNameAsCaption, soColLines, soRowLines, soAutoCloseStatistic]
    TitleStatus = 'Exporting...'
    Statistic.CurrentRowHeight = 0
    OnAfterExecute = SMExportToXLS1AfterExecute
    Columns = <>
    Bands = <>
    DefaultFont.Charset = DEFAULT_CHARSET
    DefaultFont.Color = clWindowText
    DefaultFont.Height = -11
    DefaultFont.Name = 'Arial'
    DefaultFont.Style = []
    DataSet = QRYGen                <<<<<<<  This is the TDataSet we wish to export
    ColumnSource = csDataSet
    FileName = 'c:\exfiles\exp1.xls'    << from memory I think it did not like an initial blank entry?
    AddTitle = True
    CharacterSet = csUnicode
    DetailSources = <>
    ExportStyle.Style = esNormal
    ExportStyle.OddColor = clBlack
    ExportStyle.EvenColor = clBlack
    UserName = 'Harry'
    Left = 168
    Top = 72
  end
 
 
To allow the user to save the result to their own machine use the afterexecute method:
 
procedure TUniMainModule.SMExportToXLS1AfterExecute(Sender: TObject);
begin
 //offer the user the smExportToXLS1 Result
 UniSession.SendFile(smExportToXLS1.filename);
end;
 
 
All the best
Link to comment
Share on other sites

  • 4 years later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...