0

I am trying to add an image via a URL using IXLWorksheet. However, it says the file is not supported.

My method:

private void createReport(ref IXLWorksheet)
{
    ...
    w.Range($"S{rowCounter}:U{rowCounter}").Merge();
    w.Range($"S{rowCounter}");
    var logo = "https://sm.mashable.com/t/mashable_in/photo/default/nasa-
    galaxy_9pu4.1248.jpg"
    w.AddPicture(logo);
    ...
}

However an exception appears at the w.AddPicture(logo); line saying:

The given path's format is not supported url worksheet

I assume this only works with a direct path in a folder. How can I make it add a picture straight from the URL?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
dros
  • 1,217
  • 2
  • 15
  • 31
  • 1
    .csv files are text files (coma separated values). Excel opens them but they are just text files so you can not add images to them. – Brad Sep 15 '21 at 13:11
  • surely its possible, why is there an AddPicture() method then? – dros Sep 15 '21 at 13:14
  • Where/what app are you opening the .csv file to see AddPicture()? Your code looks like its using sheets (so Excel) but the file your pointing at is .CSV which is NOT Excel file. Its a standard file format that any notepad like app can open. – Brad Sep 15 '21 at 13:19
  • 1
    apologies i have mislabel the question. I am working with an EXCEL not csv – dros Sep 15 '21 at 13:23
  • Re *"The given path's format is not supported url worksheet"*: I don't believe that is the actual error message. It is ***incomprehensible***. Can you [fix it](https://stackoverflow.com/posts/69193827/edit)? Please respond by [editing (changing) your question](https://stackoverflow.com/posts/69193827/edit), not here in comments (***without*** "Edit:", "Update:", or similar - the question should appear as if it was written today). – Peter Mortensen Oct 05 '21 at 11:45

1 Answers1

0

Specific cell:

string picPath = @"C:\Users\Administrator\Desktop\logo.png";

ExcelPicture picture = sheet.Pictures.Add(1, 1, picPath);

Hyperlink:

Excel picture.SetHyperLink("link", true);

sheet.Columns[0].ColumnWidth = chooseWidth;
sheet.Rows[0].RowHeight = chooseHeight;
Dharman
  • 30,962
  • 25
  • 85
  • 135
  • this is adding in the link via a path . I need to add it in via a url – dros Sep 15 '21 at 14:07
  • Try this thread: https://stackoverflow.com/questions/1333772/adding-hyperlinks-in-excel2007-in-c-sharp-within-excel-it-self –  Sep 15 '21 at 14:11
  • You can also see this one here: https://docs.aspose.com/cells/net/load-a-web-image-from-a-url-into-an-excel-worksheet/ –  Sep 15 '21 at 14:15