Skip to content

Commit 0688fda

Browse files
izanhzhshps951023
andauthored
feat(ExcelNumberFormat): extend the SectionType (#716)
* feat(ExcelNumberFormat): extend the SectionType * cancel the missubmit code * Update SheetStyleBuildContext.cs Signed-off-by: Wei Lin <[email protected]> --------- Signed-off-by: Wei Lin <[email protected]> Co-authored-by: Wei Lin <[email protected]>
1 parent 2e7219c commit 0688fda

File tree

3 files changed

+397
-7
lines changed

3 files changed

+397
-7
lines changed

src/MiniExcel/OpenXml/ExcelOpenXmlSheetWriter.DefaultOpenXml.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -217,12 +217,17 @@ private Tuple<string, string, string> GetCellValue(int rowIndex, int cellIndex,
217217

218218
if (TypeHelper.IsNumericType(type))
219219
{
220-
var dataType = _configuration.Culture == CultureInfo.InvariantCulture ? "n" : "str";
221-
string cellValue;
220+
var cellValue = GetNumericValue(value, type);
222221

223-
cellValue = GetNumericValue(value, type);
224-
225-
return Tuple.Create("2", dataType, cellValue);
222+
if (columnInfo == null || columnInfo.ExcelFormat == null)
223+
{
224+
var dataType = _configuration.Culture == CultureInfo.InvariantCulture ? "n" : "str";
225+
return Tuple.Create("2", dataType, cellValue);
226+
}
227+
else
228+
{
229+
return Tuple.Create(columnInfo.ExcelFormatId.ToString(), (string)null, cellValue);
230+
}
226231
}
227232

228233
if (type == typeof(bool))

src/MiniExcel/OpenXml/Styles/SheetStyleBuildContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public async Task InitializeAsync(SheetStyleElementInfos generateElementInfos)
127127
NewXmlWriter = XmlWriter.Create(newXmlWriterStream, new XmlWriterSettings() { Indent = true, Encoding = _encoding, Async = true });
128128

129129
GenerateElementInfos = generateElementInfos;
130-
ColumnsToApply = SheetStyleBuilderHelper.GenerateStyleIds(OldElementInfos.CellXfCount + generateElementInfos.CellXfCount, _columns);
130+
ColumnsToApply = SheetStyleBuilderHelper.GenerateStyleIds(OldElementInfos.CellXfCount + generateElementInfos.CellXfCount, _columns).ToArray();//ToArray to avoid multiple calculations, if there is a performance problem then consider optimizing the
131131
CustomFormatCount = ColumnsToApply.Count();
132132

133133
initialized = true;

0 commit comments

Comments
 (0)