Dan*_*den 5 c# excel com-interop
我想知道是否有人遇到以下问题,并对如何解决它有任何想法:我通过Interop将数据从C#应用程序(.NET 3.5)导出到Excel(2003).其中一列存储了一个看似数字的字符串值.也就是说它是一个以0开头的数字,例如000123
我需要存储完整的号码,因为它可能是序列号或类似的东西.Excel并不热衷于此,所以我认为我可以通过将目标单元格设置为常规来绕过它.当我导出到Excel时,我发现123存储而不是000123.
我已经在调试中运行了应用程序,并从我发现的监视列表(对于"范围范围":
range.NumberFormat = "General"`
this.Rows[iGridRow].Cells[iGridCol].Value = "000123" '/* (datagrid is not truncating it)*/
range.Value2 = 123.0
Run Code Online (Sandbox Code Playgroud)
即使我在此之前设置了数字格式,它似乎也被作为数字处理:
range.NumberFormat = sNumberFormat;
range = (Range)sheet.Cells[iExcelRow, iExcelCol];
range.Value2 = this.Rows[iGridRow].Cells[iGridCol].Value.ToString();
Run Code Online (Sandbox Code Playgroud)
有人可以帮忙吗?
| 归档时间: |
|
| 查看次数: |
6028 次 |
| 最近记录: |