如何从Excel数据库中的PictureBox插入图像? [英] How to Insert Image from PictureBox in Excel Database?
问题描述
嗨朋友们,
我正在研究名为Employe Record Management的项目。现在,我想插入所有记录和雇员,包括他们的PictureImage。我完成了插入其他记录,如名字姓氏等,但现在我坚持插入图像到Excel数据库。请教我写插入图像的查询。
我用来存储图像的代码如下..
< pre lang =c#> pictureBox_Profile_Picture.Image.Save(FilePath,System.Drawing.Imaging.ImageFormat.Jpeg)
但它不起作用..请帮我另外一些代码。
提前致谢:)
private void insertImage()
{
Excel.Application ThisApplication = new Excel.Application();
Excel.Workbook ThisWorkBook;
string _stFileName =C:\\Users\\Rupam \\Desktop\\Test.xlsx;
string _stLOGO =D:\\LOGO.bmp;
对象缺失= System.Reflection.Missing.Value;
尝试
{
ThisWorkBook = ThisApplication.Workbooks.Open(_stFileName,缺失,缺失,5,缺失,缺失,缺失,缺失,缺失,缺失,缺失,缺失,失踪,失踪,失踪);
Excel.Worksheet ThisSheet =(Excel.Worksheet)ThisWorkBook.Sheets [1];
Excel.Range oRange =(Excel.Range)ThisSheet.Cells [10,1];
Image oImage = pictureBox1.Image;
System.Windows.Forms.Clipboard.SetDataObject(oImage,true);
ThisSheet.Paste(oRange,_stLOGO);
ThisWorkBook.Save();
}
catch(Exception oEx)
{MessageBox.Show(oEx.Message); }
最后
{
ThisApplication.Quit();
ThisWorkBook = null;
ThisApplication = null;
}
}
请在此处查看msdn帖子:
http://social.msdn.microsoft.com /论坛/ zh-CN / csharpgeneral / thread / 5bb5eb47-ea5e-4d97-a794-6266122552ea [ ^ ]
重要提示:还包括来自的Microsoft Excell对象库添加参考 - > Com选项卡和Microsoft Office对象库
另外
使用Excel = Microsoft .Office.Interop.Excel;
使用命名空间部分代码顶部的上一行。
作为同等解释,请阅读一些文档,以了解其中的工作原理。
Hi Friends,
Well I am working on project called Employe Record Management. Now here i wants to insert all the records of and employes including their PictureImage. I am done with the insert other records like Firstname Lastname etc but now i stuck in inserting Image in to Excel Database. Pleease Hellp me to write the Query of inserting Image.
The Code which i am using to store image is as follow..
pictureBox_Profile_Picture.Image.Save(FilePath,System.Drawing.Imaging.ImageFormat.Jpeg)
but its not working.. Please help me with some another code.
Thanks in advance :)
private void insertImage() { Excel.Application ThisApplication = new Excel.Application(); Excel.Workbook ThisWorkBook; string _stFileName = "C:\\Users\\Rupam\\Desktop\\Test.xlsx"; string _stLOGO = "D:\\LOGO.bmp"; object missing = System.Reflection.Missing.Value; try { ThisWorkBook = ThisApplication.Workbooks.Open(_stFileName, missing, missing, 5, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing); Excel.Worksheet ThisSheet = (Excel.Worksheet)ThisWorkBook.Sheets[1]; Excel.Range oRange = (Excel.Range)ThisSheet.Cells[10, 1]; Image oImage = pictureBox1.Image; System.Windows.Forms.Clipboard.SetDataObject(oImage, true); ThisSheet.Paste(oRange, _stLOGO); ThisWorkBook.Save(); } catch (Exception oEx) { MessageBox.Show(oEx.Message); } finally { ThisApplication.Quit(); ThisWorkBook = null; ThisApplication = null; } }
See the msdn post here:
http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/5bb5eb47-ea5e-4d97-a794-6266122552ea[^]
Important: Also include Microsoft Excell Object Library from Add Reference-> Com tab and Microsoft Office object Library
Also
using Excel = Microsoft.Office.Interop.Excel;
use the above line at the top of code in namespace section.
As par explanation, read through some documents to get an overview of how stuff works.
这篇关于如何从Excel数据库中的PictureBox插入图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!