mirror of
https://gitee.com/dotnetchina/MiniExcel.git
synced 2024-11-29 18:38:08 +08:00
Formula attribute added to support in rows with dto or dynamic attrib… (#679)
* Formula attribute added to support in rows with dto or dynamic attributes * Change Formula attribute to ColumnType (Value, Formula) --------- Co-authored-by: Eulises Vargas <eulises.vargas@iconstruye.onmicrosoft.com>
This commit is contained in:
parent
436aaa80c9
commit
f0fe803d6a
@ -21,6 +21,8 @@ namespace MiniExcelLibs.Attributes
|
||||
|
||||
public bool Ignore { get; set; }
|
||||
|
||||
public ColumnType Type { get; set; } = ColumnType.Value;
|
||||
|
||||
public int Index
|
||||
{
|
||||
get => _index;
|
||||
@ -50,6 +52,7 @@ namespace MiniExcelLibs.Attributes
|
||||
}
|
||||
}
|
||||
|
||||
public enum ColumnType { Value, Formula }
|
||||
|
||||
public class DynamicExcelColumn : ExcelColumnAttribute
|
||||
{
|
||||
|
@ -1,4 +1,5 @@
|
||||
using System.Globalization;
|
||||
using MiniExcelLibs.Attributes;
|
||||
|
||||
namespace MiniExcelLibs.OpenXml.Constants
|
||||
{
|
||||
@ -52,14 +53,13 @@ namespace MiniExcelLibs.OpenXml.Constants
|
||||
internal static string EmptyCell(string cellReference, string styleIndex)
|
||||
=> $"<x:c r=\"{cellReference}\" s=\"{styleIndex}\"></x:c>";
|
||||
//t check avoid format error ![image](https://user-images.githubusercontent.com/12729184/118770190-9eee3480-b8b3-11eb-9f5a-87a439f5e320.png)
|
||||
internal static string Cell(string cellReference, string cellType, string styleIndex, string cellValue, bool preserveSpace = false)
|
||||
=> $"<x:c r=\"{cellReference}\"{(cellType == null ? string.Empty : $" t=\"{cellType}\"")} s=\"{styleIndex}\"{(preserveSpace ? " xml:space=\"preserve\"" : string.Empty)}><x:v>{cellValue}</x:v></x:c>";
|
||||
internal static string Cell(string cellReference, string cellType, string styleIndex, string cellValue, bool preserveSpace = false, ColumnType columnType = ColumnType.Value)
|
||||
=> $"<x:c r=\"{cellReference}\"{(cellType == null ? string.Empty : $" t=\"{cellType}\"")} s=\"{styleIndex}\"{(preserveSpace ? " xml:space=\"preserve\"" : string.Empty)}><x:{(columnType == ColumnType.Formula ? "f" : "v")}>{cellValue}</x:{(columnType == ColumnType.Formula ? "f" : "v")}></x:c>";
|
||||
|
||||
internal static string Autofilter(string dimensionRef)
|
||||
=> $"<x:autoFilter ref=\"{dimensionRef}\" />";
|
||||
|
||||
internal static string Drawing(int sheetIndex)
|
||||
=> $"<x:drawing r:id=\"drawing{sheetIndex}\" />";
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
using MiniExcelLibs.OpenXml.Constants;
|
||||
using MiniExcelLibs.Attributes;
|
||||
using MiniExcelLibs.OpenXml.Constants;
|
||||
using MiniExcelLibs.Utils;
|
||||
using MiniExcelLibs.Zip;
|
||||
using System;
|
||||
@ -459,10 +460,11 @@ namespace MiniExcelLibs.OpenXml
|
||||
var styleIndex = tuple.Item1;
|
||||
var dataType = tuple.Item2;
|
||||
var cellValue = tuple.Item3;
|
||||
var columnType = p.ExcelColumnType;
|
||||
|
||||
/*Prefix and suffix blank space will lost after SaveAs #294*/
|
||||
var preserveSpace = cellValue != null && (cellValue.StartsWith(" ", StringComparison.Ordinal) || cellValue.EndsWith(" ", StringComparison.Ordinal));
|
||||
await writer.WriteAsync(WorksheetXml.Cell(columnReference, dataType, styleIndex, cellValue, preserveSpace: preserveSpace));
|
||||
await writer.WriteAsync(WorksheetXml.Cell(columnReference, dataType, styleIndex, cellValue, preserveSpace: preserveSpace, columnType: columnType));
|
||||
}
|
||||
|
||||
private async Task GenerateEndXmlAsync(CancellationToken cancellationToken)
|
||||
|
@ -103,6 +103,7 @@ namespace MiniExcelLibs.OpenXml
|
||||
|
||||
prop.Nullable = true;
|
||||
prop.ExcelIgnore = dynamicColumn.Ignore;
|
||||
prop.ExcelColumnType = dynamicColumn.Type;
|
||||
prop.ExcelColumnIndex = dynamicColumn.Index;
|
||||
prop.ExcelColumnWidth = dynamicColumn.Width;
|
||||
//prop.ExcludeNullableType = item2[key]?.GetType();
|
||||
|
@ -1,4 +1,5 @@
|
||||
using MiniExcelLibs.OpenXml.Constants;
|
||||
using MiniExcelLibs.Attributes;
|
||||
using MiniExcelLibs.OpenXml.Constants;
|
||||
using MiniExcelLibs.OpenXml.Models;
|
||||
using MiniExcelLibs.Utils;
|
||||
using MiniExcelLibs.Zip;
|
||||
@ -579,10 +580,11 @@ namespace MiniExcelLibs.OpenXml
|
||||
var styleIndex = tuple.Item1; // https://learn.microsoft.com/en-us/dotnet/api/documentformat.openxml.spreadsheet.cell?view=openxml-3.0.1
|
||||
var dataType = tuple.Item2; // https://learn.microsoft.com/en-us/dotnet/api/documentformat.openxml.spreadsheet.cellvalues?view=openxml-3.0.1
|
||||
var cellValue = tuple.Item3;
|
||||
var columnType = columnInfo?.ExcelColumnType ?? ColumnType.Value;
|
||||
|
||||
/*Prefix and suffix blank space will lost after SaveAs #294*/
|
||||
var preserveSpace = cellValue != null && (cellValue.StartsWith(" ", StringComparison.Ordinal) || cellValue.EndsWith(" ", StringComparison.Ordinal));
|
||||
writer.Write(WorksheetXml.Cell(columnReference, dataType, styleIndex, cellValue, preserveSpace: preserveSpace));
|
||||
writer.Write(WorksheetXml.Cell(columnReference, dataType, styleIndex, cellValue, preserveSpace: preserveSpace, columnType: columnType));
|
||||
}
|
||||
|
||||
private static void WriteCell(MiniExcelStreamWriter writer, string cellReference, string columnName)
|
||||
|
@ -24,6 +24,7 @@
|
||||
public string ExcelIndexName { get; internal set; }
|
||||
public bool ExcelIgnore { get; internal set; }
|
||||
public int ExcelFormatId { get; internal set; }
|
||||
public ColumnType ExcelColumnType { get; internal set; }
|
||||
}
|
||||
|
||||
internal class ExcellSheetInfo
|
||||
@ -206,7 +207,8 @@
|
||||
ExcelIndexName = p.GetAttribute<ExcelColumnIndexAttribute>()?.ExcelXName ?? excelColumn?.IndexName,
|
||||
ExcelColumnWidth = p.GetAttribute<ExcelColumnWidthAttribute>()?.ExcelColumnWidth ?? excelColumn?.Width,
|
||||
ExcelFormat = excelFormat ?? excelColumn?.Format,
|
||||
ExcelFormatId = excelColumn?.FormatId ?? -1
|
||||
ExcelFormatId = excelColumn?.FormatId ?? -1,
|
||||
ExcelColumnType = excelColumn?.Type ?? ColumnType.Value
|
||||
};
|
||||
}).Where(_ => _ != null);
|
||||
}
|
||||
@ -307,6 +309,7 @@
|
||||
p.ExcelColumnName = dynamicColumn.Name;
|
||||
isIgnore = dynamicColumn.Ignore;
|
||||
p.ExcelColumnWidth = dynamicColumn.Width;
|
||||
p.ExcelColumnType = dynamicColumn.Type;
|
||||
}
|
||||
}
|
||||
if (!isIgnore)
|
||||
|
Loading…
Reference in New Issue
Block a user