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. sql where,group by ,having,order by用法和区别

    select 子句 指定列 可放置分组函数 where子句:限制行 group by 子句:对数据进行分组 和 having子句:限定组.和group by 一起使用 (对分组时候进行筛选)可放置分组 ...

  2. Scrapy框架-----爬虫

    说明:文章是本人读了崔庆才的Python3---网络爬虫开发实战,做的简单整理,希望能帮助正在学习的小伙伴~~ 1. 准备工作: 安装Scrapy框架.MongoDB和PyMongo库,如果没有安装, ...

  3. linux异步IO的两种方式【转】

    转自:https://blog.csdn.net/shixin_0125/article/details/78898146 知道异步IO已经很久了,但是直到最近,才真正用它来解决一下实际问题(在一个C ...

  4. innodb表碎片处理

    本次测试环境是 mysql 5.7.23,表空间为每个表单独表空间 mysql> sHOW VARIABLES LIKE 'innodb_file_per_tabl%'; +---------- ...

  5. 【原创】大叔经验分享(10)Could not transfer artifact org.apache.maven:maven. from/to central. Received fatal alert: protocol_version

    maven编译工程报错 [ERROR] Failed to execute goal net.alchim31.maven:scala-maven-plugin:3.2.2:add-source (s ...

  6. WPF样式中TargetType 属性 (Property) 和 x:Key 属性 (Attribute)

    如第一个示例所示,如果将 TargetType 属性设置为 TextBlock 而不为样式分配 x:Key,样式就会应用于所有 TextBlock 元素.这种情况下,x:Key 隐式设置为 {x:Ty ...

  7. noj算法 踩气球 回溯法

    描述: 六一儿童节,小朋友们做踩气球游戏,气球的编号是1-100,两位小朋友各踩了一些气球,要求他们报出自己所踩气球的编号的乘积.现在需要你编一个程序来判断他们的胜负,判断的规则是这样的:如果两人都说 ...

  8. 使用mysqlslap进行MySQL压力测试

    使用mysqlslap进行MySQL压力测试发表于236 天前 ? MySQL ? 暂无评论 MySQL从5.1.4版开始带有一个压力测试工具mysqlslap,通过模拟多个并发客户端访问mysql来 ...

  9. ansible的logging模块用来写日志

    [root@node-1 library]# cat dolog.py #!/bin/env python ANSIBLE_METADATA = { 'metadata_version': 'alph ...

  10. ssh-copy-id Permission denied (publickey,gssapi-keyex,gssapi-with-mic). 的解决方案

    -bash-4.2# ssh-copy-id 192.168.9.180 /usr/bin/ssh-copy-id: INFO: attempting to log in with the new k ...