我必须用 C# 做一个 Excel 管理器,我选择使用 Gem Box Spreadsheet Free
var ef = new ExcelFile();
ef = ExcelFile.Load(File_Lettura);
ExcelWorksheet ws = ef.Worksheets.ActiveWorksheet;
int riga = 13;
string s = (ws.Cells["B6"]).ToString();
string[] r = s.Split('-');
int c = 0;
while (ws.Cells["B"+riga.ToString()].Value != null)
{
if (ws.Cells["F"+riga.ToString()].Value.ToString() != "")
{
// add row
dgwFile.Rows.Add();
dgwFile.Rows[c].Cells[0].Value = r[0] + "-" + r[1] + "-" + ws.Cells["B"+riga.ToString()].Value.ToString();
dgwFile.Rows[c].Cells[1].Value = ws.Cells["D" + riga.ToString()].Value.ToString() + ws.Cells["G" + riga.ToString()].Value.ToString() + ws.Cells["H" + riga.ToString()].Value.ToString() + ws.Cells["I" + riga.ToString()].Value.ToString();
dgwFile.Rows[c].Cells[2].Value = ws.Cells["F" + riga.ToString()].Value.ToString();
dgwFile.Rows[c].Cells[3].Value = "0";
c++;
}
riga++;
}
VS 在第一个“IF”出现错误:
发生了“System.NullReferenceException”类型的未处理异常。
我认为错误的行是前 3 行提前谢谢微笑 | :)
我也试过喜欢
ExcelFile ef = ExcelFile.Load(File_Lettura);
ExcelWorksheet ws = ef.Worksheets.ActiveWorksheet;