Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Foo Foo is offline
external usenet poster
 
Posts: 1
Default Paste bitmap to Excel

When the following function is run by a Windows program it works just fine.
When it is run from an ASP.NET page the xlWorkSheet.PasteSpecial line
generates: "Exception from HRESULT: 0x800A03EC."

The page is set up with the aspcompat="true" page directive to avoid an
exception about the lack of a Single threaded apartment.
It is also run with impersonation to the same user that runs the Windows
executable.

Any ideas, or other ways to get a bitmap into the sheet?

using System;
using System.Reflection;
using System.Globalization;
using System.Windows.Forms;
using System.Drawing;
using Excel = Microsoft.Office.Interop.Excel;

public void PasteBitmap()
{
CultureInfo oC = System.Threading.Thread.CurrentThread.CurrentCultu re;
System.Threading.Thread.CurrentThread.CurrentCultu re = new
CultureInfo("en-US"); // To work around bug 320369

Excel.Application xl = new Excel.Application();
xl.Visible = false;
Excel.Workbook xlWorkBook = xl.Workbooks.Add(Missing.Value);
Excel.Worksheet xlWorkSheet = (Excel.Worksheet)xlWorkBook.ActiveSheet;

Image logo = Image.FromFile("D:\\Images\\logo.bmp");
Clipboard.SetDataObject(logo);
Excel.Range xlRange = (Excel.Range)xlWorkSheet.Cells[1,1];
xlRange.Select();
xlWorkSheet.PasteSpecial("Bitmap",false,false,stri ng.Empty,0,string.Empty,true);
System.Runtime.InteropServices.Marshal.ReleaseComO bject (xlRange);
System.Runtime.InteropServices.Marshal.ReleaseComO bject (xlWorkSheet);
System.Runtime.InteropServices.Marshal.ReleaseComO bject (xlWorkBook);
System.Runtime.InteropServices.Marshal.ReleaseComO bject (xl);
xlRange = null;
xlWorkSheet = null;
xlWorkBook = null;
xl = null;

System.Threading.Thread.CurrentThread.CurrentCultu re = oC;
}

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Cannot copy Excel 2007 Chart and Paste as Bitmap into Powerpoint 2 SysMod Charts and Charting in Excel 6 September 30th 09 03:58 PM
How to paste a bitmap-excel paste doesn't work... Your Display Name here... Excel Discussion (Misc queries) 0 August 27th 09 06:38 PM
Excel copies as a bitmap SueD Excel Discussion (Misc queries) 0 June 20th 07 12:12 PM
How can I put text over a bitmap picture in Excel? jkatsoff Excel Discussion (Misc queries) 1 March 11th 06 02:02 AM
Writing bitmap to Excel Spreadsheet Macca Excel Programming 0 September 21st 04 02:41 PM


All times are GMT +1. The time now is 08:13 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"