[英]Gembox removes precision when saving as CSV
我正在使用Gembox電子表格將一些數據導出到.CSV,但是在輸出文件中沒有任何小數。
當導出為XLSX時,一切看起來都與預期的一樣。
我已經嘗試了Gembox 3.7和3.9,但結果是相同的。
使用下面的代碼來重現該問題。
SpreadsheetInfo.SetLicense("FREE-LIMITED-KEY");
var ef = new ExcelFile();
var ws = ef.Worksheets.Add("NumberFormatTest");
ws.Cells[0, 0].Value = "Expected";
ws.Cells[1, 0].Value = "0";
ws.Cells[2, 0].Value = "0.0";
ws.Cells[3, 0].Value = "0.00";
ws.Cells[0, 1].Value = "Actual";
ws.Cells[1, 1].Value = 0m;
ws.Cells[1, 1].Style.NumberFormat = "0";
ws.Cells[2, 1].Value = 0m;
ws.Cells[2, 1].Style.NumberFormat = "0.0";
ws.Cells[3, 1].Value = 0m;
ws.Cells[3, 1].Style.NumberFormat = "0.00";
ef.Save("Numberformat test.csv");
ef.Save("Numberformat test.xlsx");
如何不使用.ToString("0.00")
獲得正確的結果?
如果對別人有趣。 我與他們的支持部門聯系,他們告訴我該數字格式當前未導出為CSV文件格式,因此應使用以下解決方法。
foreach (var row in ws.Rows)
foreach (var cell in row.AllocatedCells)
if (cell.Value != null)
cell.Value = cell.GetFormattedValue();
ef.Save("Numberformat test.csv");
對於澳大利亞VB用戶
Dim enAU As CultureInfo = CultureInfo.CreateSpecificCulture("en-AU")
Dim SaveOptions As New CsvSaveOptions(CsvType.CommaDelimited)
With SaveOptions
.FormatProvider = enAU
End With
For Each row In ws.Rows
For Each cell In row.AllocatedCells
If Not (String.IsNullOrEmpty(cell.Value)) Then
cell.Value = cell.GetFormattedValue()
End If
Next
Next
ws.Save(sSaveAsFullFilename, New CsvSaveOptions(CsvType.CommaDelimited) With {.FormatProvider = enAU})
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.