Add =КУРСЕВРО() function
This commit is contained in:
parent
9f0ef90005
commit
c5895f78c2
@ -185,4 +185,34 @@ public class RhSolutionsFunction
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[ExcelFunction(Description = "Получить курс евро по ЦБ")]
|
||||
public static object КУРСЕВРО([ExcelArgument(Name = "ДАТА", Description = "Дата в формате Excel (необязательно)")] double dateField)
|
||||
{
|
||||
ICurrencyClient currencyClient = RhSolutionsAddIn.ServiceProvider.GetRequiredService<ICurrencyClient>();
|
||||
|
||||
if (ExcelAsyncUtil.Run("Database request", dateField, delegate
|
||||
{
|
||||
DateTime date = dateField == 0 ? DateTime.Now : DateTime.FromOADate(dateField);
|
||||
var exchangeRate = currencyClient.GetCurrencyCourse(date)
|
||||
.GetAwaiter()
|
||||
.GetResult();
|
||||
|
||||
return exchangeRate ?? -1m;
|
||||
}) is not decimal requestResult)
|
||||
{
|
||||
return "Загрузка...";
|
||||
}
|
||||
else
|
||||
{
|
||||
if (requestResult < 0)
|
||||
{
|
||||
return ExcelError.ExcelErrorNA;
|
||||
}
|
||||
else
|
||||
{
|
||||
return Math.Round(requestResult, 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user