Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,10 @@ private Tuple<string, string, string> GetCellValue(int rowIndex, int cellIndex,
return Tuple.Create(RegularCellStyleIndex, StringDataType, string.Empty);

if (value is string str)
return Tuple.Create(RegularCellStyleIndex, StringDataType, ExcelOpenXmlUtils.EncodeXML(str));
{
var styleIndex = columnInfo?.ExcelFormatId is { } fmt and not -1 ? fmt.ToString() : RegularCellStyleIndex;
return Tuple.Create(styleIndex, StringDataType, ExcelOpenXmlUtils.EncodeXML(str));
}

var type = GetValueType(value, columnInfo);

Expand Down
23 changes: 23 additions & 0 deletions tests/MiniExcelTests/MiniExcelIssueAsyncTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@

private class Issue243Dto
{
public string Name { get; set; }

Check warning on line 227 in tests/MiniExcelTests/MiniExcelIssueAsyncTests.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

Non-nullable property 'Name' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
public int Age { get; set; }
public DateTime InDate { get; set; }
}
Expand Down Expand Up @@ -358,11 +358,11 @@
var sheets = new DataSet();

var users = JsonConvert.DeserializeObject<DataTable>(JsonConvert.SerializeObject(new[] { new { Name = "Jack", Age = 25 }, new { Name = "Mike", Age = 44 } }));
users.TableName = "users";

Check warning on line 361 in tests/MiniExcelTests/MiniExcelIssueAsyncTests.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

Dereference of a possibly null reference.
sheets.Tables.Add(users);

var department = JsonConvert.DeserializeObject<DataTable>(JsonConvert.SerializeObject(new[] { new { ID = "01", Name = "HR" }, new { ID = "02", Name = "IT" } }));
department.TableName = "department";

Check warning on line 365 in tests/MiniExcelTests/MiniExcelIssueAsyncTests.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

Dereference of a possibly null reference.
sheets.Tables.Add(department);

var rowsWritten = await MiniExcel.SaveAsAsync(path, sheets);
Expand Down Expand Up @@ -1888,4 +1888,27 @@
Assert.All(rows, x => Assert.Single(x));
Assert.Equal("Name", rows[0].A);
}

[Fact]
public async Task TestIssue627()
{
var data = new[] { new { LongNumber = "1550432695793487872" } };

var config = new OpenXmlConfiguration
{
DynamicColumns = [
new DynamicExcelColumn("LongNumber") { Format = "@" }
]
};

await using var ms = new MemoryStream();
await ms.SaveAsAsync(data, configuration: config);
ms.Seek(0, SeekOrigin.Begin);

using var package = new ExcelPackage(ms);
var cell = package.Workbook.Worksheets[0].Cells["A2"];

Assert.Equal("1550432695793487872", cell.GetValue<string>());
Assert.Equal("@", cell.Style.Numberformat.Format);
}
}
Loading