您的位置:首页 > 其它

.NET导入导出excel的简单方法

2014-04-01 22:19 253 查看
  {

  IRow row = sheet1.GetRow(i);

  Shop_Product product = new Shop_Product();

  string category = row.GetCell(2) != null ? row.GetCell(2).ToString() : null;

  if (!string.IsNullOrEmpty(category))

  {

  var cate =

  _unitOfWork.Shop_ProductCategoryRepository().GetAll().FirstOrDefault(t => t.Name == category);

  if (cate != null)

  {

  product.ProductCategoryName = cate.Name;

  product.Shop_ProductCategory_ID = cate.ID;

  }

  else

  {

  continue;

  }

  }

  else

  {

  continue;

  }

  product.PName = row.GetCell(0) != null ? row.GetCell(0).ToString() : null;

  product.PCName = row.GetCell(1) != null ? row.GetCell(1).ToString() : null;

  if (row.GetCell(3) != null)

  {

  product.Price = Double.Parse(row.GetCell(3).ToString());

  }

  product.Description = row.GetCell(4) != null ? row.GetCell(4).ToString() : null;

  _unitOfWork.Shop_ProductRepository().Insert(product);

  }

  _unitOfWork.Save();

  }

  catch

  {

  return false;

  }

  return true;

  }

  复制代码
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: