Excel将我的数字转换为浮点数
我有一些ASP.NET代码可以将datagrid中的数据导出到Excel中,但我注意到它在导出时会弄乱特定字段 例如,在datagrid中的一列中,我的值大约为8923401000725515875,但在导出时,它会将其转换为89234+19Excel将我的数字转换为浮点数,excel,datagrid,formatting,floating-point,export,Excel,Datagrid,Formatting,Floating Point,Export,我有一些ASP.NET代码可以将datagrid中的数据导出到Excel中,但我注意到它在导出时会弄乱特定字段 例如,在datagrid中的一列中,我的值大约为8923401000725515875,但在导出时,它会将其转换为89234+19 是否有任何Excel格式可以恢复我的原始编号?谢谢。Excel并没有把这个领域搞得一团糟。有两件事正在发生: Excel以科学记数法格式化大量数字。因此,“8923401000725515875”变为“8.9234E+19”或“8.9234 x 10^19
是否有任何Excel格式可以恢复我的原始编号?谢谢。Excel并没有把这个领域搞得一团糟。有两件事正在发生:
using System;
using SpreadsheetGear;
namespace Program
{
class Program
{
static void Main(string[] args)
{
// Create a new workbook and get a reference to A1.
IWorkbook workbook = Factory.GetWorkbook();
IWorksheet worksheet = workbook.Worksheets[0];
IRange a1 = worksheet.Cells["A1"];
// Format A1 as Text using the "@" format so that the text
// will not be converted to a number, and put the text in A1.
a1.NumberFormat = "@";
a1.Value = "89234010000725515875";
// Show that the formatted value is
Console.WriteLine("FormattedValue={0}, Raw Value={1}", a1.Text, a1.Value);
// Save the workbook.
workbook.SaveAs(@"c:\tmp\Text.xls", FileFormat.Excel8);
workbook.SaveAs(@"c:\tmp\Text.xlsx", FileFormat.OpenXMLWorkbook);
}
}
}
您可以在字段中添加空格,然后将其导出到Excel时,将其视为字符串:
lblTest.Text = DTInfo.Rows(0).Item("Test") & " "
祝你好运