运行时候老是提示未将对象引用到设置到对象实例中,应该怎么处理才对?
DataTable dt = new DataTable( FilePath);
FileStream fs = new FileStream("", FileMode.Open, FileAccess.Read);
NPOI.XSSF.UserModel.XSSFWorkbook book = new NPOI.XSSF.UserModel.XSSFWorkbook(fs);
//是否找到表头
bool isTitle = false;
NPOI.SS.UserModel.ISheet sheet = book.GetSheetAt(0);
for (int i = 0; i <= sheet.LastRowNum; i++)
{
NPOI.SS.UserModel.IRow row = sheet.GetRow(i);
if (row.GetCell(0).ToString() == "INVOICENO")
{
//表头行
isTitle = true;
if (row == null) continue;
int firstCellNum = row.FirstCellNum;
int lastCellNum = row.LastCellNum;
if (firstCellNum == lastCellNum) continue;
for (int ji = firstCellNum; ji < lastCellNum; ji++)
{
if (!dt.Columns.Contains(row.GetCell(ji).ToString()))
{
dt.Columns.Add(row.GetCell(ji).StringCellValue, typeof(string));
}
}
}
if (isTitle)
{
//其它行
DataRow newRow = dt.Rows.Add();
for (int j = 0; j < 14; j++)
{
newRow[j] = row.GetCell(j).ToString();
}
}
}