Error When Copying from Clipboard to PowerPoint slide

A

Ata

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);
 
A

Ata

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.
 
A

Ata

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).
 
A

Ata

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).
 
A

Ata

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)?
 
A

Ata

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.
 
A

Ata

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.
 
A

Ata

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