Controllers/HomeController.cs
(开头部分) 5KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using OfficeOpenXml;
using xlxsToJsonString.Models;
namespace xlxsToJsonString.Controllers
{
public class HomeController : Controller
{
private readonly IHostingEnvironment hostingEnvironment;
private readonly GeneralDBContext generalDBContext;
public HomeController(IHostingEnvironment hostingEnvironment, GeneralDBContext generalDBContext)
{
this.hostingEnvironment = hostingEnvironment;
this.generalDBContext = generalDBContext;
}
/// <summary>
/// 导入xlsx文件
/// </summary>
/// <returns></returns>
public IActionResult Index()
{
return View();
}
/// <summary>
/// 导出
/// </summary>
/// <returns></returns>
[HttpGet]
public IActionResult Export()
{
string sWebRootFolder = hostingEnvironment.WebRootPath;
string sFileName = $"{Guid.NewGuid()}.xlsx";
FileInfo file = new FileInfo(Path.Combine(sWebRootFolder, sFileName));
using (ExcelPackage package = new ExcelPackage(file))
{
// 添加worksheet
ExcelWorksheet worksheet = package.Workbook.Worksheets.Add("aspnetcore");
//添加头
worksheet.Cells[1, 1].Value = "ID";
worksheet.Cells[1, 2].Value = "Name";
worksheet.Cells[1, 3].Value = "Url";
//添加值
worksheet.Cells["A2"].Value = 1000;
worksheet.Cells["B2"].Value = "51aspx1";
worksheet.Cells["C2"].Value = "https://www.51aspx.com/";
后面还有 103 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明
AI 解读
登录后可用,每次 10 积分,解读结果公开显示在下面。
还没有人解读过这个文件。
