[HttpPost]
public ActionResult UploadExcel(HttpPostedFileBase file)
{
if (file != null && file.ContentLength > 0)
{
// 保存上传的文件
var path = Path.Combine(Server.MapPath("~/uploads/"), file.FileName);
file.SaveAs(path);

// 读取Excel文件并解析数据
using (ExcelPackage package = new ExcelPackage(file.InputStream))
{
ExcelWorksheet worksheet = package.Workbook.Worksheets[0]; // 第一个工作表

int rowCount = worksheet.Dimension.Rows;
int colCount = worksheet.Dimension.Columns;

for (int row = 1; row <= rowCount; row++)
{
for (int col = 1; col <= colCount; col++)
{
// 在这里处理每个单元格的数据,可以根据需要进行进一步的操作
// 例如将数据保存到数据库或其他数据存储中
string cellValue = worksheet.Cells[row, col].Value.ToString();
Console.WriteLine("Cell Value: " + cellValue);
}
}
}
}
else
{
// 处理未选择文件的情况,可以返回错误信息或其他操作
ViewBag.ErrorMessage = "Please select a valid Excel file.";
}

return View(); // 返回原始视图或其他适当的视图以完成文件上传操作
}

posted @ 2023-12-11 20:57 荧屏 阅读(17) 评论(0) 推荐(0) 编辑
摘要: public static byte[] ConvertDataTableToExcelBuffer(DataTable table) { ExcelPackage.LicenseContext = LicenseContext.NonCommercial; byte[] result = null 阅读全文
posted @ 2023-12-11 18:11 荧屏 阅读(11) 评论(0) 推荐(0) 编辑
摘要: //删除确认 function m_del(id) { layer.confirm('确认删除?',{ btn:['确认','取消'], },function(index,layero){ $.ajax({ type: "POST", url: durl, data: { 'id': id }, s 阅读全文
posted @ 2023-09-25 14:29 荧屏 阅读(22) 评论(0) 推荐(0) 编辑
摘要: public class Program { private static TestDBContext _tContext; private static void Main(string[] args) { Startup(); var dd = _tContext.User.Take(1).To 阅读全文
posted @ 2023-07-25 11:19 荧屏 阅读(100) 评论(0) 推荐(1) 编辑
摘要: 以a_1表 循环 插入 b_1 表为例 1.普通的循环 插入a_1表 --一个正常的循环 指定30次 插入数据 declare @i int set @i=1 while @i<30 begin insert into a_1(a)values(@i) set @i=@i+1 end 2.循环a_1 阅读全文
posted @ 2023-07-21 15:45 荧屏 阅读(530) 评论(0) 推荐(0) 编辑
摘要: 网上找了很多 都是链接失效的,找了很多次就找到了 我分享出来 链接:https://pan.baidu.com/s/1jax1tfHWFKIkSISu0jBZ7w 提取码:mawy 然后欢迎观临我的淘宝小店: 可接 阅读全文
posted @ 2023-06-09 17:57 荧屏 阅读(6) 评论(0) 推荐(0) 编辑
摘要: https://cloud.tencent.com/developer/article/1531860?from=15425&areaSource=102001.1&traceId=B4KzYkzcjSz31MUNIH68v 阅读全文
posted @ 2023-03-09 13:18 荧屏 阅读(80) 评论(0) 推荐(0) 编辑
摘要: public ActionResult V1() { try { string filePath = "E://123.pdf"; if (System.IO.File.Exists(filePath) == false) { return base.Content("文件不存在!"); } Res 阅读全文
posted @ 2023-03-09 13:14 荧屏 阅读(308) 评论(0) 推荐(0) 编辑
摘要: function showHtml(str) { $("#btn").html("<input value= " + str.replace(/\'/g, "&#39;") + " />");//单引号 //$("#btn").html("<input value= " + str.replace( 阅读全文
posted @ 2023-02-22 13:36 荧屏 阅读(20) 评论(0) 推荐(0) 编辑
摘要: 找的一个解决方案,这个简单明了 还能用,备份一下 两台同局域网的电脑 A机器:IIS WEB服务器 B机器:文件盘服务 添加文件共享 添加用户 admin/123456,(可能文件共享的全下你了要添加这个用户,有的也可以不添加) 解决方法: 1.需要在A机器上创建一个和B服务器一样的用户和密码 ad 阅读全文
posted @ 2022-11-28 16:18 荧屏 阅读(494) 评论(0) 推荐(0) 编辑
点击右上角即可分享
微信分享提示