Coping in .NET

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a ListView control with several columns and rows worth of data. What I wantto be able to do is to allow the user to hit copy and it will copy this information to the clipboard. Then I would like the user to be able to open up any of the following application; Excel, Word, PowerPoint or WordPad and be able to paste the data into these applications. In Excel it should obviously paste the information into the different columns and rows. In Work and PowerPoint I would like to be able to create a table put the information into the applications this way. Ideally pasting into WordPad would also work and just provide the data, in neat format, like tab between the columns and enters between the rows. Basically I want it to act similar to if you copy information from Excel and try and paste it into these other applications.
 
Hi Paul,

You can put in the clipboard your data in several different formats at the
same time. Usually what the programs do they put the data in some
proprietary format as well as some of the well known formats such as text
(plain or rtf) for the text based application, bitmap for graphics
applications, meta files, html and so on. The clipboard itself is able to
convert between some of the formats. For example if you put ascii text and
the consumer ask for unicode the clipboard will convert the data for you and
you don't have to put both of them. Find out what format the target
applications support and provide these formats in the clipboard. For example
I'm pretty sure that if you put tabbed (or comma separated ) text into the
clipboard excel will paste it in a separate columns.

You can use DataObject Viewer tool to see what kind of formats the
application put in the clipboard. You can find this tool in <VS.NET
folder>\Common7\Tools\Bin\dobjview.exe.

For more info about the clipboard and its formats you can read in MSDN at
offline:
ms-help://MS.MSDNQTR.2003APR.1033/winui/winui/windowsuserinterface/dataexcha
nge/clipboard/clipboardformats.htm

online:
http://msdn.microsoft.com/library/d...e/dataexchange/clipboard/clipboardformats.asp

--
HTH
Stoitcho Goutsev (100) [C# MVP]


Paul said:
I have a ListView control with several columns and rows worth of data.
What I wantto be able to do is to allow the user to hit copy and it will
copy this information to the clipboard. Then I would like the user to be
able to open up any of the following application; Excel, Word, PowerPoint or
WordPad and be able to paste the data into these applications. In Excel it
should obviously paste the information into the different columns and rows.
In Work and PowerPoint I would like to be able to create a table put the
information into the applications this way. Ideally pasting into WordPad
would also work and just provide the data, in neat format, like tab between
the columns and enters between the rows. Basically I want it to act similar
to if you copy information from Excel and try and paste it into these other
applications.
 
I knew most of this information, the part that I don't know how to do is paste something to the clipboard that will be recognized as I stated in each application, rows and columns in Excel, but as a table in Word.

Stoitcho Goutsev (100) said:
Hi Paul,

You can put in the clipboard your data in several different formats at the
same time. Usually what the programs do they put the data in some
proprietary format as well as some of the well known formats such as text
(plain or rtf) for the text based application, bitmap for graphics
applications, meta files, html and so on. The clipboard itself is able to
convert between some of the formats. For example if you put ascii text and
the consumer ask for unicode the clipboard will convert the data for you and
you don't have to put both of them. Find out what format the target
applications support and provide these formats in the clipboard. For example
I'm pretty sure that if you put tabbed (or comma separated ) text into the
clipboard excel will paste it in a separate columns.

You can use DataObject Viewer tool to see what kind of formats the
application put in the clipboard. You can find this tool in <VS.NET
folder>\Common7\Tools\Bin\dobjview.exe.

For more info about the clipboard and its formats you can read in MSDN at
offline:
ms-help://MS.MSDNQTR.2003APR.1033/winui/winui/windowsuserinterface/dataexcha
nge/clipboard/clipboardformats.htm

online:
http://msdn.microsoft.com/library/d...e/dataexchange/clipboard/clipboardformats.asp

--
HTH
Stoitcho Goutsev (100) [C# MVP]


Paul said:
I have a ListView control with several columns and rows worth of data.
What I wantto be able to do is to allow the user to hit copy and it will
copy this information to the clipboard. Then I would like the user to be
able to open up any of the following application; Excel, Word, PowerPoint or
WordPad and be able to paste the data into these applications. In Excel it
should obviously paste the information into the different columns and rows.
In Work and PowerPoint I would like to be able to create a table put the
information into the applications this way. Ideally pasting into WordPad
would also work and just provide the data, in neat format, like tab between
the columns and enters between the rows. Basically I want it to act similar
to if you copy information from Excel and try and paste it into these other
applications.
 
Hi Paul,

It looks like you are looking for working example.

Ok here it is. Oviously the most expressive format among the public formats
Word and Excel use is HTML so what you need to do is to describe the table
in HTML

Clipboard.SetDataObject(new DataObject(DataFormats.Html,
"Version:1.0\r\nStartHTML:0000000105\r\nEndHTML:0000000405\r\nStartFragment:
0000000105\r\nEndFragment:0000000405\r\n<table border=\"1\"
cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse: collapse\"
bordercolor=\"#111111\" width=\"100%\" id=\"AutoNumber1\"><tr><td
width=\"33%\">10</td><td width=\"33%\">20</td><td
width=\"34%\">30</td></tr><tr><td width=\"33%\">40</td><td
width=\"33%\">50</td><td width=\"34%\">60</td></tr></table>"));

Watch for line breaks. This is one very long line

--
HTH
Stoitcho Goutsev (100) [C# MVP]


Paul said:
I knew most of this information, the part that I don't know how to do is
paste something to the clipboard that will be recognized as I stated in each
application, rows and columns in Excel, but as a table in Word.
Stoitcho Goutsev (100) said:
Hi Paul,

You can put in the clipboard your data in several different formats at the
same time. Usually what the programs do they put the data in some
proprietary format as well as some of the well known formats such as text
(plain or rtf) for the text based application, bitmap for graphics
applications, meta files, html and so on. The clipboard itself is able to
convert between some of the formats. For example if you put ascii text and
the consumer ask for unicode the clipboard will convert the data for you and
you don't have to put both of them. Find out what format the target
applications support and provide these formats in the clipboard. For example
I'm pretty sure that if you put tabbed (or comma separated ) text into the
clipboard excel will paste it in a separate columns.

You can use DataObject Viewer tool to see what kind of formats the
application put in the clipboard. You can find this tool in <VS.NET
folder>\Common7\Tools\Bin\dobjview.exe.

For more info about the clipboard and its formats you can read in MSDN at
offline:
ms-help://MS.MSDNQTR.2003APR.1033/winui/winui/windowsuserinterface/dataexcha
nge/clipboard/clipboardformats.htm

online:
http://msdn.microsoft.com/library/d...e/dataexchange/clipboard/clipboardformats.asp

--
HTH
Stoitcho Goutsev (100) [C# MVP]


Paul said:
I have a ListView control with several columns and rows worth of
data.
What I wantto be able to do is to allow the user to hit copy and it will
copy this information to the clipboard. Then I would like the user to be
able to open up any of the following application; Excel, Word, PowerPoint or
WordPad and be able to paste the data into these applications. In Excel it
should obviously paste the information into the different columns and rows.
In Work and PowerPoint I would like to be able to create a table put the
information into the applications this way. Ideally pasting into WordPad
would also work and just provide the data, in neat format, like tab between
the columns and enters between the rows. Basically I want it to act similar
to if you copy information from Excel and try and paste it into these other
applications.
 
Thank You I had tried something with HTML, but it didn't work. But I only had the HTML not all the stuff you have at the beginning.

Stoitcho Goutsev (100) said:
Hi Paul,

It looks like you are looking for working example.

Ok here it is. Oviously the most expressive format among the public formats
Word and Excel use is HTML so what you need to do is to describe the table
in HTML

Clipboard.SetDataObject(new DataObject(DataFormats.Html,
"Version:1.0\r\nStartHTML:0000000105\r\nEndHTML:0000000405\r\nStartFragment:
0000000105\r\nEndFragment:0000000405\r\n<table border=\"1\"
cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse: collapse\"
bordercolor=\"#111111\" width=\"100%\" id=\"AutoNumber1\"><tr><td
width=\"33%\">10</td><td width=\"33%\">20</td><td
width=\"34%\">30</td></tr><tr><td width=\"33%\">40</td><td
width=\"33%\">50</td><td width=\"34%\">60</td></tr></table>"));

Watch for line breaks. This is one very long line

--
HTH
Stoitcho Goutsev (100) [C# MVP]


Paul said:
I knew most of this information, the part that I don't know how to do is
paste something to the clipboard that will be recognized as I stated in each
application, rows and columns in Excel, but as a table in Word.
Stoitcho Goutsev (100) said:
Hi Paul,

You can put in the clipboard your data in several different formats at the
same time. Usually what the programs do they put the data in some
proprietary format as well as some of the well known formats such as text
(plain or rtf) for the text based application, bitmap for graphics
applications, meta files, html and so on. The clipboard itself is able to
convert between some of the formats. For example if you put ascii text and
the consumer ask for unicode the clipboard will convert the data for you and
you don't have to put both of them. Find out what format the target
applications support and provide these formats in the clipboard. For example
I'm pretty sure that if you put tabbed (or comma separated ) text into the
clipboard excel will paste it in a separate columns.

You can use DataObject Viewer tool to see what kind of formats the
application put in the clipboard. You can find this tool in <VS.NET
folder>\Common7\Tools\Bin\dobjview.exe.

For more info about the clipboard and its formats you can read in MSDN at
offline:
ms-help://MS.MSDNQTR.2003APR.1033/winui/winui/windowsuserinterface/dataexcha
nge/clipboard/clipboardformats.htm

online:
http://msdn.microsoft.com/library/d...e/dataexchange/clipboard/clipboardformats.asp

--
HTH
Stoitcho Goutsev (100) [C# MVP]


I have a ListView control with several columns and rows worth of data.
What I wantto be able to do is to allow the user to hit copy and it will
copy this information to the clipboard. Then I would like the user to be
able to open up any of the following application; Excel, Word, PowerPoint or
WordPad and be able to paste the data into these applications. In Excel it
should obviously paste the information into the different columns and rows.
In Work and PowerPoint I would like to be able to create a table put the
information into the applications this way. Ideally pasting into WordPad
would also work and just provide the data, in neat format, like tab between
the columns and enters between the rows. Basically I want it to act similar
to if you copy information from Excel and try and paste it into these other
applications.
 
Hi Paul,

You have to have it. This is the HTML clipboard format header

--
HTH
Stoitcho Goutsev (100) [C# MVP]


Paul said:
Thank You I had tried something with HTML, but it didn't work. But I only
had the HTML not all the stuff you have at the beginning.
Stoitcho Goutsev (100) said:
Hi Paul,

It looks like you are looking for working example.

Ok here it is. Oviously the most expressive format among the public formats
Word and Excel use is HTML so what you need to do is to describe the table
in HTML

Clipboard.SetDataObject(new DataObject(DataFormats.Html,
"Version:1.0\r\nStartHTML:0000000105\r\nEndHTML:0000000405\r\nStartFragment:
0000000105\r\nEndFragment:0000000405\r\n<table border=\"1\"
cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse: collapse\"
bordercolor=\"#111111\" width=\"100%\" id=\"AutoNumber1\"><tr><td
width=\"33%\">10</td><td width=\"33%\">20</td><td
width=\"34%\">30</td></tr><tr><td width=\"33%\">40</td><td
width=\"33%\">50</td><td width=\"34%\">60</td></tr></table>"));

Watch for line breaks. This is one very long line

--
HTH
Stoitcho Goutsev (100) [C# MVP]


Paul said:
I knew most of this information, the part that I don't know how to do
is
paste something to the clipboard that will be recognized as I stated in each
application, rows and columns in Excel, but as a table in Word.
:

Hi Paul,

You can put in the clipboard your data in several different formats
at
the
same time. Usually what the programs do they put the data in some
proprietary format as well as some of the well known formats such as text
(plain or rtf) for the text based application, bitmap for graphics
applications, meta files, html and so on. The clipboard itself is
able
to
convert between some of the formats. For example if you put ascii
text
and
the consumer ask for unicode the clipboard will convert the data for
you
and
you don't have to put both of them. Find out what format the target
applications support and provide these formats in the clipboard. For example
I'm pretty sure that if you put tabbed (or comma separated ) text
into
the
clipboard excel will paste it in a separate columns.

You can use DataObject Viewer tool to see what kind of formats the
application put in the clipboard. You can find this tool in <VS.NET
folder>\Common7\Tools\Bin\dobjview.exe.

For more info about the clipboard and its formats you can read in
MSDN
at
ms-help://MS.MSDNQTR.2003APR.1033/winui/winui/windowsuserinterface/dataexcha
nge/clipboard/clipboardformats.htm

online:
http://msdn.microsoft.com/library/d...e/dataexchange/clipboard/clipboardformats.asp
--
HTH
Stoitcho Goutsev (100) [C# MVP]


I have a ListView control with several columns and rows worth of data.
What I wantto be able to do is to allow the user to hit copy and it will
copy this information to the clipboard. Then I would like the user
to
be
able to open up any of the following application; Excel, Word, PowerPoint or
WordPad and be able to paste the data into these applications. In
Excel
it
should obviously paste the information into the different columns
and
rows.
In Work and PowerPoint I would like to be able to create a table put the
information into the applications this way. Ideally pasting into WordPad
would also work and just provide the data, in neat format, like tab between
the columns and enters between the rows. Basically I want it to act similar
to if you copy information from Excel and try and paste it into
these
other
applications.
 
Back
Top