.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;
}
复制代码
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;
}
复制代码
相关文章推荐
- 【MVC】 非常简单的页面导出 WORD, EXCEL方法
- ASP 最简单导出excel的方法
- asp导出excel文件最简单方便的方法
- winform中 将listview的数据导出至 excel (最简单的方法)
- VB6数据导出到Excel文件,一种设计界面查询条件的方法,一种简单加密方法(改写)
- ASP.NET中导出excel/word等类型文件的简单方法
- 将repeater、datalist、gridview中的数据导出到Excel中的简单方法
- ASP.net中导出Excel的简单方法介绍
- java 导出excel封装了一个简单的导出方法。
- asp.net导出excel的简单方法实例
- 导出Excel的简单方法,并可以解决乱码问题
- asp导出excel文件最简单方便的方法
- asp.net导出excel的简单方法实例
- phpexcel php导入导出excel表格的简单方法
- .net导出excel简单方法,有什么方法大家都推荐下 啊,菜鸟才学习
- 导入Excel和导出Excel:的简单方法与程序处理方法,使用Excel程序读写Excel ,实现Excel的多个 Sheets读写并导出
- ASP.NET中导出excel/word等类型文件的简单方法
- 非常简单方便的导出Excel的方法
- 将repeater、datalist、gridview中的数据导出到Excel中的简单方法
- 从gridview 中查询数据导出Excel 简单方法