Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Loading AxSpreadsheet from a .NET resource
Hi,
I'd like to be able to include my Excel templates (XML files) as resources in the assembly rather than separate files only I can't find a method of loading these into the AxSpreadsheet. The XMLUrl property on accepts URL's not strings so the only way I can think of is to extract the resource, save to a temprary file, load and then delete the temporary file. I'd like to find a more elegant solution if I can. Any ideas anyine? |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Loading AxSpreadsheet from a .NET resource
Hi
We can add the excel file(e.g. xls) into the project, and in the properties to change the build action into embedded resources, so that the xls file will be compiled into the assebmly. And then we can use he code below to retrieve the xls file and write to disk for use. string[] names=Assembly.GetExecutingAssembly().GetManifestR esourceNames(); System.IO.Stream sm = Assembly.GetExecutingAssembly().GetManifestResourc eStream(names[0]); byte[] bts = new byte[sm.Length]; FileStream fs =new ); sm.Position = 0; int i = (int)sm.Read(bts,0,(int)sm.Length); fs.Write(bts,0,i); fs.Close(); sm.Close(); Best regards, Peter Huang Microsoft Online Partner Support Get Secure! - www.microsoft.com/security This posting is provided "AS IS" with no warranties, and confers no rights. |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Loading AxSpreadsheet from a .NET resource
Peter,
Thanks, I had hoped I might be able to load the resource directly into the AxSpreadsheet but this is a useable solution. ""Peter Huang" [MSFT]" wrote: Hi We can add the excel file(e.g. xls) into the project, and in the properties to change the build action into embedded resources, so that the xls file will be compiled into the assebmly. And then we can use he code below to retrieve the xls file and write to disk for use. string[] names=Assembly.GetExecutingAssembly().GetManifestR esourceNames(); System.IO.Stream sm = Assembly.GetExecutingAssembly().GetManifestResourc eStream(names[0]); byte[] bts = new byte[sm.Length]; FileStream fs =new ); sm.Position = 0; int i = (int)sm.Read(bts,0,(int)sm.Length); fs.Write(bts,0,i); fs.Close(); sm.Close(); Best regards, Peter Huang Microsoft Online Partner Support Get Secure! - www.microsoft.com/security This posting is provided "AS IS" with no warranties, and confers no rights. |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Loading AxSpreadsheet from a .NET resource
Peter,
Rather than use the root of C: (which is locked down under group policy) I'm trying to use the Isolated Storage directory hive. However, although I can create the file I can't get a fully resolved path to it!! Any ideas? ""Peter Huang" [MSFT]" wrote: Hi We can add the excel file(e.g. xls) into the project, and in the properties to change the build action into embedded resources, so that the xls file will be compiled into the assebmly. And then we can use he code below to retrieve the xls file and write to disk for use. string[] names=Assembly.GetExecutingAssembly().GetManifestR esourceNames(); System.IO.Stream sm = Assembly.GetExecutingAssembly().GetManifestResourc eStream(names[0]); byte[] bts = new byte[sm.Length]; FileStream fs =new ); sm.Position = 0; int i = (int)sm.Read(bts,0,(int)sm.Length); fs.Write(bts,0,i); fs.Close(); sm.Close(); Best regards, Peter Huang Microsoft Online Partner Support Get Secure! - www.microsoft.com/security This posting is provided "AS IS" with no warranties, and confers no rights. |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Loading AxSpreadsheet from a .NET resource
Hi
IsolatedStorage's concrete file path is controled by .NET framework, we should always use IsolatedStorage's method to write/read the data. Usually it is in the directory below. C:\Documents and Settings\v-phuang\Local Settings\Application Data\IsolatedStorage e.g. You will find it is not predictable. C:\Documents and Settings\v-phuang\Local Settings\Application Data\IsolatedStorage\3tc5ggky.5gr\dmwbcbtm.f2w\Url .kddvnk2rsg3bfnvnoazlcymom ubiim5q You can use the Isolated Storage Tool (Storeadm.exe) utility to list and remove the Isolated Storage files that are created with this console application. IsolatedStorageFile Class Represents an isolated storage area containing files and directories. Here is some code about how to read and write to files with IsolatedStorageFileStream Reading and Writing to Files http://msdn.microsoft.com/library/de...us/cpguide/htm l/cpconreadingwritingtofiles.asp Best regards, Peter Huang Microsoft Online Partner Support Get Secure! - www.microsoft.com/security This posting is provided "AS IS" with no warranties, and confers no rights. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Resource Scheduling/loading | Excel Worksheet Functions | |||
Resource loading (difficulty with date functions) | Excel Worksheet Functions | |||
Using axSpreadsheet | Excel Worksheet Functions | |||
Available Resource Error | Excel Discussion (Misc queries) | |||
Opening an Excel file in OWC10.AxSpreadSheet | Excel Programming |