[Go] read the picture from the database and import the Excel file, C # Way

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.