PB à toute heure et à tout moment. (à parcourir avec modération)

Le forum (ô combien francophone) des utilisateurs de Powerbuilder.

Recherche rapide

Annonce

Certaines rubriques, dont des cours, sont uniquement visibles par les membres du forum ^^.
Dans la rubrique Liens & Références, vous avez accès à un sommaire de téléchargement, profitez-en !
Il existe maintenant un nouveau TOPIC "Votre CV en Ligne" accessible uniquement par demande.

#1 12-04-2008 09:32:28

erasorz  
Admin
Lieu: Babylone
Date d'inscription: 23-11-2006
Messages: 5121
Pépites: 97,197
Banque: 2,147,483,647

[SOURCE] PB 11.1 WEBFORM - Save a datawindow to Excel and email as an attachment

Source : CodeXchange

This sample code shows how to save a datawindow grid using DW2XLS and email it as an attachment.  DW2XLS is very nice as it saves the computed fields (which a normal dw_1.saveas() does not.  The people at DW2XLS were nice enough to help me with a parameter to turn off the progress bar that was not working on the WEBFORM.  Once the file is saved (with the help of helper.dll) to the virtual file system, you can email the excel file as an attachment via SMTP.

Here is where you can get helper.dll and the source code (written by Scrinivas Jonela at Sybase):

http://65.213.119.67/helper/helper.zip

Here is where you can get DW2XLS (but you have to pay for it (well worth it, I think -- They say that PB 11.0 is not supported, so be careful -- but it does work).

http://desta.com.ua/dw2xls/

Here is the sample code:

Code: pb

mle_1.text = "PROCESSING...PLEASE WAIT..."

string user
user = left(email, (pos(email, "@")-1))

string filename

#if defined PBWEBFORM then
  
filename = Helper.PBInternal.ConvertVFS2ActualPath("OnDemand Report For-" + selectedaccount + "-" + user + ".xls")
  
integer li_ret
  
  n_dwr_service_parm lnv_parm
  lnv_parm = Create n_dwr_service_parm
  lnv_parm.ib_show_progress = False
  if allaccounts = 'F' then
    li_ret = uf_save_dw_as_excel_parm(dw_1, filename, lnv_parm)
  else
    li_ret = uf_save_dw_as_excel_parm(dw_2, filename, lnv_parm)
  end if

  if li_ret = 1 then
      
    string ToAddress2
    ToAddress2 = email
    
    string bodytext
    bodytext = 'Dear Customer, ' + '~r~n' + '~r~n' + 'Please find attached the requested trip report in Microsoft Excel format.' + '~r~n' + '~r~n' + 'Thank you,' + '~r~n' + '~r~n' + 'Billing Operations' + '~r~n' + '1-800-555-5555'
    
    string sStartDate
    sStartDate = string(start_date, "MM/DD/YYYY")
    sStartDate = left(sStartDate,2) + "-" + mid(sStartDate,4,2) + "-" + right(sStartDate,4)
    
    string sEndDate
    sEndDate = string(end_date, "MM/DD/YYYY")
    sEndDate = left(sEndDate,2) + "-" + mid(sEndDate,4,2) + "-" + right(sEndDate,4)
    
    string subject
    subject = 'Customer Report for ' + user + ' for Dates: ' + sStartDate + " To " + sEndDate + " Accounts: " + selectedaccount
    string fromaddresstext
    fromaddresstext = "billing@ftl.com"
    
    System.Net.mail.MailMessage message
    message = create  System.Net.mail.MailMessage
    message.subject = subject  
  
    message.body = bodytext
    
    System.Net.Mail.MailAddress fromaddress
    fromaddress = create System.Net.Mail.MailAddress("billing@ftl.com", "Billing Operations")
    message.From = fromAddress
    
    System.Net.Mail.MailAddress toaddress
    message.To.Add(email);
    message.Bcc.Add("pemurray@staysystems.com");
    
    System.Net.Mail.Attachment attach 
    attach = create System.Net.Mail.Attachment(filename);
    Helper.Mail.AddAttachment(message, attach);

    System.Net.Mail.SmtpClient smtpclient
    smtpclient = create  System.Net.Mail.SmtpClient
    smtpclient.host = "webapp.ftl.com"
    smtpclient.port = 25
    smtpclient.send(message)
    
    mle_1.show()
    mle_1.text = "The Excel Export was sent to " + email
  else
    mle_1.text = "Sorry, there was an error saving the file."
  end if
  
#end if

N'envoyez jamais un humain faire le travail d'un programme.

Hors ligne

 

Pied de page des forums

Propulsé par FluxBB 1.2.22