简体   繁体   中英

How can I insert a picture into an Excel spreadsheet with Spreadsheet Light from a link rather than an image file?

It's easy to add a picture to a sheet with Spreadsheet Light like this:

SLPicture logoPic = new SLPicture(@"C:\Platypus\DuckbillsUnlimited.png");
logoPic.SetPosition(0, 13);
sl.InsertPicture(logoPic);

...but I want to use an image at an URL, not from a file. How is this accomplished?

I tried using the image URL directly in the constructor of SLPicture, however that is not supported. You can use a workaround as follows:

  1. Download the image file to a temporary location.
  2. Use the downloaded file from the temporary location.

Modification to your sample code can be shown as follows:

WebClient client = new WebClient();
client.DownloadFile(new Uri(url), @"C:\Platypus\DuckbillsUnlimited.png");

SLPicture pic = new SLPicture(@"C:\Platypus\DuckbillsUnlimited.png");
logoPic.SetPosition(0, 13);
sl.InsertPicture(logoPic);

Not sure if there are other approaches but this definitely works!! Open for other suggestions!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM