Fix extentions

This commit is contained in:
ngfrolov 2022-06-23 18:10:33 +05:00
parent fce7482d1b
commit 2712eb43ef

View File

@ -5,36 +5,29 @@ namespace AsbCloudInfrastructure.Services.DailyReport
{ {
internal static class XLExtentions internal static class XLExtentions
{ {
public static IXLRange SetValue(this IXLRange range, object value, int maxCharsToWrap = 88) public static IXLRange SetValue(this IXLRange range, object value)
{ {
range.Merge(); range.Merge();
range.FirstCell().SetValue(value, maxCharsToWrap); range.FirstCell().SetValue(value);
return range; return range;
} }
public static IXLCell SetValue(this IXLCell cell, object value) public static IXLCell SetValue(this IXLCell cell, object value)
{ {
switch (value)
{
case DateTime dateTime:
cell.SetValue(dateTime);
break;
case IFormattable formattable:
cell.SetValue(formattable);
break;
case string valueString:
cell.SetValue(valueString);
break;
default:
cell.Value = value; cell.Value = value;
cell.Style break;
.SetAllBorders()
.Alignment.WrapText = true;
if (value is string valueString && valueString.Length > maxChartsToWrap)
{
var row = cell.WorksheetRow();
var baseHeight = row.Height;
row.Height = 0.82d * baseHeight * Math.Ceiling(1d + valueString.Length / maxChartsToWrap);
}
if (value is DateTime)
{
cell.DataType = XLDataType.DateTime;
cell.Style.DateFormat.Format = "DD.MM.YYYY HH:MM:SS";
}
else if (value is IFormattable)
{
cell.DataType = XLDataType.Number;
cell.Style.NumberFormat.Format = "0.00";
} }
return cell; return cell;
@ -64,6 +57,36 @@ namespace AsbCloudInfrastructure.Services.DailyReport
return cell; return cell;
} }
public static IXLCell SetValue(this IXLCell cell, DateTime value, string dateFormat = "DD.MM.YYYY HH:MM:SS")
{
cell.Value = value;
cell.Style
.SetAllBorders()
.Alignment.WrapText = true;
cell.Value = value;
cell.DataType = XLDataType.DateTime;
cell.Style.DateFormat.Format = "DD.MM.YYYY HH:MM:SS";
return cell;
}
public static IXLCell SetValue(this IXLCell cell, IFormattable value, string format = "0.00")
{
cell.Value = value;
cell.Style
.SetAllBorders()
.Alignment.WrapText = true;
cell.Value = value;
cell.DataType = XLDataType.Number;
cell.Style.NumberFormat.Format = "0.00";
return cell;
}
public static IXLStyle SetAllBorders(this IXLStyle style, XLBorderStyleValues borderStyle = XLBorderStyleValues.Thin) public static IXLStyle SetAllBorders(this IXLStyle style, XLBorderStyleValues borderStyle = XLBorderStyleValues.Thin)
{ {
style.Border.RightBorder = borderStyle; style.Border.RightBorder = borderStyle;