Add =КУРСЕВРО() function

This commit is contained in:
Sergey Chebotar 2023-05-17 08:11:24 +03:00
parent 9f0ef90005
commit c5895f78c2

View File

@ -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);
}
}
}
} }