Retrieve pictures from Excel file using OLEDB
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的更多相关文章
- Read Excel file from C#
Common way is: var fileName = string.Format("{0}\\fileNameHere", Directory.GetCurrentDirec ...
- csharp:using OpenXml SDK 2.0 and ClosedXML read excel file
https://openxmlexporttoexcel.codeplex.com/ http://referencesource.microsoft.com/ 引用: using System; u ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- How to create Excel file in C#
http://csharp.net-informations.com/excel/csharp-create-excel.htm Before you create an Excel file in ...
- 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, ...
随机推荐
- KL散度
摘自: https://www.jianshu.com/p/43318a3dc715?from=timeline&isappinstalled=0 一.解决的问题 量化两种概率分布P和Q可以使 ...
- SpringBoot中Application开启与关闭
0.声明 缘由:没有学过或者没有经历SpringBoot的Application运行机制的话,一定会好奇,博主为啥会写一篇关闭开启的博文,是不是好幼稚?(/o(╥﹏╥)o),待我娓娓道来......为 ...
- poj100纪念
- oracle的安装与卸载
安装oracle: 下载符合系统要求的oracle数据库 2. 将上面的压缩文件都解压到一个文件夹中,然后以管理员的身份运行其中的可执行文件(.exe) 3. 配置安全更新(可选可不选,学习时我没 ...
- mysql 分库分表 ~ ShardingSphere生态圈
一 简介 Apache ShardingSphere是一款开源的分布式数据库中间件组成的生态圈二 成员包含 Sharding-JDBC是一款轻量级的Java框架,在JDBC层提供上述核心功能 ...
- Linux IO Scheduler(Linux IO 调度器)【转】
每个块设备或者块设备的分区,都对应有自身的请求队列(request_queue),而每个请求队列都可以选择一个I/O调度器来协调所递交的request.I/O调度器的基本目的是将请求按照它们对应在块设 ...
- Java_Number(装箱和拆箱)
所有的包装类(Integer.Long.Byte.Double.Float.Short)都是抽象类Number子类 装箱: 自动将基本数据类型装换为包装器类型 拆箱: 自动将包装器类型转换为基本数据类 ...
- 此主机支持Intel VT-x,但Intel VT-x处于禁用状态
原因:未开启虚拟化技术 解决方法:https://www.cnblogs.com/jiefu/p/10711955.html
- 七.HTTP协议原理介绍
01. 当用户访问一个网站时,都发生了事情? ①. 利用DNS服务,将输入的域名解析为相应的IP地址 a --本地主机输入域名后,会查询本地缓存信息和本地hosts文件 如果有就进行解析,如果没有 ...
- Niagara workbench (Basic )
1.the basic information about workbench Last saved station open in the workbench or opened another ...