Error When Copying from Clipboard to PowerPoint slide

G

Guest

Hello,

I am trying to copy the contents of the output of SQL Reporting Services to
a PowerPoint slide. For this, I am using SQL Reporting Services to obtain an
IMAGE stream, which I paste to the Windows clipboard. Then, using automation,
I am trying to copy this information from the clipboard to a PowerPoint
slide. However, I get an error at slide.Shapes.PasteSpecial.

I am able create a System.Drawing.Bitmap object from the memory stream that
I associate with the image stream. I can also copy an image fragment that I
clipped in MSPaint (which means it's on the clipboard) to PowerPoint using
Automation. And if I generate a CSV stream from Reporting Services, I can
copy this to the clipboard and from there to Excel. It's only that I don't
seem to be able to copy anything from the clipboard to PowerPoint if I pasted
it to the clipboard using the MemoryStream. Also, using the following code,
I find that the clipped data from MSPaint supports 4 formats ("Embed Source",
"Object Descriptor" , "MetaFilePict", and "DeviceIndependentBitmap") but the
data I copy from the MemoryStream has only 2 ("System.Drawing.Bitmap" and
"Bitmap").

// Code to check formats for clipboad data
IDataObject data = Clipboard.GetDataObject();
String[] arrayOfFormats = data.GetFormats(true);

Does anyone have any pointers?

Thanks,
Ajay.

ERROR
*****

An unhandled exception of type 'System.Runtime.InteropServices.COMException'
occurred in WindowsApplication2.exe

Additional information: Shapes (unknown member) : Invalid request.
Clipboard is empty or contains data which may not be pasted here.

CODE
****

// Obtain an image stream in "results", which is Byte[]

MemoryStream MemStream = new MemoryStream(results);
DataObject d = new DataObject();
d.SetData(DataFormats.Bitmap, true, MemStream);
Clipboard.SetDataObject(d, true);

PowerPoint.Presentation ppt;
PowerPoint.Application pptApp;
PowerPoint.Slide slide;
pptApp = new PowerPoint.Application();
ppt = pptApp.Presentations.Add(MsoTriState.msoTriStateMixed);

slide = ppt.Slides.Add(1, PowerPoint.PpSlideLayout.ppLayoutBlank)
slide.Shapes.PasteSpecial(PowerPoint.PpPasteDataType.ppPasteDefault,MsoTriState.msoFalse,"",0,"",MsoTriState.msoFalse);
ppt.SaveAs("D:\\Ata\\test.ppt",
PowerPoint.PpSaveAsFileType.ppSaveAsPresentation, MsoTriState.msoTrue);
 
S

Steve Rindsberg

Have you tried specifying the constant for bitmap as a param to PasteSpecial rather than
the default? You'd expect the bitmap to BE the default in this case, but perhaps it's
not for some odd reason.



Hello,

I am trying to copy the contents of the output of SQL Reporting Services to
a PowerPoint slide. For this, I am using SQL Reporting Services to obtain an
IMAGE stream, which I paste to the Windows clipboard. Then, using automation,
I am trying to copy this information from the clipboard to a PowerPoint
slide. However, I get an error at slide.Shapes.PasteSpecial.

I am able create a System.Drawing.Bitmap object from the memory stream that
I associate with the image stream. I can also copy an image fragment that I
clipped in MSPaint (which means it's on the clipboard) to PowerPoint using
Automation. And if I generate a CSV stream from Reporting Services, I can
copy this to the clipboard and from there to Excel. It's only that I don't
seem to be able to copy anything from the clipboard to PowerPoint if I pasted
it to the clipboard using the MemoryStream. Also, using the following code,
I find that the clipped data from MSPaint supports 4 formats ("Embed Source",
"Object Descriptor" , "MetaFilePict", and "DeviceIndependentBitmap") but the
data I copy from the MemoryStream has only 2 ("System.Drawing.Bitmap" and
"Bitmap").

// Code to check formats for clipboad data
IDataObject data = Clipboard.GetDataObject();
String[] arrayOfFormats = data.GetFormats(true);

Does anyone have any pointers?

Thanks,
Ajay.

ERROR
*****

An unhandled exception of type 'System.Runtime.InteropServices.COMException'
occurred in WindowsApplication2.exe

Additional information: Shapes (unknown member) : Invalid request.
Clipboard is empty or contains data which may not be pasted here.

CODE
****

// Obtain an image stream in "results", which is Byte[]

MemoryStream MemStream = new MemoryStream(results);
DataObject d = new DataObject();
d.SetData(DataFormats.Bitmap, true, MemStream);
Clipboard.SetDataObject(d, true);

PowerPoint.Presentation ppt;
PowerPoint.Application pptApp;
PowerPoint.Slide slide;
pptApp = new PowerPoint.Application();
ppt = pptApp.Presentations.Add(MsoTriState.msoTriStateMixed);

slide = ppt.Slides.Add(1, PowerPoint.PpSlideLayout.ppLayoutBlank);
slide.Shapes.PasteSpecial(PowerPoint.PpPasteDataType.ppPasteDefault,MsoTriState.msoFalse,
"",0,"",MsoTriState.msoFalse);
ppt.SaveAs("D:\\Ata\\test.ppt",
PowerPoint.PpSaveAsFileType.ppSaveAsPresentation, MsoTriState.msoTrue);
 
G

Guest

Steve Rindsberg said:
Have you tried specifying the constant for bitmap as a param to PasteSpecial rather than
the default? You'd expect the bitmap to BE the default in this case, but perhaps it's
not for some odd reason.

The only case in which PpPasteBitmap works is if I clip a portion from
MSPaint. However, PasteSpecial fails if I first copy an image stream from
Reporting Services (RS) to the clipboard. I would guess that this is because
of the list of available formats as RS output is binary data (that's what the
Clipboard Viewer utility says for some formats). Clipped MSPaint data on the
clipboard has 4 formats ("Embed Source", "Object Descriptor" ,
"MetaFilePict", and DeviceIndependentBitmap") but the data I copy from the
MemoryStream has only 2 ("System.Drawing.Bitmap" and "Bitmap") even though I
am specifying the autoconvert parameter. If I paste onto the clipboard using
some other format such as Dib or Tiff, only that format is available and not
viewable in Clipboard Viewer and PasteSpecial with any parameter fails.

The only case in which I can get a successful link from RS output to PPT
slide is if I render the RS output as Byte[] of HTML data, copy this to a
memory stream as text, and then use PasteSpecial with PpPasteText as the
parameter (PpPasteHtml fails even if I copy the stream to the clipboard as
HTML). However, in this case, I get the HTML code for the data rather than
the actual data itself, which is what I need. Similarly, PpPasteText works if
I copy some text from Notepad.
 
S

Steve Rindsberg

I'm not familiar with RS or image streams, but it certainly sounds as though nothing PPT
understands as an image is getting onto the clipboard. You'd think that DIB would work
in this situation, though, no? Can you manually PasteSpecial as DIB into PPT after
clipping it from MSPaint?
The only case in which PpPasteBitmap works is if I clip a portion from
MSPaint. However, PasteSpecial fails if I first copy an image stream from
Reporting Services (RS) to the clipboard. I would guess that this is because
of the list of available formats as RS output is binary data (that's what the
Clipboard Viewer utility says for some formats). Clipped MSPaint data on the
clipboard has 4 formats ("Embed Source", "Object Descriptor" ,
"MetaFilePict", and DeviceIndependentBitmap") but the data I copy from the
MemoryStream has only 2 ("System.Drawing.Bitmap" and "Bitmap") even though I
am specifying the autoconvert parameter. If I paste onto the clipboard using
some other format such as Dib or Tiff, only that format is available and not
viewable in Clipboard Viewer and PasteSpecial with any parameter fails.

The only case in which I can get a successful link from RS output to PPT
slide is if I render the RS output as Byte[] of HTML data, copy this to a
memory stream as text, and then use PasteSpecial with PpPasteText as the
parameter (PpPasteHtml fails even if I copy the stream to the clipboard as
HTML). However, in this case, I get the HTML code for the data rather than
the actual data itself, which is what I need. Similarly, PpPasteText works if
I copy some text from Notepad.
 
G

Guest

In fact, it's not just PPT that doesn't understand the format: after copying
my stream to the clipboard, I can't paste the contents into MSPaint either.
As you've nailed it, I too thought that DIB would have solved my problems but
it appears that there's some more info (one of the other 3 formats when I
clip from MSPaint) that is necessary.

I can clip from MSPaint and then PasteSpecial as Bitmap (there is no option
to paste as DIB).
 
S

Steve Rindsberg

Is it possible that what's appearing on the clipboard is a format that contains multiple
images rather than just one? Neither PPT nor Paint could cope with that.
 
G

Guest

Not sure how I can verify this. Could you please guide me? I have checked
that the TIFF image stream (for e.g.) appears on a single screen itself after
I save it to a file and then open the same in the MS Document Imaging TIFF
viewer. Is this what you were referring to?

FWIW, I think the problem is that I'm pasting binary data as a stream onto
the clipboard (as suggested by Clipboard Viewer in some cases) and this
binary data lacks some information that allows it to be converted to multiple
formats that provide some sort of meta/header data to apps that try to copy
off the clipboard (even though I specify auto-convert as True in all places).
 
S

Steve Rindsberg

FWIW, I think the problem is that I'm pasting binary data as a stream onto
the clipboard (as suggested by Clipboard Viewer in some cases) and this
binary data lacks some information that allows it to be converted to multiple
formats that provide some sort of meta/header data to apps that try to copy
off the clipboard (even though I specify auto-convert as True in all places).

I'm really just speculating here, but wouldn't binary data be any arbitrary data your
app cares to post to the clipboard rather than data in some format the
clipboard/windows/other apps recognize as standard types?

I suspect you'll need to put the data up there in some format that PPT can cope with.
 
G

Guest

True, which is why we have to specify the format when copying to the
clipboard. Problem is that it appears that you can only read off the
clipboard using a mechanism similar to copying onto it (IDataObject). Copying
off in any other way (PPT) seems to require some additional formatting info.
Also, as the available data formats show, I would think that the binary
stream has been enveloped on the clipboard with some meta info. Just appears
that PPT, Paint, etc. require some additional header info.

Is there any way I check this out directly with MS (how to convert binary
data to multiple formats when pasting on the clipboard so that apps such as
PPT, Paint, etc. can read it)?
 
S

Steve Rindsberg

True, which is why we have to specify the format when copying to the
clipboard. Problem is that it appears that you can only read off the
clipboard using a mechanism similar to copying onto it (IDataObject). Copying
off in any other way (PPT) seems to require some additional formatting info.
Also, as the available data formats show, I would think that the binary
stream has been enveloped on the clipboard with some meta info. Just appears
that PPT, Paint, etc. require some additional header info.

I am but a humble VBA pusher. We're getting way out of my league here, I have to confess.
I keep hoping one of our competent C/++/Sharp folks will pop up in this thread.

OH CHIRAG!! Help!
Is there any way I check this out directly with MS (how to convert binary
data to multiple formats when pasting on the clipboard so that apps such as
PPT, Paint, etc. can read it)?

Not sure offhand, but if you have an MSDN subscription, one of your support incidents or a
post to one of the managed groups (Win API probably?) might work.
 
G

Guest

Thanks all the same for all your inputs! You did provide a couple of new
directions for me to venture in. Hope Chirag or someone else can chip in.

Should I try reposting with a different subject/body or call Chirag's
attention to this in the subject itself? This is actually my first experience
with these groups so I'm not really sure of the protocol. I would appreciate
your guidance on this practical matter as well!

Thanks,
Ajay.
 
S

Steve Rindsberg

Should I try reposting with a different subject/body or call Chirag's
attention to this in the subject itself? This is actually my first experience
with these groups so I'm not really sure of the protocol. I would appreciate
your guidance on this practical matter as well!

Normally all of the regulars hop in when they see a subject they may be able to help
with, but it depends on the time available. I don't see any problem with starting a
new thread with Chirag's name in the title; then summarize what you've learned so far
so he doesn't have to plow through all of *my* idiotic speculations. ;-)
 
G

Guest

Hi Steve,

I was able to accomplish what I wanted to!!!

Just to recollect: my initial aim was to copy the output of SQL Server
Reporting Services to a PPT slide. Amongst my many other trials, I came
across the clipboard error that I had last posted.

The solution appears simple in hindsight:

AddPicture requires the path to a TIFF file. The Reporting Services Web
service provides the facility to render a report to an output TIFF stream.
This output TIFF stream can also be generated by using an appropriate
rendering URL for a specific report (the URL is part of the report that is
developed using Reporting Services). In the normal course, this URL generates
a Web dialog box (Open, Save, Cancel) that allows you to open/save the
generated TIFF stream as a file. Passing this URL as a parameter to
AddPicture allows PPT to add the contained image from the temporary file path
that the URL generates the file at. So, all's well that ends well!

Thank you for your constant inputs!!!

Regards,
Ajay.
 
S

Steve Rindsberg

I was able to accomplish what I wanted to!!!

Great! And thanks for coming back with the explanation. If I understand you
correctly, it's a matter of getting Reporting Services to write a file; after
that, bringing a picture into PPT is no different than importing any other image
file.
 
G

Guest

Yes ... you are spot on. We were initially not too clear on the URL access
feature of Reporting Services but after some (read tons!) of research, we
found that this feature writes data to a temp file, which it then retrieves
in the Web dialog box. From then on, it's like you said ... the same as
importing any other image file.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top