CopyPicture in Office 2003 & Office 2007

D

Doug

Hi Everyone,

I've been testing my app in Office 2007, and found a problem with the
behaviour of the CopyPicture method in Office 2007, specifically on the Range
object.

My app copies to the clipboard a bitmap of the current spreadsheet, so i can
save it as an image file, this currently works in Office 2003. The routine
i'm using to get the data off the clipboard expects that a Bitmap is added.
However in Office 2007, if i use the CopyPicture method to copy an image to
the clipboard, telling it to copy using a format of
XlCopyPictureFormat.xlBitmap, it seems to disregards the format and copies to
the clipboard as an enhanced metafile.

See below for a cutdown example of what i'm doing in code.

Does anybody have any idea why this behaviour appears to have been changed?
Does anybody have any ideas on how i can work around my problem?

Thanks in advance,

Doug.

using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Windows.Forms;
namespace ExcelTest
{
class Program
{
[STAThread]
static void Main(string[] args)
{
Excel.Application oXL;
Excel._Workbook oWB;
Excel._Worksheet oSheet;
Excel.Range oRng;

oXL = new Excel.Application();
oXL.Visible = false;
oWB =
(Excel._Workbook)(oXL.Workbooks.Add(System.Reflection.Missing.Value));
oSheet = (Excel._Worksheet)oWB.ActiveSheet;

oSheet.Cells[1, 1] = "abc";
oSheet.Cells[1, 2] = "def";
oSheet.Cells[1, 3] = "ghi";
oSheet.Cells[2, 1] = 1;
oSheet.Cells[2, 2] = 2;
oSheet.Cells[2, 3] = 3;

oRng = oSheet.get_Range(oSheet.Cells[1, 1], oSheet.Cells[2, 3]);

oRng.CopyPicture(Excel.XlPictureAppearance.xlScreen,
Excel.XlCopyPictureFormat.xlBitmap);

if (Clipboard.ContainsImage())
{
Console.WriteLine"Image is on the clipboard");
}
else
{
Console.WriteLine("No image on the clipboard");
}

MessageBox.Show("End of Process");
}
}
}
 

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