惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

腾讯CDC
Schneier on Security
Schneier on Security
B
Blog RSS Feed
aimingoo的专栏
aimingoo的专栏
P
Proofpoint News Feed
A
About on SuperTechFans
Recorded Future
Recorded Future
Recent Announcements
Recent Announcements
Microsoft Security Blog
Microsoft Security Blog
L
LangChain Blog
Hugging Face - Blog
Hugging Face - Blog
The GitHub Blog
The GitHub Blog
Google DeepMind News
Google DeepMind News
T
Tailwind CSS Blog
Vercel News
Vercel News
H
Hackread – Cybersecurity News, Data Breaches, AI and More
MyScale Blog
MyScale Blog
V2EX - 技术
V2EX - 技术
N
Netflix TechBlog - Medium
F
Fortinet All Blogs
V
Visual Studio Blog
Martin Fowler
Martin Fowler
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
博客园 - Franky
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
T
The Exploit Database - CXSecurity.com
F
Full Disclosure
Scott Helme
Scott Helme
H
Heimdal Security Blog
博客园 - 叶小钗
Google DeepMind News
Google DeepMind News
Cyberwarzone
Cyberwarzone
Application and Cybersecurity Blog
Application and Cybersecurity Blog
V
Vulnerabilities – Threatpost
Blog — PlanetScale
Blog — PlanetScale
Security Latest
Security Latest
WordPress大学
WordPress大学
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
T
Troy Hunt's Blog
S
SegmentFault 最新的问题
Forbes - Security
Forbes - Security
Jina AI
Jina AI
S
Securelist
小众软件
小众软件
Simon Willison's Weblog
Simon Willison's Weblog
J
Java Code Geeks
AWS News Blog
AWS News Blog
N
News and Events Feed by Topic
博客园 - 三生石上(FineUI控件)
量子位

博客园 - Meyer

SQL Server不能通过条件控制生成同名的存储过程 我的2004 SQL中一个不明的错误 String TechEd流水帐 行医要厚道 Tech ed 2004 sh Asp.net程序的身份 delphi与asp.net - Meyer - 博客园 被C#2005 Express 撞了一下腰 闲话一 ActiveX CRView 与Asp.net 在水晶报表中显示条形码 Crystal Report&Barcode Crystal Report 新工作 这是.Text 的trackback功能吗? about zhanbos' quiz GMail I Get
NPOI中嵌入图片
Meyer · 2009-03-29 · via 博客园 - Meyer

感谢Tony移植了POI到了.net平台,我尝试了一下.

关键的几行代码如下

创建HSSFPatriarch对象,如果有多张图片需要添加,只能有一个HSSFPatriarch对象。

HSSFPatriarch patriarch = sheet1.CreateDrawingPatriarch();
byte[] buff = File.ReadAllBytes("/home/meyer/030.jpg");
int pic = hssfworkbook.AddPicture(buff,HSSFWorkbook.PICTURE_TYPE_JPEG);
HSSFClientAnchor anchor 
= new HSSFClientAnchor(0,0,0,0,1,1,2,2);
anchor.AnchorType 
= 2;
patriarch.CreatePicture(anchor,pic);

JAVA的POI上的文档说只能支持:jpg,png,dib三种格式。

对于常见的gif是没有支持的。HSSFWorkbook中也没有PICTURE_TYPE_GIF的定义。

不过,好玩的是你可以在NPOI中尝试下面的代码

byte[] buff = File.ReadAllBytes("/home/meyer/xml.gif");
int pic = hssfworkbook.AddPicture(buff,HSSFWorkbook.PICTURE_TYPE_JPEG);