【发布时间】:2018-01-24 14:40:47
【问题描述】:
我在这里浏览了类似的帖子,但没有运气。我的 Excel 上传在本地可以正常工作,但在 Azure 上却出现了一个无法描述的错误(“处理您的请求时发生错误。)...EPPlus 不能在 Azure 上工作吗?
我的控制器:
[HttpPost]
public ActionResult Index(HttpPostedFileBase upload)
{
var fileName = Path.GetFileName(upload.FileName);
var path = Path.Combine(Server.MapPath("~/Excel"), fileName);
SqlConnection objConn = new SqlConnection(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString);
if (upload.ContentLength > 0)
{
upload.SaveAs(path);
}
FileInfo excel = new FileInfo(path);
using (var package = new ExcelPackage(excel))
{
var workbook = package.Workbook;
var worksheet = workbook.Worksheets["Sheet1"];
objConn.Open();
int totalRows = worksheet.Dimension.End.Row;
for (int i=2; i<=totalRows; i++)
{
string strSQL = "INSERT INTO Upload (Email, TimeStamp, EmployeeId, Name, Title, Department, Race, Gender, AnnualizedBase, AnnualizedTCC) VALUES ("
+ " '" + System.Web.HttpContext.Current.User.Identity.GetUserId() + "', "
+ " '" + DateTime.Now + "', "
+ " '" + worksheet.Cells[i, 1].Text.ToString() + "', "
+ " '" + worksheet.Cells[i, 2].Text.ToString() + "', "
+ " '" + worksheet.Cells[i, 3].Text.ToString() + "', "
+ " '" + worksheet.Cells[i, 4].Text.ToString() + "', "
+ " '" + worksheet.Cells[i, 5].Text.ToString() + "', "
+ " '" + worksheet.Cells[i, 6].Text.ToString() + "', "
+ worksheet.Cells[i, 7].Value + ", "
+ worksheet.Cells[i, 8].Value
+ ")";
var objCmd = new SqlCommand(strSQL, objConn);
objCmd.ExecuteNonQuery();
ViewBag.Message = "Dataset Uploaded Successfully!";
}
objConn.Close();
return View();
}
【问题讨论】:
-
我一直在 Azure 应用服务中使用 EPPlus Core(一个非官方的 .Net Core 端口)没有任何问题,所以我认为标准包应该可以工作。
标签: asp.net-mvc azure epplus