Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/305.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# NPOI方法GetFormat(“GetFormat”)正在显示“GetFormat”;日期“;而不是",;“文本”;_C#_Excel_Npoi_Text Formatting_Cell Formatting - Fatal编程技术网

C# NPOI方法GetFormat(“GetFormat”)正在显示“GetFormat”;日期“;而不是",;“文本”;

C# NPOI方法GetFormat(“GetFormat”)正在显示“GetFormat”;日期“;而不是",;“文本”;,c#,excel,npoi,text-formatting,cell-formatting,C#,Excel,Npoi,Text Formatting,Cell Formatting,我在stackoverflow上找到了将Excel文件的一列设置为文本的解决方案 DataFormat currDataFormat = this.Workbook.CreateDataFormat(); CellStyle textStyle = this.Workbook.CreateCellStyle(); textStyle.DataFormat = currDataFormat.GetFormat("@"); sheet.SetDefaultColumnStyle(0, textSty

我在stackoverflow上找到了将Excel文件的一列设置为文本的解决方案

DataFormat currDataFormat = this.Workbook.CreateDataFormat();
CellStyle textStyle = this.Workbook.CreateCellStyle();
textStyle.DataFormat = currDataFormat.GetFormat("@");
sheet.SetDefaultColumnStyle(0, textStyle);
我也尝试了同样的方法,在导出excel文件时,它显示了同一列的“日期”格式。这对我不起作用。我想要一列作为“文本”格式


提前谢谢。

问题似乎重复。请看答案。实际的代码修复应该是

textStyle.DataFormat = currDataFormat.GetFormat("text");