Original address, author Lvyou1980
Direct Source Bar.
Using system;using system.io;using system.data;using system.drawing;using system.drawing.imaging;using system.windows.forms;using excel;private void Educeexcel () {string picpath=directory.getcurrentdirectory () + ' \ \ Excelpic.jpg '; String excelname=directory.getcurrentdirectory () + ' \\ExcelModul.xls '; String fileName = ' Excel ' +datetime.now.tostring (). Replace (': ', ') + '. xls '; Excel.Application app =new Excel.Application ();//Create an Excel object app. visible=true;//make Excel file visible Workbook objbook; Objbook = App. Workbooks.Add (Excelname); Worksheet Worksheet; Worksheet = (worksheet) objbook. WORKSHEETS[1]; Excel.pictures pics= (excel.pictures) worksheet. Pictures (Type.Missing);//Create Picture Collection object int td=1; int p=1; Picitemcolletion picitems= Picitem.getpictems ();//Read database picture data set foreach (Picitem pi in picitems) {if (pi. ImageData! = null) {MemoryStream stream = new MemoryStream (PI). ImageData, 0, PI. Imagedata.length); Bitmap Bitmap = new Bitmap (stream); Bitmap. Save (Picpath,sysTem. DRAWING.IMAGING.IMAGEFORMAT.JPEG)///Save temporary picture file to hard drive if (file.exists (Picpath)) {stream. Close ();//Turn off image file stream Range range_1 =range=worksheet.get_range (' A ' +td. ToString (), ' A ' +td. ToString ()); Gets the padding cell range pics. Insert (picpath,type.missing);//Get picture Excel.picture pic = (excel.picture) Pics. Item (P);//Create a picture collection of a Picture object pic. left = (double) range_1.left; Pic. Top = (double) range_1.top; Pic. Height = (double) range_1.height; Pic. Width = (double) range_1.width; td=td+1; p=p+1; }} if (File.exists (Picpath)) {file.delete (Picpath);//Delete picture}}
[Go] read the picture from the database and import the Excel file, C # Way