设置环境:
我正在使用vb.net开发Excel 2010应用程序级外接程序
我的目标:
此代码可用于临时保存并删除.png文件:
'Create temporary file path using the commonapplicationdata folder
Dim picturepath As StringBuilder
picturepath = New StringBuilder(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData))
picturepath.Append("\chartGridlines.png")
'Save resources into temp location in HD
My.Resources.grayGrid.Save(picturepath.ToString, System.Drawing.Imaging.ImageFormat.Png)
'Add picture to the worksheet
With Globals.ThisAddIn.Application.Selection.ShapeRange.Fill
.UserPicture(picturepath.ToString())
End With
'Clean up and delete the png from commonapplicationdata folder
System.IO.File.Delete(picturepath.ToString())
如何为.xlsm文件做同样的事情?
有人会提供一个关于如何做到这一点的指针吗?我真的很感激。
答案 0 :(得分:1)
就这样做:
Imports System.IO
...
File.WriteAllBytes("C:\Path\to\NameList.xlsm", My.Resources.NameList)
不同之处在于图像存储为Bitmap对象,但Excel文件存储为字节数组。
干杯