class Clipboard (.Net Framework 3.5) - setting Html data

Using (or providing) Microsoft.NET Classes

class Clipboard (.Net Framework 3.5) - setting Html data

Postby roberto on Mon Mar 18, 2013 7:30 am

I need to export in Html format which can be loaded into application Word (I am using Dyalog 13.1 version)

For this reason I would set Clipboard using dotnet class Clipboard according to Microsoft instructions:

http://msdn.microsoft.com/en-us/library/system.windows.forms.clipboard.setdata(v=vs.90).aspx

I wrote a function like this:

z←clip x;⎕USING
⍝ x: Html text
⎕USING←'System'
⎕USING,←⊂'System.Windows.Forms,system.windows.forms.dll'
Clipboard.SetData('Html' x)
1


The Html text x is taken from Windows site

http://msdn.microsoft.com/en-us/library/aa767917%28VS.85%29.aspx

and is could be exactly this (below) but when I paste into Word nothing happenes.

Could anyone help me to undestand why I can not setting Clipboard ?

Thanks in advance
Roberto
___________________________________________________________________
Version:0.9
StartHTML:71
EndHTML:170
StartFragment:140
EndFragment:160
StartSelection:140
EndSelection:160
<!DOCTYPE>
<HTML>
<HEAD>
<TITLE>The HTML Clipboard</TITLE>
<BASE HREF="http://sample/specs">
</HEAD>
<BODY>
<!--StartFragment -->
<P>The Fragment</P>
<!--EndFragment -->
</BODY>
</HTML>
roberto
 
Posts: 1
Joined: Thu Mar 14, 2013 7:05 am

Re: class Clipboard (.Net Framework 3.5) - setting Html data

Postby JohnD|Dyalog on Thu Mar 21, 2013 1:24 pm

Hi Roberto,

I think there are a number of problems here.

1) The name of the format. It's not 'Html' it has to be 'CF_HTML'
2) You shouldn't nest the arguments
3) Word doesn't recognise CF_HTML format (so the paste doesn't work)

So to put HTML in the clipboard you need:
Clipboard.SetData 'CF_HTML' x
You can check that it's worked with
Clipboard.GetData ⊂'CF_HTML'

To get it into word though, you may need to use text:
Clipboard.SetData 'Text' x

Best Regards,
John Daintree.
User avatar
JohnD|Dyalog
 
Posts: 74
Joined: Wed Oct 01, 2008 9:35 am

Re: class Clipboard (.Net Framework 3.5) - setting Html data

Postby giangiquario on Tue Mar 26, 2013 5:15 pm

Roberto,

using Dyalog 13.0 and .NET 2.0

please look at next function

      z←toClipHtml hText;⎕USING;uCONV
⍝ set Html text to Clipboard with TextDataFormat Html
⍝ z ←→ 1 ←→ OK
⍝ Warning: hText must be HTML well conformed
⎕USING←'System'
⎕USING,←⊂'System.Windows.Forms,system.windows.forms.dll'
Clipboard.SetText'xxx'TextDataFormat.Text ⍝ reset the Clipboard
:If Clipboard.ContainsText TextDataFormat.Text ⍝ the Clipboard is listening
:AndIf 0<⍴hText
Clipboard.SetText hText TextDataFormat.Html
:AndIf Clipboard.ContainsText TextDataFormat.Html ⍝ the Clipboard contains a text or Htmltext
uCONV←{((((⍴⍺)⍴0 1)/⍺),⎕AV)[((((⍴⍺)⍴1 0)/⍺),⎕AV)⍳⍵]}
z←∨/'</html>'⍷'HhTtMmLl'uCONV ¯15↑Clipboard.GetText TextDataFormat.Html ⍝ is it a Htmltext?
:Else
z←0
:EndIf
You will be able to set a HTML text inside the Clipboard, and paste it into MS Word

You can CTRL+C a table from MS Word and read it into a Dyalog variable:

       z←fromClipHtml;⎕USING
⍝ z: vector: HTML text from Clipboard
⍝ z←→'' when clipboard does not contain any HTML text
⎕USING←'System'
⎕USING,←⊂'System.Windows.Forms,system.windows.forms.dll'
z←Clipboard.GetText TextDataFormat.Html
User avatar
giangiquario
 
Posts: 46
Joined: Thu Nov 26, 2009 8:55 am
Location: Milano, Italia


Return to Microsoft.NET

Who is online

Users browsing this forum: No registered users and 1 guest