Click here to Skip to main content
15,900,378 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
New to VB 2008. How can i include an Excel file in a visual basic standalone application ? When program starts all data is loaded into a matrix,so no editing capability is needed, just to include it in the final application without user having access to original excel file.
I have tried adding that as a resource, but get run time error:
...
Wb = XLApp.Workbooks.Open(my.Resources.sample3.xcl)
...

Thanks for your help.
Posted

1 solution

If the only thing you need from the Excel file is data, I would really recommend breaking the problem into two separate applications:

  1. A utility app, that you run only in your development environment, which converts the data from Excel to comma separated txt-file. Or just use Excel - save as CSV, if the Excel file does not change very often.
  2. In your standalone application that you distribute to users, you embed the text file. Then your my.Resources.filename, will be a string and you can just read it line-by-line and split with commas.

This approach makes everything faster and you avoid a host of potential problems which may arrive if users have different versions of Office etc.

If your data is more complex, better option is to use XML format instead of CSV, which makes a few lines more code, but if it is just a matrix with simple data, CSV should be fine.

I don't know whether it is possible to open an Excel file from an embedded resource stream. If not you would need to take the stream and save it as a file to a temp folder. But I really do not see the reason to do that in your scenario.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900