使用C#以编程方式将Excel单元格从科学数值格式转换为文本格式 [英] Formating programmatically Excel cells from Scientific numeric to Text with C#
问题描述
使用Microsoft.Office.Interop.Excel参考将数据从sqlServer数据库提取到Excel工作表后,我遇到了问题.数字数据以科学的数字格式显示,而不是以文本格式显示.我试图以这种方式格式化单元格,但仍然无法正常工作:
Microsoft.Office.Interop.Excel.Range cell= (Range) worksheet.Cells[rowNum, fieldNum];
cell.NumberFormat="@";
我什至尝试在输入Excel文件中设置单元格格式;我实际上将其用作该程序的模板;为数字或文本,但无助地无法正常工作.
I'm facing a problem after extracting data from my sqlServer dataBase to my Excel worksheet using Microsoft.Office.Interop.Excel reference. Numeric data are displayed in a scientific numeric format, instead of being displayed in a text format. I tried to format my cell this way, but still doesn't work :
Microsoft.Office.Interop.Excel.Range cell= (Range) worksheet.Cells[rowNum, fieldNum];
cell.NumberFormat="@";
I tried even to set my cells format in my Input Excel file; which i'm actually using as a template for this program; as Number or Text but helplessly it's not working.
我该如何解决此问题?
推荐答案
尝试使用EntireColumn
try by using EntireColumn
cell.EntireColumn.NumberFormat = "@";
这篇关于使用C#以编程方式将Excel单元格从科学数值格式转换为文本格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!