我正在阅读一个 excel 文件的列。列不能为空。我如何测试每一列,即 col1value 到 col15value 而不对所有列使用 && 语句
for (int rowNumber = startRow + 1; rowNumber <= currentWorkSheet.Dimension.End.Row; rowNumber++)
// read each row from the start of the data (start row + 1 header row) to the end of the spreadsheet.
{
try
{
object col1Value = currentWorkSheet.Cells[rowNumber, 1].Value;
object col2Value = currentWorkSheet.Cells[rowNumber, 2].Value;
object col3Value = currentWorkSheet.Cells[rowNumber, 3].Value;
object col4Value = currentWorkSheet.Cells[rowNumber, 4].Value;
object col5Value = currentWorkSheet.Cells[rowNumber, 5].Value;
object col6Value = currentWorkSheet.Cells[rowNumber, 6].Value;
object col7Value = currentWorkSheet.Cells[rowNumber, 7].Value;
object col8Value = currentWorkSheet.Cells[rowNumber, 8].Value;
object col9Value = currentWorkSheet.Cells[rowNumber, 9].Value;
object col10Value = currentWorkSheet.Cells[rowNumber, 10].Value;
object col11Value = currentWorkSheet.Cells[rowNumber, 11].Value;
object col12Value = currentWorkSheet.Cells[rowNumber, 12].Value;
object col13Value = currentWorkSheet.Cells[rowNumber, 13].Value;
object col14Value = currentWorkSheet.Cells[rowNumber, 14].Value;
object col15Value = currentWorkSheet.Cells[rowNumber, 15].Value;
if ((col1Value != null && col2Value != null && col3Value != null))
{
excelFileDataList.Add(new priceAddDelete
{
businessunitcode = col1Value.ToString(),
customerNumber = Convert.ToInt32(col2Value),
productcode = col3Value.ToString(),
sizecode = col4Value.ToString(),
finishingmethodcode = col5Value.ToString(),
startdate = Convert.ToDateTime(col6Value),
typeofprice = col7Value.ToString(),
pricetype = Convert.ToInt32(col8Value),
typeofrent = Convert.ToInt32(col9Value),
changesperweek = Convert.ToInt32(col10Value),
adddelete = col11Value.ToString(),
price = Convert.ToInt32(col12Value),
processed = Convert.ToInt32(col13Value),
processed_date = Convert.ToDateTime(col14Value),
systemuser_id = Convert.ToInt32(col15Value)
});
}
}
catch (Exception ex)
{
}
}