【问题标题】:How to use vb.net to save an embedded project resource (excel worksheet) to a user's desktop如何使用 vb.net 将嵌入式项目资源(excel 工作表)保存到用户桌面
【发布时间】:2014-04-19 02:44:25
【问题描述】:

设置环境:

我正在使用 vb.net 开发 Excel 2010 应用程序级插件。

我的目标:

  1. 将项目资源(即 Excel 工作表)临时保存到用户的 电脑
  2. 使用 vb.net 以编程方式查询电子表格
  3. 完成后删除文件


此代码用于临时保存然后删除 .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 文件做同样的事情?

有人能指点我如何去做这件事吗?我真的很感激。

【问题讨论】:

    标签: .net vb.net excel visual-studio-2010 vsto


    【解决方案1】:

    就这样做吧:

    Imports System.IO
    
    ...
    
    File.WriteAllBytes("C:\Path\to\NameList.xlsm", My.Resources.NameList)
    

    区别是因为图片存储为Bitmap对象,而Excel文件存储为字节数组。

    干杯

    【讨论】:

    • 太棒了,正是我需要的。我知道这很简单。谢谢!
    猜你喜欢
    • 2013-07-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-25
    相关资源
    最近更新 更多