简体   繁体   English

如何使用vb.net将嵌入式项目资源(Excel工作表)保存到用户的桌面

[英]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: 我的目标:

  1. Temporarily save a project resource (ie an excel worksheet) to a user's computer 临时将项目资源(例如excel工作表)保存到用户的计算机上
  2. Use vb.net to programmatically query the spreadsheet 使用vb.net以编程方式查询电子表格
  3. After finished, delete the file 完成后,删除文件


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文件怎么做?

Visual Studio 2010

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.

相关问题 如何在Excel文件工作表中选择特定列,然后使用vb.net将它们存储到SQL Server数据库中 - How to select a specific column in an excel file worksheet and then store them into an SQL Server database using vb.net 我如何在 VB.NET 中使用 Excel 函数 - How do i use an Excel function in VB.NET 如何在vb.net中使用嵌入式资源正确使用名称空间? - How do I properly use namespaces in vb.net with embedded resources? 如何在 VB.NET 中的用户计算机上安装字体,以便 Word 等应用程序可以使用它? - How do I install a font on a user's machine in VB.NET so applications like Word can use it? 如何使用vb.net检索具有合并单元格的复杂Excel文件并另存为xml文件? - How to retrieve complex excel file with merged cells and save as xml file using vb.net? vb.net,如何覆盖用户桌面字体设置 - vb.net, how to override users desktop font settings 使用VB.NET应用程序将HTML表从剪贴板粘贴到Excel工作表中 - Pasting HTML table from clipboard to Excel worksheet with VB.NET Application 如何在ASP.Net中使用嵌入式资源? - How to use embedded resource in ASP.Net? 如何在VB.NET中使用IsNullOrEmpty? - How to use IsNullOrEmpty in VB.NET? 如何在VB.NET中使用Dictionary类 - How to use Dictionary class in VB.NET
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM