Spire.XLS is a professional Excel API that enables developers to create, manage, manipulate, convert and print Excel worksheets. Get free and professional technical support for Spire.XLS for .NET, Java, Android, C++, Python.

Thu Dec 29, 2011 10:15 pm

Hi, I was wondering if anyone can help, I have a silverlight application and have integrated the Spire.XLS, all good, I have laid out my sheet and all is OK. Now i want to incorporate an image or 2 into the worksheets. The images I want to put in are both available at a URL and also embedded in the root of the silverlight application. How can I incorporate these, when I try to set the file path to http://www.xyz.com/abc/abc/image1.png I get a

{System.ArgumentException: URI formats are not supported.
at System.IO.Path.NormalizePath(String path, Boolean fullCheck, Int32 maxPathLength)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
at System.Drawing.Image.FromFile(String fileName)
at Spire.Xls.Core.Spreadsheet.Collections.XlsPicturesCollection.Add(Int32 topRow, Int32 leftColumn, Int32 bottomRow, Int32 rightColumn, String fileName, ImageFormatType imageFormat)
at Spire.Xls.Collections.PicturesCollection.Add(Int32 topRow, Int32 leftColumn, Int32 bottomRow, Int32 rightColumn, String fileName, ImageFormatType imageFormat)
at ChicaneInvoicing.MainPage.saveinvoice_Click(Object sender, RoutedEventArgs e)}

and when i set it to @"..\image1.png" or "image1.png" I get a

{System.Security.SecurityException: File operation not permitted. Access to path 'gtrak.png' is denied.
at System.IO.FileSecurityState.EnsureState()
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
at System.Drawing.Image.FromFile(String fileName)
at Spire.Xls.Core.Spreadsheet.Collections.XlsPicturesCollection.Add(Int32 topRow, Int32 leftColumn, Int32 bottomRow, Int32 rightColumn, String fileName, ImageFormatType imageFormat)
at Spire.Xls.Collections.PicturesCollection.Add(Int32 topRow, Int32 leftColumn, Int32 bottomRow, Int32 rightColumn, String fileName, ImageFormatType imageFormat)
at ChicaneInvoicing.MainPage.saveinvoice_Click(Object sender, RoutedEventArgs e)}

I am wondering if this can be done at all from silverlight, using a stream? saving to isolated storage and re-loading from there? anything. Any help would be appreciated and any code samples would be massively appreciated!
Cheers, Tom

gtrakltd
 
Posts: 2
Joined: Fri Nov 11, 2011 10:01 am

Thu Dec 29, 2011 10:37 pm

As allways Ive asked the question and then figured it out, anyone else who has this issue, i found the following thread

http://stackoverflow.com/questions/5045 ... in-the-xap

and then used the following code

Stream s = Application.GetResourceStream(new Uri("/ChicaneInvoicing;component/GTRAK.png", UriKind.Relative)).Stream;
StreamReader reader = new StreamReader(s);
sheet.Pictures.Add(1, 4, s);

Thanks

Tom

gtrakltd
 
Posts: 2
Joined: Fri Nov 11, 2011 10:01 am

Return to Spire.XLS