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
C# 如何使用interop.excel将长数字写入文本_C#_Excel - Fatal编程技术网

C# 如何使用interop.excel将长数字写入文本

C# 如何使用interop.excel将长数字写入文本,c#,excel,C#,Excel,我正在使用interop.excel dll并创建一个excel文件。我在将长数字作为文本写入时遇到问题 下面是我正在使用的代码。我可以使用撇号,但如果您查看公式栏,您可以看到单元格已格式化 有没有其他方法可以将长数字写入Excel电子表格,而不使用numberformat查看公式栏中的格式化值 如果你想在一行中完成,你可以使用 例如: worksheets.Cells[i, j] = "=Text(" + dr[p] + ", \"#\""; Range r= worksheet.Cells

我正在使用interop.excel dll并创建一个excel文件。我在将长数字作为文本写入时遇到问题

下面是我正在使用的代码。我可以使用撇号,但如果您查看公式栏,您可以看到单元格已格式化

有没有其他方法可以将长数字写入Excel电子表格,而不使用numberformat查看公式栏中的格式化值


如果你想在一行中完成,你可以使用

例如:

worksheets.Cells[i, j] = "=Text(" + dr[p] + ", \"#\"";
Range r= worksheet.Cells;
r.NumberFormat = "@";
但这可能不是您想要的,因为这会将数字存储为文本,并在公式栏中显示公式。在这种情况下,就像user194076建议的那样,您可以使用.NumberFormat=@;
或.NumberFormat=;如果您不希望它以科学记数法显示。

您可以将NumberFormat与'@'或 例如:

Range r= worksheet.Cells;
r.NumberFormat = "@";

你试过使用cell.NumberFormat=@吗?谢谢,成功了。我没有使用正确语法的numberformat