[英]How to use vb.net to save an embedded project resource (excel worksheet) to a user's desktop
Setup Environment: 设置环境:
I'm developing an Excel 2010 Application Level Add-in using vb.net. 我正在使用vb.net开发Excel 2010应用程序级加载项。
My goal: 我的目标:
This code works to temporarily save and then delete a .png file: 此代码可以临时保存然后删除.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())
How to do the same thing for .xlsm file? .xlsm文件怎么做?
Would someone provide a pointer on how I could go about doing this? 有人会为我提供如何执行此操作的指示吗? I'd really appreciate it.
我真的很感激。
Just do like this: 就是这样:
Imports System.IO
...
File.WriteAllBytes("C:\Path\to\NameList.xlsm", My.Resources.NameList)
The difference is because the image is stored as a Bitmap object, but the Excel file is stored as a byte array. 区别在于,图像存储为位图对象,而Excel文件存储为字节数组。
Cheers 干杯
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.