Aspose.Cells导入Excel,Aspose.Cells读取Excel
Posted 棉晗榜
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Aspose.Cells导入Excel,Aspose.Cells读取Excel相关的知识,希望对你有一定的参考价值。
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
public async Task<ResultInfo> BatchImport(Stream stream, string roleGuid)
{
if (stream == null)
{
return new ResultInfo() { Messages = "stream不可为空" };
}
if (string.IsNullOrWhiteSpace(roleGuid))
{
return new ResultInfo() { Messages = "roleGuid不可为空" };
}
Aspose.Cells.Workbook wb = new Aspose.Cells.Workbook(stream);
Aspose.Cells.Worksheet sheet = wb.Worksheets[0];
Aspose.Cells.Cells cells = sheet.Cells;
if (cells.Rows.Count == 1)
{
return new ResultInfo() { Messages = "导入数据至少一行" };
}
List<Sys_UsersInfo> list = new List<Sys_UsersInfo>();
for (int i = 0; i < cells.Rows.Count; i++)
{
if (i == 0)
{
continue;
}
Sys_UsersInfo user = new Sys_UsersInfo();
var row_cells = cells.Rows[i];
//姓名
var xing_ming_cell = row_cells.GetCellOrNull(0);
user.fullname = xing_ming_cell.StringValue;
//账号
var account_cell = row_cells.GetCellOrNull(1);
user.account = account_cell.StringValue;
//部门id
var bum_cell = row_cells.GetCellOrNull(2);
string bumenGuid = bum_cell.StringValue;
Guid departmentGuid;
if (!Guid.TryParse(bumenGuid, out departmentGuid))
{
return new ResultInfo() { Messages = "部门guid值无效,格式:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" };
}
user.departmentguid = departmentGuid;
user.roleguid = roleGuid;
list.Add(user);
}
}
}
以上是关于Aspose.Cells导入Excel,Aspose.Cells读取Excel的主要内容,如果未能解决你的问题,请参考以下文章
Aspose.Cells导入excel文件异常No data is available for encoding 936.