一些Excel单元格保持未填充,C#

我正在编写一个应用程序,打开一个现有的.xlsx文件并写入某些单元格。

有些单元格正确写入,其他单元保持空白?

有任何想法吗?

这是一段代码

除了索引已更改外,其他单元格和单元格的代码都是相同的

 oSheet.Cells[3, 15] = "1"; // this doesnt write to the cell oSheet.Cells[7, 7] = "1"; // this writes to the cell 

所有我能想到的是,Excel文件中存在格式问题?

我一直在Excel工作多年,一直在找这样的怪癖。 如果你在.NET 4.0中试试这个:

 using Excel = Microsoft.Office.Interop.Excel //Other Class code var range = oSheet.Cells[3, 15]; range.Value2 = "1"; 

否则,试试这个:

 using Excel = Microsoft.Office.Interop.Excel //Other Class code Excel.Range range = (Excel.Rang)oSheet.Cells[3, 15]; range.Value2 = "1"; 

Value2似乎工作更一致,所以我通常build议使用它。

干杯!

安东尼是正确的,我有我的列和行切换。