string file = @"C:\sample.xlsx";

        if(System.IO.File.Exists(file))
{ Microsoft.Office.Interop.Excel.Application excelApp = new Microsoft.Office.Interop.Excel.Application();
excelApp.Visible = true; //FOR TESTING ONLY
Microsoft.Office.Interop.Excel.Workbook wb = excelApp.Workbooks.Open(file,
Type.Missing,
Type.Missing,
Type.Missing,
Type.Missing,
Type.Missing,
Type.Missing,
Type.Missing,
Type.Missing,
Type.Missing,
Type.Missing,
Type.Missing,
Type.Missing,
Type.Missing,
Type.Missing); Microsoft.Office.Interop.Excel.Worksheet ws = (Microsoft.Office.Interop.Excel.Worksheet)wb.Sheets[]; //Selects the first sheet
Microsoft.Office.Interop.Excel.Range range = (Microsoft.Office.Interop.Excel.Range)ws.Cells[, ]; //Select cell A1
object cellValue = range.Value2; #region Extract the image
Microsoft.Office.Interop.Excel.Picture pic = (Microsoft.Office.Interop.Excel.Picture)ws.Pictures(); if (pic != null)
{
//This code will detect what the region span of the image was
int startCol = (int)pic.TopLeftCell.Column;
int startRow = (int)pic.TopLeftCell.Row;
int endCol = (int)pic.BottomRightCell.Column;
int endRow = (int)pic.BottomRightCell.Row; pic.CopyPicture(Microsoft.Office.Interop.Excel.XlPictureAppearance.xlScreen, Microsoft.Office.Interop.Excel.XlCopyPictureFormat.xlBitmap);
if (Clipboard.ContainsImage())
{
Image img = Clipboard.GetImage();
this.pictureBox1.Image = img;
}
}
#endregion //Close the workbook
wb.Close(false,Type.Missing,Type.Missing); //Exit Excel
excelApp.Quit();
}

work great for me in my web application with a little change it was not copying image to clipboard

Thread thread = new Thread(() =>
{
foreach (var pic in ws.Pictures())
{
if (pic != null)
{
//This code will detect what the region span of the image was
int startCol = pic.TopLeftCell.Column;
int startRow = pic.TopLeftCell.Row;
int endCol = pic.BottomRightCell.Column;
int endRow = pic.BottomRightCell.Row;
pic.CopyPicture(XlPictureAppearance.xlScreen, XlCopyPictureFormat.xlBitmap);
if (Clipboard.GetDataObject() != null)
{
Image img = Clipboard.GetImage();
}
}
}
});
thread.SetApartmentState(ApartmentState.STA);
//Set the thread to STA
thread.Start();
thread.Join();

Retrieve pictures from Excel file using OLEDB的更多相关文章

  1. Read Excel file from C#

    Common way is: var fileName = string.Format("{0}\\fileNameHere", Directory.GetCurrentDirec ...

  2. csharp:using OpenXml SDK 2.0 and ClosedXML read excel file

    https://openxmlexporttoexcel.codeplex.com/ http://referencesource.microsoft.com/ 引用: using System; u ...

  3. The 13th tip of DB Query Analyzer, powerful processing EXCEL file

    The 13thtip of DB Query Analyzer, powerful processing EXCEL file MA Genfeng (Guangdong UnitollServic ...

  4. NetSuite SuiteScript 2.0 export data to Excel file(xls)

    In NetSuite SuiteScript, We usually do/implement export data to CSV, that's straight forward: Collec ...

  5. Creating Excel File in Oracle Forms

    Below is the example to create an excel file in Oracle Forms.Pass the Sql query string to the below ...

  6. Formatting Excel File Using Ole2 In Oracle Forms

    Below is the some useful commands of Ole2 to format excel file in Oracle Forms.-- Change font size a ...

  7. Read / Write Excel file in Java using Apache POI

    Read / Write Excel file in Java using Apache POI 2014-04-18 BY DINESH LEAVE A COMMENT About a year o ...

  8. How to create Excel file in C#

    http://csharp.net-informations.com/excel/csharp-create-excel.htm Before you create an Excel file in ...

  9. Apache POI – Reading and Writing Excel file in Java

    来源于:https://www.mkyong.com/java/apache-poi-reading-and-writing-excel-file-in-java/ In this article, ...

随机推荐

  1. 【js课设】电子画板01

    这学期web开发课的课设选了电子画板课题.(人家本来想做富文本编辑器的嘛然鹅老师在第二版里把这题删掉了。゚ヽ(゚´Д`)ノ゚。) 主要考虑的有[界面美观][画笔类型][画布分层]这三个点了. [界面美 ...

  2. 🍓 DOM常用基础知识点汇总(入门者适用) 🍓

    铛-今天又没啥事,来总结一下DOM的基础知识.(公司没活干我也很无奈

  3. SQL Server - ISNULL

    ISNULL 使用指定的替换值替换 NULL. 语法       ISNULL ( check_expression , replacement_value ) 参数    check_express ...

  4. TCP-IP详解学习笔记2

    TCP-IP详解学习笔记2 链路层 链路层的目的是为IP模块发送和接收IP数据报: TCP/IP支持多种不同的链路层,依赖于使用网络硬件类型:有线局域网(以太网,城域网(MAN),有线语音网络).无线 ...

  5. 【easy】112.path sum 113.-----------------

    求是否有从根到叶的路径,节点和等于某个值. /** * Definition for a binary tree node. * struct TreeNode { * int val; * Tree ...

  6. 【原创】数据库基础之Mysql(2)主从库配置

    一 安装 # wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm# yum -y insta ...

  7. 分布式Session共享解决方案

    分布式Session解决方案 Author:SimpleWu 分布式Session一致性? 说白了就是服务器集群Session共享的问题 Session的作用? Session 是客户端与服务器通讯会 ...

  8. cc.Node 的坐标空间与ACTION的学习

    1.创建二维的向量坐标 //创建向量坐标方法一 let new_pos1 = new cc.Vec2(100, 100); //创建向量坐标方法二 let new_pos2 = cc.v2(200, ...

  9. 批量执行 sql 的 shell 脚本

    最近有用到需要批量导入N个表的sql,一个个导入会吐老血的,写了个shell脚本,便捷导入. 通常我们导入单个sql,可以用 $mysql -uroot -p world < xxxx.sql ...

  10. 办公用品管理系统VB——库存数量导出EXCEL,SaveEXCEL

    办公用品管理系统VB——库存数量导出EXCEL,SaveEXCEL 总体来说,VB的EXCEL导出效率还是蛮低的,就是一个小型化的办公用品管理软件,不再优化了. 时间紧迫,就没有从头到尾的用C#编写, ...