在C#中使用Excel中的相对路径添加图像 [英] add Image with relative path in Excel in C#

查看:298
本文介绍了在C#中使用Excel中的相对路径添加图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

worksheet.Pictures.Add("Penguins.jpg", PositioningMode.MoveAndSize,

    new AnchorCell(worksheet.Columns[0], worksheet.Rows[0], true),

    new AnchorCell(worksheet.Columns[10], worksheet.Rows[10], false));







How to Pass First Parameter which is image path Dynamically oR relative path in first parameter





谢谢



Thank You

推荐答案

如果relative不工作,那么只需使用完整路径。您可以使用



If relative is not working then just use the full path. You can get the path to your workbook by using

Application.ActiveWorkbook.Path

获取工作簿的路径




您可以使用应用程序 StartupPath [ ^ ],它返回启动应用程序的可执行文件的路径,不包括可执行文件名。



< a href =http://msdn.microsoft.com/en-us/library/aa457089.aspx>如何:确定执行应用程序的路径 [ ^ ]



[/ EDIT ]


You can use application StartupPath[^], which returns the path for the executable file that started the application, not including the executable name.

HOW TO: Determine the Executing Application's Path[^]

[/EDIT]
String sFile = "MyPicture.jpg";
String sPath = Application.StartupPath + "\\Images\\" + sFile;

worksheet.Pictures.Add(sPath + , PositioningMode.MoveAndSize,  new AnchorCell(worksheet.Columns[0], worksheet.Rows[0], true),  new AnchorCell(worksheet.Columns[10], worksheet.Rows[10], false));





看看这里:

1)图片

添加图片到电子表格非常简单 [ ^ ]

2)使用形状

如何从C#App在Excel中插入图片 [ ^ ]

3)剪贴板中的位图

如何使用C#以编程方式将图片或图标添加到Excel工作表 [ ^ ]



Have a look here:
1) pictures
Adding pictures to a spreadsheet is very easy[^]
2) using shapes
How to insert a picture in excel from C# App[^]
3) bitmap from Clipboard
How to programmatically add a Picture or Icon to an Excel WorkSheet using C#[^]


这篇关于在C#中使用Excel中的相对路径添加图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆