从SQL中导出资料汇成Excel表格,原1.0、2.0……都自动变成了1、2……,请问怎麼在程式中设定才可以在Excel中显示1.0、2.0……
我用的C#写的程式,将资料从SQL中导出成Excel表格,怎样在程式中设置导出的表格格式?
追答NumberFormat的设置好好看一下,应该有小数点位置的设置。
追问NumberFormatInfo nfi = new CultureInfo("en-US", false).NumberFormat;
nfi.NumberDecimalDigits = 1;
select filw_version.tostring('N',nfi) as 文件版本 from tb_file;
程式不成正确执行,请问我该怎样设置才能使导出的资料保留一位小数
看看下面的例子做一下:
using System;
using System.Globalization;
class NumberFormatInfoSample {
public static void Main() {
// Gets a NumberFormatInfo associated with the en-US culture.
NumberFormatInfo nfi = new CultureInfo( "en-US", false ).NumberFormat;
// Displays a negative value with the default number of decimal digits (2).
Int64 myInt = -1234;
Console.WriteLine( myInt.ToString( "N", nfi ) );
// Displays the same value with four decimal digits.
nfi.NumberDecimalDigits = 4;
Console.WriteLine( myInt.ToString( "N", nfi ) );
}
}
/*
This code produces the following output.
-1,234.00
-1,234.0000
*/
我明天试试
追答自己修改单元格即可,你懂得的
本回答被提问者和网友采纳这是导出后的设置啦,我想要的是导出后就保留一位小数
这是导出后的设置啦,我想要的是导出后就保留一位小数