blob: 9394a81c1c3ad503e45aab15d5f02a24b3d09bdc (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
using ExcelAddIn.Services;
using Microsoft.Extensions.DependencyInjection;
namespace ExcelAddIn;
public static class ExcelFunctions
{
[ExcelFunction]
public static object ExchangeRate(double dateField)
{
ICurrencyClient currencyClient = MyAddIn.ServiceProvider.GetService<ICurrencyClient>();
DateTime date = dateField == 0 ? DateTime.Today : DateTime.FromOADate(dateField);
if (ExcelAsyncUtil.Run(nameof(ExchangeRate), dateField, delegate
{
return currencyClient.GetExchangeRate(date)
.GetAwaiter()
.GetResult() ?? -1m;
}) is not decimal requestResult)
{
return "Загрузка...";
}
else if (requestResult < 0)
{
return ExcelError.ExcelErrorNA;
}
else
{
return Math.Round(requestResult, 2);
}
}
}
|