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.
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 (
Livres en rapport
|
Derniers Blogs
TECHDAYS PARIS 2010 : PLAN DE MIGRATION VERS SHAREPOINT 2010TECHDAYS PARIS 2010 : PLAN DE MIGRATION VERS SHAREPOINT 2010 par ROMELARD Fabrice
Animé par: Arnault Nouvel et Antoine Dongois Le processus à prendre : Apprendre (découvrir la plateforme) Préparer (documenter l'historique et choisir la méthode de MAJ) Test (Test de MAJ) Implémenter (Effectuer la MAJ) Valid...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice TECHDAYS PARIS 2010 : LA PLEINIèRE DU SECOND JOURTECHDAYS PARIS 2010 : LA PLEINIèRE DU SECOND JOUR par ROMELARD Fabrice
Après un retour sur l'histoire des TechDays de Paris et le fait que ce soit le plus gros event MS au monde (du fait de sa gratuité), le président de MS France (Eric Boustoullier) a fait une présentation de la vision Microsoft pour les années à venir...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice CRéATION D'UNE BASE DE DONNéE SOUS SQL AZURECRéATION D'UNE BASE DE DONNéE SOUS SQL AZURE par junarnoalg
Sans rentrer dans les détails, je me propose ici de faire un rapide tour de ce que propose SQL Azure.
SQL Azure est avant tout un service d'hébergement de base de données relationnelles construit sur SQL Server. Il permet aux entreprises d...
Cliquez pour lire la suite de l'article par junarnoalg TECHDAYS PARIS 2010 : LES SERVICES D'APPLICATIONS DANS SHAREPOINT 2010TECHDAYS PARIS 2010 : LES SERVICES D'APPLICATIONS DANS SHAREPOINT 2010 par ROMELARD Fabrice
Animé par: Xavier Moreels et Julien Bakmezdjian Ce sujet est lié au partage des applications comme services dans SharePoint 2010, ceci représente la possibilité de créer sa propre application qui sera utilisable comme ceux en standard : Search...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice
Logiciels
DB-MAIN (9.1.0)DB-MAIN (9.1.0)DB-MAIN is a data-modeling and data-architecture tool. It is designed to help developers and anal... Cliquez pour télécharger DB-MAIN Xilisoft DPG Convertisseur (5.1.37.0120)XILISOFT DPG CONVERTISSEUR (5.1.37.0120)Xilisoft DPG Convertisseur offre aux fans de Nintendo DS une bonne solution leur permettant de dé... Cliquez pour télécharger Xilisoft DPG Convertisseur GraphicsGale (2.01.01)GRAPHICSGALE (2.01.01)GraphicsGale est un logiciel de PixelArt avec de nombreuse fonctionnalités permettant de réalisé ... Cliquez pour télécharger GraphicsGale Architecte 3D (Platinum 2010)ARCHITECTE 3D (PLATINUM 2010)Architecte 3D Platinium vous permet de concevoir facilement les plans votre future maison, de l'é... Cliquez pour télécharger Architecte 3D TeamViewer 5 (TeamViewer 5)TEAMVIEWER 5 (TEAMVIEWER 5)Dépanner un ami,expliquer une manipulation devient un jeu d'enfant.
Prise en main d'un autre ord... Cliquez pour télécharger TeamViewer 5
|