//create a new workbook var workbook = new GrapeCity.Documents.Excel.Workbook(); // Configure the network request processor, which requires user customization. GrapeCity.Documents.Excel.Workbook.WebRequestHandler = new WebRequestHandler(); IWorksheet worksheet = workbook.Worksheets[0]; // Init data worksheet.Range["A1:D11"].Value = new object[,] { {"SKU", "ITEM", "QTY", "COST" }, { "BO87680", "Boots", 30, 20 }, { "DR676554", "Dress", 10, 50 }, { "GL98767", "Glasses", 40, 15 }, { "HA23423", "Hat", 12, 26 }, { "JA87684", "Jacket", 10, 100 }, { "SH67655", "Shorts", 19, 30 }, { "SLG123", "Slippers", 25, 8 }, { "SU98762", "Suitcase", 7, 50 }, { "SW3456", "Swimsuit", 15, 60 }, { "TS98768", "T-shirt", 20, 14 } }; worksheet.Range["E1"].Value = "IMAGE"; // Setting the image function worksheet.Range["E2"].Formula = "= IMAGE(\"https://cdn-icons-png.flaticon.com/512/1785/1785348.png\")"; worksheet.Range["E3"].Formula = "= IMAGE(\"https://cdn-icons-png.flaticon.com/512/2682/2682178.png\")"; worksheet.Range["E4"].Formula = "= IMAGE(\"https://cdn-icons-png.flaticon.com/512/1971/1971886.png\")"; worksheet.Range["E5"].Formula = "= IMAGE(\"https://cdn-icons-png.flaticon.com/512/1357/1357590.png\")"; worksheet.Range["E6"].Formula = "= IMAGE(\"https://cdn-icons-png.flaticon.com/512/2411/2411728.png\")"; worksheet.Range["E7"].Formula = "= IMAGE(\"https://cdn-icons-png.flaticon.com/512/5029/5029595.png\")"; worksheet.Range["E8"].Formula = "= IMAGE(\"https://cdn-icons-png.flaticon.com/512/15618/15618724.png\")"; worksheet.Range["E9"].Formula = "= IMAGE(\"https://cdn-icons-png.flaticon.com/512/3412/3412695.png\")"; worksheet.Range["E10"].Formula = "= IMAGE(\"https://cdn-icons-png.flaticon.com/512/5398/5398550.png\")"; worksheet.Range["E11"].Formula = "= IMAGE(\"https://cdn-icons-png.flaticon.com/512/1867/1867565.png\")"; // Setting the style worksheet.Range["2:11"].RowHeightInPixel = 75; IRange range = worksheet.Range["A1:E11"]; var table = worksheet.Tables.Add(range, true); table.TableStyle = workbook.TableStyles["TableStyleMedium2"]; range.Borders[BordersIndex.InsideHorizontal].LineStyle = BorderLineStyle.Thin; range.Borders[BordersIndex.InsideVertical].LineStyle = BorderLineStyle.Thin; range.Borders[BordersIndex.EdgeTop].LineStyle = BorderLineStyle.Thin; range.Borders[BordersIndex.EdgeLeft].LineStyle = BorderLineStyle.Thin; range.Borders[BordersIndex.EdgeRight].LineStyle = BorderLineStyle.Thin; range.Borders[BordersIndex.EdgeRight].LineStyle = BorderLineStyle.Thin; // Calculate all formulas so the asynchronous image function will run. workbook.Calculate(); // Block the current thread until all asynchronous functions have finished. // If this method is not called, the exported file may contain #BUSY! error. workbook.WaitForCalculationToFinish();
' Create a new Workbook Dim workbook As New Workbook 'Configure the network request processor, which requires user customization. GrapeCity.Documents.Excel.Workbook.WebRequestHandler = New WebRequestHandler() 'Init data Dim worksheet As IWorksheet = workbook.Worksheets(0) worksheet.Range("A1:D11").Value = New Object(,) { {"SKU", "ITEM", "QTY", "COST"}, {"BO87680", "Boots", 30, 20}, {"DR676554", "Dress", 10, 50}, {"GL98767", "Glasses", 40, 15}, {"HA23423", "Hat", 12, 26}, {"JA87684", "Jacket", 10, 100}, {"SH67655", "Shorts", 19, 30}, {"SLG123", "Slippers", 25, 8}, {"SU98762", "Suitcase", 7, 50}, {"SW3456", "Swimsuit", 15, 60}, {"TS98768", "T-shirt", 20, 14} } worksheet.Range("E1").Value = "IMAGE" 'Setting the image function worksheet.Range("E2").Formula = "= IMAGE(""https://cdn-icons-png.flaticon.com/512/1785/1785348.png"")" worksheet.Range("E3").Formula = "= IMAGE(""https://cdn-icons-png.flaticon.com/512/2682/2682178.png"")" worksheet.Range("E4").Formula = "= IMAGE(""https://cdn-icons-png.flaticon.com/512/1971/1971886.png"")" worksheet.Range("E5").Formula = "= IMAGE(""https://cdn-icons-png.flaticon.com/512/1357/1357590.png"")" worksheet.Range("E6").Formula = "= IMAGE(""https://cdn-icons-png.flaticon.com/512/2411/2411728.png"")" worksheet.Range("E7").Formula = "= IMAGE(""https://cdn-icons-png.flaticon.com/512/5029/5029595.png"")" worksheet.Range("E8").Formula = "= IMAGE(""https://cdn-icons-png.flaticon.com/512/15618/15618724.png"")" worksheet.Range("E9").Formula = "= IMAGE(""https://cdn-icons-png.flaticon.com/512/3412/3412695.png"")" worksheet.Range("E10").Formula = "= IMAGE(""https://cdn-icons-png.flaticon.com/512/5398/5398550.png"")" worksheet.Range("E11").Formula = "= IMAGE(""https://cdn-icons-png.flaticon.com/512/1867/1867565.png"")" ' Setting the style worksheet.Range("2:11").RowHeightInPixel = 75 Dim range As IRange = worksheet.Range("A1:E11") Dim table As ITable = worksheet.Tables.Add(range, True) table.TableStyle = workbook.TableStyles("TableStyleMedium2") range.Borders(BordersIndex.InsideHorizontal).LineStyle = BorderLineStyle.Thin range.Borders(BordersIndex.InsideVertical).LineStyle = BorderLineStyle.Thin range.Borders(BordersIndex.EdgeTop).LineStyle = BorderLineStyle.Thin range.Borders(BordersIndex.EdgeLeft).LineStyle = BorderLineStyle.Thin range.Borders(BordersIndex.EdgeRight).LineStyle = BorderLineStyle.Thin range.Borders(BordersIndex.EdgeRight).LineStyle = BorderLineStyle.Thin 'Calculate all formulas so the asynchronous image function will run. workbook.Calculate() 'Block the current thread until all asynchronous functions have finished. 'If this method is not called, the exported file may contain #BUSY! error. workbook.WaitForCalculationToFinish() ' save to an excel file workbook.Save("ImageFunction.xlsx")