我正在编写一个打开现有.xlsx
文件并写入某些单元格的应用程序。
有些单元格正确写入,其他单元格保持空白?
有什么想法吗?
这是一段代码
除了索引已更改
之外,有效且不起作用的单元格的代码相同oSheet.Cells[3, 15] = "1"; // this doesnt write to the cell
oSheet.Cells[7, 7] = "1"; // this writes to the cell
我能想到的只是Excel文件中存在格式化问题?
答案 0 :(得分:1)
我一直在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似乎更加一致,所以我通常建议使用它。
干杯!
答案 1 :(得分:1)
安东尼是对的,我的列和行已经切换了。