begin process at 2010 02 09 16:15:46
  Trouver un code source :
 
dans
 
Accueil > Forum > 

Delphi

 > 

Divers

 > 

Débutant(e)

 > 

Copier de l'HTML dans le pressepapier


Derniers messages déposésPoser une question dans le forum ou lancer une discussion

Copier de l'HTML dans le pressepapier

vendredi 24 avril 2009 à 17:08:26 | Copier de l'HTML dans le pressepapier

thonyboy

Bonjour je voudrais copier un lien HTML du type \\serveur\espace de travail\chemin accentué dans le presse papier si je fais un clipboard.astext cela me copie du fichier en texte brut A faire des recherche, j'ai trouvé une fonction sur le net qui permet de copier dans le presse papier au format HTML (il y avait peut etre plus simple mais je n'ai rien trouvé donc) Ca fonctionne, sauf que les caractères accentués (éèà etc) sont transformé en hyroglyphes quand je fais le paste dans Outlook. Quelqu'un aurait une idée pour me dépatouiller de ce probleme ? Merci a tous
vendredi 24 avril 2009 à 17:09:50 | Re : Copier de l'HTML dans le pressepapier

thonyboy

Pour completer mon message, voici le code de la fonction que j'ai trouvé et que j'utilise { If you've ever tried sticking html into the clipboard using the usual CF_TEXT format then you might have been disappointed to discover that wysiwyg html editors paste your offering as if it were just text, rather than recognising it as html. For that you need the CF_HTML format. CF_HTML is entirely text format and uses the transformation format UTF-8. It includes a description, a context, and within the context, the fragment. As you may know one can place multiple items of data onto the clipboard for a single clipboard entry, which means that the same data can be pasted in a variety of different formats in order to cope with target applications of varying sophistocation. The following example shows how to stick CF_TEXT (and CF_HTML) into the clipboard. } { Vielleicht hast du schon mal probiert, HTML-formatierter Text in die Zwischenablage zu kopieren mit dem gewöhnlichen CF_TEXT Format. Wenn man dann z.B in Word (Bearbeiten, Inhalte Einfügen) auswählt, gibt's das HTML Format aber nicht zur Auswahl. Lösung: Mit RegisterClipboardFormat das Format CF_HTML registrieren, dann einen String so formatieren, wie es auf der Microsoft Seite beschrieben ist (Siehe Link unten) und ihn dann mit der SetClipboardData API in die Zwischenablage kopieren. Das folgende Beispiel zeigt, wie man zwei verschiedene Formate (Text und HTML) in die Zwischenablage einfügen kann. } function FormatHTMLClipboardHeader(HTMLText: string): string; const CrLf = #13#10; begin Result := 'Version:0.9' + CrLf; Result := Result + 'StartHTML:-1' + CrLf; Result := Result + 'EndHTML:-1' + CrLf; Result := Result + 'StartFragment:000081' + CrLf; Result := Result + 'EndFragment:°°°°°°' + CrLf; Result := Result + HTMLText + CrLf; Result := StringReplace(Result, '°°°°°°', Format('%.6d', [Length(Result)]), []); end; //The second parameter is optional and is put into the clipboard as CF_HTML. //Function can be used standalone or in conjunction with the VCL clipboard so long as //you use the USEVCLCLIPBOARD conditional define //($define USEVCLCLIPBOARD} //(and clipboard.open, clipboard.close). //Code from http://www.lorriman.com procedure CopyHTMLToClipBoard(const str: string; const htmlStr: string = ''); var gMem: HGLOBAL; lp: PChar; Strings: array[0..1] of string; Formats: array[0..1] of UINT; i: Integer; begin gMem := 0; {$IFNDEF USEVCLCLIPBOARD} Win32Check(OpenClipBoard(0)); {$ENDIF} try //most descriptive first as per api docs Strings[0] := FormatHTMLClipboardHeader(htmlStr); Strings[1] := str; Formats[0] := RegisterClipboardFormat('HTML Format'); Formats[1] := CF_TEXT; {$IFNDEF USEVCLCLIPBOARD} Win32Check(EmptyClipBoard); {$ENDIF} for i := 0 to High(Strings) do begin if Strings[i] = '' then Continue; //an extra "1" for the null terminator gMem := GlobalAlloc(GMEM_DDESHARE + GMEM_MOVEABLE, Length(Strings[i]) + 1); {Succeeded, now read the stream contents into the memory the pointer points at} try Win32Check(gmem <> 0); lp := GlobalLock(gMem); Win32Check(lp <> nil); CopyMemory(lp, PChar(Strings[i]), Length(Strings[i]) + 1); finally GlobalUnlock(gMem); end; Win32Check(gmem <> 0); SetClipboardData(Formats[i], gMEm); Win32Check(gmem <> 0); gmem := 0; end; finally {$IFNDEF USEVCLCLIPBOARD} Win32Check(CloseClipBoard); {$ENDIF} end; end;
vendredi 24 avril 2009 à 17:15:02 | Re : Copier de l'HTML dans le pressepapier

JulioDelphi

Membre Club Administrateur CodeS-SourceS
Une petite mise en forme serait la bienvenue. Change de navigateur au besoin.
vendredi 24 avril 2009 à 17:21:39 | Re : Copier de l'HTML dans le pressepapier

thonyboy



{
  If you've ever tried sticking html into the clipboard using the usual CF_TEXT
  format then you might have been disappointed to discover that wysiwyg html
  editors paste your offering as if it were just text,
  rather than recognising it as html. For that you need the CF_HTML format.
  CF_HTML is entirely text format and uses the transformation format UTF-8.
  It includes a description, a context, and within the context, the fragment.

  As you may know one can place multiple items of data onto the clipboard for
  a single clipboard entry, which means that the same data can be pasted in a
  variety of different formats in order to cope with target
  applications of varying sophistocation.

  The following example shows how to stick CF_TEXT (and CF_HTML)
  into the clipboard.
}

{
  Vielleicht hast du schon mal probiert, HTML-formatierter Text in die
  Zwischenablage zu kopieren mit dem gewöhnlichen CF_TEXT Format.
  Wenn man dann z.B in Word (Bearbeiten, Inhalte Einfügen) auswählt,
  gibt's das HTML Format aber nicht zur Auswahl.
  Lösung: Mit RegisterClipboardFormat das Format CF_HTML registrieren,
  dann einen String so formatieren, wie es auf der Microsoft Seite beschrieben
  ist (Siehe Link unten) und ihn dann mit der SetClipboardData API in
  die Zwischenablage kopieren.
  Das folgende Beispiel zeigt, wie man zwei verschiedene Formate (Text und HTML)
  in die Zwischenablage einfügen kann.
}

function FormatHTMLClipboardHeader(HTMLText: string): string;
const
  CrLf = #13#10;
begin
  Result := 'Version:0.9' + CrLf;
  Result := Result + 'StartHTML:-1' + CrLf;
  Result := Result + 'EndHTML:-1' + CrLf;
  Result := Result + 'StartFragment:000081' + CrLf;
  Result := Result + 'EndFragment:°°°°°°' + CrLf;
  Result := Result + HTMLText + CrLf;
  Result := StringReplace(Result, '°°°°°°', Format('%.6d', [Length(Result)]), []);
end;

//The second parameter is optional and is put into the clipboard as CF_HTML.
//Function can be used standalone or in conjunction with the VCL clipboard so long as
//you use the USEVCLCLIPBOARD conditional define
//($define USEVCLCLIPBOARD}
//(and clipboard.open, clipboard.close).
//Code from http://www.lorriman.com
procedure CopyHTMLToClipBoard(const str: string; const htmlStr: string = '');
var
  gMem: HGLOBAL;
  lp: PChar;
  Strings: array[0..1] of string;
  Formats: array[0..1] of UINT;
  i: Integer;
begin
  gMem := 0;
  {$IFNDEF USEVCLCLIPBOARD}
  Win32Check(OpenClipBoard(0));
  {$ENDIF}
  try
    //most descriptive first as per api docs
    Strings[0] := FormatHTMLClipboardHeader(htmlStr);
    Strings[1] := str;
    Formats[0] := RegisterClipboardFormat('HTML Format');
    Formats[1] := CF_TEXT;
    {$IFNDEF USEVCLCLIPBOARD}
    Win32Check(EmptyClipBoard);
    {$ENDIF}
    for i := 0 to High(Strings) do
    begin
      if Strings[i] = '' then Continue;
      //an extra "1" for the null terminator
      gMem := GlobalAlloc(GMEM_DDESHARE + GMEM_MOVEABLE, Length(Strings[i]) + 1);
      {Succeeded, now read the stream contents into the memory the pointer points at}
      try
        Win32Check(gmem <> 0);
        lp := GlobalLock(gMem);
        Win32Check(lp <> nil);
        CopyMemory(lp, PChar(Strings[i]), Length(Strings[i]) + 1);
      finally
        GlobalUnlock(gMem);
      end;
      Win32Check(gmem <> 0);
      SetClipboardData(Formats[i], gMEm);
      Win32Check(gmem <> 0);
      gmem := 0;
    end;
  finally
    {$IFNDEF USEVCLCLIPBOARD}
    Win32Check(CloseClipBoard);
    {$ENDIF}
  end;
end;



Cette discussion est classée dans : html, presse, papier, copier, pressepapier


Répondre à ce message

Sujets en rapport avec ce message

Copier un fichier dans le presse papier windows??? [ par jmp77 ] Bonjour,Est ce que quelqu un saurait comment copier un fichier autocad(.dwg) dans le presse papier???Merci et bonne prog,JMP. ClipBoard D7 [ par michelroc ] Bonjour,Afin de limiter la grosseur d'une base de données .1)° je voudrais connaitre la taille du fichier image dans le presse papier.2°) Pouvoir effa Comment recuperer le contenu du presse-papier sous forme de stream ? [ par corole3 ] Bonsoir, j'aurais voulu récuperer le contenu du presse-papier tel quel avec le texte et l'image et le formatage du texte comme le fait OpenOffice da Copie d'une sélection de données BDGrid dans le presse papier [ par neho88 ] Bonjour j'ai une BDGRID avec plein de données, je voudrais pouvoir sélectionner une partie de la BDGrid, la copier dans le presse papier en vue de la coller presse papier---> excel [ par amelrc ] Bonjour, Comment je peux coller le contenu du presse papier dans un document excel (.xls) en de comment faire pour récupérer les presse papier des ordinateurs connectés au réseau. [ par Bestdoud ] bonjour je cherche à faire une application qui permettrait de récupérer les presse papier des ordinateurs connectés au réseau. en fait l'application StringGrid vers presse papier [ par miarynante ] Je suis un peu débutant sur l'outil Delphi, et j'aimerai que vous m'aider si c'est possible. En faite, le but de mon programme est de selectionner des copier le rectangle dessiner dans un bitmap [ par dieuchrist ] Hello tt le monde.G un petit probleme: j'aimerai copier l'intérieur d'un rectangle, dessiner sur le canvas de mon image, dans un bitmap. mais je sèche TStringList qui ne veut pas prendre les accents [ par intik ] Bonjour à tous Alors voila j'ai un programme qui charge un fichier html qui le modifie à un endroit bien précis et qui ensuite l'enregistre J'ut Code HTML [ par buguetj ] Bonjour, j'ai créer un Memo1 sur ma Form et je souhaiterais, que lorsque je click sur un Button1, que le code HTML de la page internet www.google.fr (


Nos sponsors


Sondage...

Comparez les prix

CalendriCode

Février 2010
LMMJVSD
1234567
891011121314
15161718192021
22232425262728

Consulter la suite du CalendriCode

 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 0,593 sec (3)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales