Commit e2144134 by jianshuqin

优化:组件功能

parent b8a6fba3
......@@ -44,5 +44,15 @@
/// 宽度
/// </summary>
public dynamic Width { get; set; }
/// <summary>
/// 精度
/// </summary>
public int? Precision { get; set; }
/// <summary>
/// 样式
/// </summary>
public dynamic Style { get; set; }
}
}
\ No newline at end of file
......@@ -274,6 +274,8 @@ namespace Bailun.DC.Services.Component
IRow headerRow = sheet.CreateRow(0);
//新建一个字体样式对象
IFont fontTitle = workbook.CreateFont();
//创建CellStyle与DataFormat并加载格式样式
IDataFormat dataformat = workbook.CreateDataFormat();
//设置字体加粗样式
fontTitle.IsBold = true;
//设置字体大小
......@@ -290,7 +292,7 @@ namespace Bailun.DC.Services.Component
alignmentstyle.Alignment = HorizontalAlignment.Center;
//合并行属性值
IDictionary<string, (int, string)> rowSpanProp = new Dictionary<string, (int, string)>();
//组
//组标题
bool hasGroup = false;
if (listColumn.Any(l => !string.IsNullOrWhiteSpace(l.GroupName)))
{
......@@ -323,12 +325,30 @@ namespace Bailun.DC.Services.Component
});
headerRow = sheet.CreateRow(1);
}
//列
//列标题
listColumn.ForEach((l, col) =>
{
var cell = headerRow.CreateCell(col);
//设置列格式化
if ((new string[] { "money", "number" }).Contains(l.Format as string))
{
if (l.Precision > 0)
{
//单元格样式
ICellStyle dataFormatStyle = workbook.CreateCellStyle();
dataFormatStyle.CloneStyleFrom(verticAlalignmentstyle);
dataFormatStyle.DataFormat = dataformat.GetFormat($"{(l.Format == "money" ? "#,##" : string.Empty)}0.{"0".PadLeft(l.Precision.Value, '0')}");
l.Style = dataFormatStyle;
}
else
{
l.Style = verticAlalignmentstyle;
}
}
cell.CellStyle = verticAlalignmentstyle;
//设置列标题
cell.SetCellValue(l.Name);
//设置列宽
if (l.Width != null)
{
if (l.Width.ToString().ToLower() == "auto")
......@@ -348,7 +368,7 @@ namespace Bailun.DC.Services.Component
{
string value = reader[header.Prop]?.ToString();
ICell cell = dataRow.CreateCell(col);
cell.CellStyle = verticAlalignmentstyle;
cell.CellStyle = header.Style as ICellStyle ?? verticAlalignmentstyle;
if (!string.IsNullOrWhiteSpace(value))
{
if (header.Format is bool && header.Format == true)
......
......@@ -194,10 +194,10 @@
</template>
<template v-else-if="item.format.constructor === String">
<template v-if="item.format == 'money'">
{{ item_value.toLocaleString() }}
{{ (item.precision && item.precision > 0 ? parseFloat(Math.round(item_value*Math.pow(10, item.precision))/Math.pow(10, 2).toFixed(item.precision)) : item_value).toLocaleString('zh',{minimumFractionDigits: item.precision}) }}
</template>
<template v-else-if="item.format == 'number'">
{{ item_value }}
{{ item.precision && item.precision > 0 ? Math.round(item_value*Math.pow(10, item.precision))/Math.pow(10, 2).toFixed(item.precision) : item_value }}
</template>
<template v-else-if="/[y|Y|m|M|d|h|H|s|S]+/.test(item.format)">
{{ new Date(item_value).format(item.format) }}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment