PDA

View Full Version : Qtable : how can I copy-paste the selected rows in a Word document ?



greencastor
23rd August 2006, 16:16
Hi,

I would like to copy the selected cells of a QTable and paste them in a Word document. How can I do that ? I haven't seen in the Qt Assistant something that could help me... :(

Thanks in advance.

jacek
23rd August 2006, 16:19
QClipboard?

greencastor
23rd August 2006, 16:26
Yes, but the aim is to create the same array in the Word document than the selected rows of the QTable. And I don't know how I can manage to do this because I could make it by using QPixmap but I will have a picture in my Word document, no ?

jacek
23rd August 2006, 16:32
You could try to encode that table in HTML or copy some table into clipboard and see how it was encoded. Other solution you might try is to use Word's COM interface --- it probably will be more reliable, but it also requires more work.

greencastor
23rd August 2006, 16:44
You could try to encode that table in HTML or copy some table into clipboard and see how it was encoded.
You mean using "QClipboard::setText" with a QString containing the code in HTML ?

(Thank you for your quick answers !)

jacek
23rd August 2006, 16:54
You mean using "QClipboard::setText" with a QString containing the code in HTML ?
I would rather try QClipboard::setData() / QClipboard::setMimeData().

greencastor
23rd August 2006, 17:01
I must admit that I have difficulties understanding how to use the class "QMimeSource" (for the function "void Clipboard::setData ( QMimeSource * src )")... :confused:

jacek
23rd August 2006, 18:47
I must admit that I have difficulties understanding how to use the class "QMimeSource" (for the function "void Clipboard::setData ( QMimeSource * src )")...
You must create your own class that inherits from QMimeSource and implement all abstract methods.

But first write a small application that dumps data from cliboard to see that Word puts there. You might try also clipbrd.exe, but it won't give you much information.

aMan
23rd August 2006, 19:28
isn't there a generic way to do that for all word processing programms (openoffice writer, kword, abiword, ms word...)?

regards..
aman..

jpn
23rd August 2006, 19:53
isn't there a generic way to do that for all word processing programms (openoffice writer, kword, abiword, ms word...)?
I suppose all of them support HTML as suggested by jacek.



// qt4 code
QMimeData* mime = new QMimeData;
mime->setHtml("<table border=2><tr><td>1</td></tr><tr><td>2</td></tr></table>");
QApplication::clipboard()->setMimeData(mime); // clipboard takes ownership of mimedata


Edit: seems to only work with MS Word, not with KWord nor OO.. :(

greencastor
24th August 2006, 10:35
Thank you guys, I'm going to test it !