【发布时间】:2010-06-28 11:37:56
【问题描述】:
我想知道是否有人遇到过以下问题并对如何解决它有任何想法:我正在通过 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
即使我在此之前设置了 numberformat,它似乎也被作为数字处理:
range.NumberFormat = sNumberFormat;
range = (Range)sheet.Cells[iExcelRow, iExcelCol];
range.Value2 = this.Rows[iGridRow].Cells[iGridCol].Value.ToString();
有人可以帮忙吗?
【问题讨论】:
标签: c# excel com-interop