LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

copy table to clipboard for use in word

hello

 

i am using the 'Array To Spreadsheet String Function' for copying a table to a clipboard.

this tab-limited text can easily pastet into excel, but not into word.

 

in an older thread this has also be mentioned: http://forums.ni.com/t5/LabVIEW/Cut-Paste-from-a-deployed-panel-Table/m-p/435620/highlight/true#M213...

there is written: When you paste in Excel it works fine but with word you would need to convert text to table as an extra step.

 

does anyone know how to realise this? i found the information that a RTF or HTML table could be used and different clipboards (like a rtf) are available. but how to access the right one?

 

thanks for any help in advance

 

0 Kudos
Message 1 of 14
(7,163 Views)

@mischl wrote:

hello

 

i am using the 'Array To Spreadsheet String Function' for copying a table to a clipboard.

this tab-limited text can easily pastet into excel, but not into word.

 

in an older thread this has also be mentioned: http://forums.ni.com/t5/LabVIEW/Cut-Paste-from-a-deployed-panel-Table/m-p/435620/highlight/true#M213...

there is written: When you paste in Excel it works fine but with word you would need to convert text to table as an extra step.

 

does anyone know how to realise this? i found the information that a RTF or HTML table could be used and different clipboards (like a rtf) are available. but how to access the right one?

 

thanks for any help in advance

 


Array to Spreadsheet String actually creates string(s) with the values separated by commas. When you write the string(s) to a text file and  save the text file as a *.csv, then Excel is able to open the *.csv file.
However, you are not really writing directly to an Excel file. A *.csv is a TEXT file that Excel can read and will autiomatically put the comma-separated values into each column.
To write to a "real" Excel file (*.xls) or to a Word file (*.doc), you need to read up on the examples for ActiveX. There are examples that come with LabVIEW.
You could also create your own HTML file which is text. An HTML file (*.html) can display tabular data, but you need to learn HTML. There is an example included with LabVIEW on how to use the Report Generation VIs to create a HTML report.
0 Kudos
Message 2 of 14
(7,135 Views)

@nyc_(is_out_of_here) wrote:

Array to Spreadsheet String actually creates string(s) with the values separated by commas.

That's not entirely correct. Array to Spreadsheet String uses whatever delimeter you wire into it. The default is actually a tab character.

 

To OP: The reason there is a difference is that when you paste the contents of the clipboard into Excel it's seeing the tabs as column separators. With Word it just sees text, and simply pastes the text as if you had typed it directly. It does not automatically create a table - Word doesn't work that way.  The "extra step" in Word that you have to do is that after the text is pasted you need to select the text and then select the Table -> Insert Table command (Word 2003 - other versions have similar command). This should automatically convert the pasted text into a table.

0 Kudos
Message 3 of 14
(7,124 Views)

@smercurio_fc wrote:

@nyc_(is_out_of_here) wrote:

Array to Spreadsheet String actually creates string(s) with the values separated by commas.

That's not entirely correct. Array to Spreadsheet String uses whatever delimeter you wire into it. The default is actually a tab character.



Ah, right.

Forgot.

I almost always use commas since tabs are unprintable so generally unseen.

 

Still not sure what the OP hopes to gain with all of this.

 

I took it to mean he wants to write to a Word file, not copy text directly into a Word file while LabVIEW is running.

 

 

 

 

0 Kudos
Message 4 of 14
(7,120 Views)

@nyc_(is_out_of_here) wrote:

@smercurio_fc wrote:

@nyc_(is_out_of_here) wrote:

Array to Spreadsheet String actually creates string(s) with the values separated by commas.

That's not entirely correct. Array to Spreadsheet String uses whatever delimeter you wire into it. The default is actually a tab character.



Ah, right.

Forgot.

I almost always use commas since tabs are unprintable so generally unseen.

 

Still not sure what the OP hopes to gain with all of this.

 

I took it to mean he wants to write to a Word file, not copy text directly into a Word file while LabVIEW is running.

 


But commas have the bad side effect to be used in some locales as decimal character. So it is not possible to use comma separation in those locales. Also it is not easy to import a comma delimited file as you really should perform some anaysis first to see if it is really a comma deimited file or actually a file using a comma as decimal separator.

Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
0 Kudos
Message 5 of 14
(7,105 Views)

@rolfk wrote:

@nyc_(is_out_of_here) wrote:

@smercurio_fc wrote:

@nyc_(is_out_of_here) wrote:

Array to Spreadsheet String actually creates string(s) with the values separated by commas.

That's not entirely correct. Array to Spreadsheet String uses whatever delimeter you wire into it. The default is actually a tab character.



Ah, right.

Forgot.

I almost always use commas since tabs are unprintable so generally unseen.

 

Still not sure what the OP hopes to gain with all of this.

 

I took it to mean he wants to write to a Word file, not copy text directly into a Word file while LabVIEW is running.

 


But commas have the bad side effect to be used in some locales as decimal character. So it is not possible to use comma separation in those locales. Also it is not easy to import a comma delimited file as you really should perform some anaysis first to see if it is really a comma deimited file or actually a file using a comma as decimal separator.



If using the comma is not relevant, then just disregard it. I am only writing what works for me in the USA.

 

 

0 Kudos
Message 6 of 14
(7,097 Views)

thanks all for your replies.

 

perhaps i hadn't wrote it too clear, what my target is: paste a table into word that it looks like a table (not only text) out of labview while labview is running.

no reports, no writing files and all..

 

i am using this code to write it into the clipboard. as strings and tab limited. this works fine with excel but not with word. there an extra step - as smercurio_fc mentioned - is necessary.

Capture.PNG

 

this command writes into the text-clipboard. but there also other clipboard formats for other data, see http://en.wikipedia.org/wiki/Clipboard_%28software%29#Data_formats

(if one copies a table out of word into another word, it is still pastet as a table. this meta information has to come from somewhere..)

 

microsoft shows it in an example code: http://support.microsoft.com/kb/216676

the table will be prepared as rich text format and then writen into the clipboard. but before, the clipboard format has been set to rtf:

RegisterClipboardFormat("Rich Text Format");

is about the 5th line of code. in the example.

 

 

even this post message window i am writing here right now, has in the toolbar above an icon to 'paste from word', looks like word.PNG

after selecting a table in word and paste it here, i got this:

 

2

b

2333

a

 

wow! exactly this information i would like to transfer over my clipboard out of labview!

 

thanks again for any help

 

ps: what i hope to gain? copy out datas to an open word really quick and simple. (and yes, i know the report generation toolkit.., but this case is different)

0 Kudos
Message 7 of 14
(7,085 Views)

You can't do that. Word will past text as text, irrelevant of any formatting it may have. Maybe there is a super secret magic conoction such as Ctrl-Alt-Del-superspace-whatever that could convince Word to paste clipboard contents directly as a table, but I don't know about it and wouldn't rely on it, as chances are way to high that it won't work the same in the next version of MS Office.

 

You have three options:

 

1) Paste it as text and manually format it into a table in Word

2) Write a Word macro that pastes the clipboard content and converts it automatically into a table. Assign it a short cut key and use that shortcut.

3) Using Active X, control Word to do exactly what you want. This will be the most flexible solution but also the most work to do. It also has a high probability to break when you upgrade MS Office.

Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
0 Kudos
Message 8 of 14
(7,071 Views)

mischl wrote:

microsoft shows it in an example code: http://support.microsoft.com/kb/216676

the table will be prepared as rich text format and then writen into the clipboard. but before, the clipboard format has been set to rtf:

RegisterClipboardFormat("Rich Text Format");

is about the 5th line of code. in the example.


That code uses the Windows API to perform clipboard operations. You can attempt to do the same thing, if you wish, by using Call Libray Function Node. Examples on how to call DLLs, including the Windows API have been posted many times before, so there should be plenty of material on how to do this.

0 Kudos
Message 9 of 14
(7,058 Views)

ok, thanks a lot for your guiding smercurio_fc.

 

i've made an example in labview now with accessing user32.dll, but writing into the clipboard itself doesn't work and i could not find out why.... attached the vi.

 

i have integrated the order as used here: http://forums.ni.com/t5/LabWindows-CVI/Copy-amp-Paste-with-RTF/m-p/638601/thread-id/33345

as well as here (both are the same). http://msdn.microsoft.com/en-us/library/windows/desktop/ms649016%28v=vs.85%29.aspx#_win32_Copying_In...

 

any help would be very useful! thanks in advance

 

btw: does this dll access also work in an exe later and is user32.dll also available on 64 bit systems? (i use 64bit by myself and it works...)

0 Kudos
Message 10 of 14
(7,036 Views)