//create a new workbook var workbook = new GrapeCity.Documents.Excel.Workbook(); IWorksheet worksheet = workbook.Worksheets[0]; worksheet.Range["A1"].Formula = "='https://developer.mescius.com/document-solutions/dot-net-excel-api/demos/api/sample/[SourceWorkbook.xlsx]Sheet1'!A1"; using (var client = new System.Net.Http.HttpClient()) { foreach (var requestUri in workbook.GetExcelLinkSources()) { var externalWorkbook = new GrapeCity.Documents.Excel.Workbook(); // TODO: Rewrite the following code using async / await (Async / Await in Visual Basic) to // avoid deadlocks in a one-thread-at-a-time context. // This change must be done when the code called on the UI thread or // in an ASP.NET (.NET Framework) context. // You mustn't use ConfigureAwait(false) or its equivalents, and // the current thread must have a synchronization context. // Because an instance of workbook can't be used in different threads. var workbookStream = client.GetStreamAsync(requestUri).GetAwaiter().GetResult(); // The original stream doesn't support seek. Copy it to memory stream. var copied = new MemoryStream(); workbookStream.CopyTo(copied); copied.Position = 0; externalWorkbook.Open(copied); workbook.UpdateExcelLink(requestUri, externalWorkbook); } } var value = worksheet.Range["B1"].Value; // Save to an excel file workbook.Save("ExternalWorkbookLinks.xlsx");
' Create a new Workbook Dim workbook As New Workbook Dim worksheet As IWorksheet = workbook.Worksheets(0) worksheet.Range!A1.Formula = "='https://developer.mescius.com/document-solutions/dot-net-excel-api/demos/api/sample/[SourceWorkbook.xlsx]Sheet1'!A1" Using client As New Net.Http.HttpClient For Each requestUri In workbook.GetExcelLinkSources() Dim externalWorkbook As New Excel.Workbook ' TODO: Rewrite the following code using async / await (Async / Await in Visual Basic) to ' avoid deadlocks in a one-thread-at-a-time context. ' This change must be done when the code called on the UI thread or ' in an ASP.NET (.NET Framework) context. ' You mustn't use ConfigureAwait(False) or its equivalents, and ' the current thread must have a synchronization context. ' Because an instance of workbook can't be used in different threads. Dim workbookStream = client.GetStreamAsync(requestUri).GetAwaiter().GetResult() ' The original stream doesn't support seek. Copy it to memory stream. Dim copied As New MemoryStream workbookStream.CopyTo(copied) copied.Position = 0 externalWorkbook.Open(copied) workbook.UpdateExcelLink(requestUri, externalWorkbook) Next requestUri End Using Dim value = worksheet.Range!B1.Value ' save to an excel file workbook.Save("ExternalWorkbookLinks.xlsx")