Accueil > Forum > > > > Copier de l'HTML dans le pressepapier
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
|
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.
copier un item de listview au presse papier [ par mohammed2020 ]
Salut, comme débutant je voudrais savoir comment copier un item de listview au presse papier. Merci d'avance.
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
coller presse papier---> excel [ par amelrc ]
Bonjour, Comment je peux coller le contenu du presse papier dans un document excel (.xls) en de
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
Copier un fichier à partir d'un repertoire sous reseau [ par hkm21 ]
salutj'amerais savoir comment acceder -a partir de mon apllication- à un repertoire sous reseau pour copier un fichier sur mon postemerci d'avance
Copier une image dans le fond d'un TPanel [ par orelien ]
Bonjour,J'aimerais savoir comment copier une image dans le fond d'un TPanel.Si quelqu'un a une idée...MerciOrélien.
Livres en rapport
|
Derniers Blogs
[FRAMEWORK 4] LES TASKS ET LE THREAD UI[FRAMEWORK 4] LES TASKS ET LE THREAD UI par fathi
Je viens de passer quelques temps au TechDay's et j'ai pu voir pas mal de session intéressante. Par contre une chose m'a un peu étonné lors de certaines de ces sessions qui abordaient les améliorations du framework .NET (donc le 4.5) : en gros, bea...
Cliquez pour lire la suite de l'article par fathi WORKFLOW FOUNDATION 3 A UN PIED DANS LA TOMBEWORKFLOW FOUNDATION 3 A UN PIED DANS LA TOMBE par JeremyJeanson
Depuis déjà un an, je conseille vivement les utilisateurs de Workflow Foundation 3 à migrer vers la version 4. L'information qui va suivre ne devrait donc pas trop prendre au dépourvu les personnes qui m'ont suivi. Je profite de ce poste, pour faire le re...
Cliquez pour lire la suite de l'article par JeremyJeanson TECHDAYS PARIS 2012 : NOUVELLES TENDANCES DU POSTE DE TRAVAIL - BRING YOUR OWN PCTECHDAYS PARIS 2012 : NOUVELLES TENDANCES DU POSTE DE TRAVAIL - BRING YOUR OWN PC par ROMELARD Fabrice
Speakers: Thierry Rapatout, Antoine Petit et Xavier Trebbia Cette session entre dans le cadre des RDV Décideurs des TechDays 2012, elle est liée à la consumérisation de l'IT et la mise en place du "DeskTop as a Service" dans de plus en ...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice TECHDAYS PARIS 2012 : SYSTEM CENTER SERVICE MANAGER 2012 VUE D'ENSEMBLETECHDAYS PARIS 2012 : SYSTEM CENTER SERVICE MANAGER 2012 VUE D'ENSEMBLE par ROMELARD Fabrice
Speakers: Julien Marechal, Gautier Confiant, Sébastien MEYER La session débute par le positionnement de la solution System Center par rapport aux concepts d'organisation ITIL. Le portail du catalogue de se...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice TECHDAYS PARIS 2012 : PLEINIèRE SECOND JOURTECHDAYS PARIS 2012 : PLEINIèRE SECOND JOUR par ROMELARD Fabrice
Après une première journée dédiée aux développeurs, cette seconde journée est dédiée au monde des entreprises et de ses applications. Ainsi, cette pleinière est dédiée à faire un 360 de l'évolution des applications Business aux demandes ac...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice
Logiciels
Academy System (17.2.1.0)ACADEMY SYSTEM (17.2.1.0)Logiciel de gestion des établissements.
- élèves/étudiants (inscription, dossier, absence...)
-... Cliquez pour télécharger Academy System Easy-Planning (1.0.0.1)EASY-PLANNING (1.0.0.1)Basé sur les mêmes principes que MyPlanning, Easy-Planning permet de créer des plannings sous la ... Cliquez pour télécharger Easy-Planning COLLECTOR PLUS (3.00B)COLLECTOR PLUS (3.00B)COLLECTOR PLUS version 3.00B est un logiciel utilisant une base de données alimentée par :
- L... Cliquez pour télécharger COLLECTOR PLUS PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V7.4)PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V7.4)PONAMEDIA TV DEVIENS HELLLOOO FLASH
LA TV SUR VOTRE ORDINATEUR.
Toute une plateforme Multi... Cliquez pour télécharger PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO LettresFaciles 2011 (8.0.0.1)LETTRESFACILES 2011 (8.0.0.1)LettresFaciles est un logiciel facilitant la création et la rédaction de lettres types.
Son inte... Cliquez pour télécharger LettresFaciles 2011
|