NPOI HSSFWorkbook自建格式导出

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.IO;
using Microsoft.AspNetCore.Mvc;
using NPOI.HSSF.UserModel;
using Microsoft.EntityFrameworkCore;
using NPOI.SS.UserModel;
using Jiumu.Entity;

namespace Project1.Controllers
{
   
    public class OutputExcel:ControllerBase
    {
   
        private readonly SalesbudgetquotingplatformContext Context;

        public OutputExcel(SalesbudgetquotingplatformContext context)
        {
   
            Context = context;
        }

        #region NPOI导出到Excel 
        //NPOI导出到Excel(故障码)
        public ActionResult ExportToExcel()
        {
   

            //查询数据
            var entity = Context.MatPrice.Include(x=>x.MatSupplier).Include(x => x.MatWarehouse).Include(x => x.MatWarehouse.MatRaw).Where(x=> string.IsNullOrEmpty(x.MatWarehouse.SyncId)).OrderBy(x=>x.MatWarehouse.Name).ToList();
            //二:代码创建一个Excel表格(这里称为工作簿)
            //创建Excel文件的对象 工作簿(调用NPOI文件)
            HSSFWorkbook excelBook = new HSSFWorkbook();
            ICellStyle style1 = excelBook.CreateCellStyle();//声明style1对象,设置Excel表格的样式
            ICellStyle style2 = excelBook.CreateCellStyle();
            ICellStyle style3 = excelBook.CreateCellStyle();
            IFont font = excelBook.CreateFont();
            font.Color = IndexedColors.Red.Index;
            //style3.SetFont(font);
            style1.Alignment = HorizontalAlignment.Justify;//两端自动对齐(自动换行)
            style1.VerticalAlignment = VerticalAlignment.Center;
            style2.Alignment = HorizontalAlignment.Center;
            style2.VerticalAlignment = VerticalAlignment.Center;
            style3.Alignment = HorizontalAlignment.Center;
            style3.VerticalAlignment = VerticalAlignment.Center;
            //创建Excel工作表 Sheet=故障码信息
            
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值