![]() |
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; } |
All times are GMT +1. The time now is 05:21 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com