C#导出excel

本文介绍了如何使用C#编程语言来实现Excel文件的导出功能,虽然文章中提到单元格填充背景色的问题尚未解决。
摘要由CSDN通过智能技术生成

话不多说
直接上代码
其中,单元格填充背景色还没搞定

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AMes.Code;
using AMes.Data;
using AMes.Domain.Entity.BasicDataManage;
using AMes.Domain.Entity.ProcessInspectionManage;
using NPOI.HSSF.UserModel;
using NPOI.HSSF.Util;
using NPOI.SS.UserModel;
using NPOI.SS.Util;

namespace AMes.Application.ExcelImport
{
   
    public class DeBugExcelExport
    {
   
        IRepositoryBase service = new RepositoryBase();


        public string Export(string[] VersionIds)
        {
   
            string path = AppDomain.CurrentDomain.BaseDirectory + Configs.GetValue("ExportPath") + "\\调试记录导出模板.xls";
            //开启文件流
            FileStream fs = null;
            //创造一个
            IWorkbook workBook = null;
            try
            {
   
                fs = new FileStream(path, FileMode.OpenOrCreate, FileAccess.ReadWrite);
                workBook = new HSSFWorkbook();

                //创建一个样式
                ICellStyle style1 = workBook.CreateCellStyle();
                //设置单元格字体居中
                style1.Alignment = HorizontalAlignment.Center;
                style1.VerticalAlignment = VerticalAlignment.Center;//上下居中       
                //设置边框
                style1.BorderBottom = BorderStyle.Thin;
                style1.BorderLeft = BorderStyle.Thin;
                style1.BorderRight = BorderStyle.Thin;
                style1.BorderTop = BorderStyle.Thin;
                style1.BottomBorderColor = HSSFColor.Black.Index;
                style1.LeftBorderColor = HSSFColor.Black.Index;
                style1.RightBorderColor = HSSFColor.Black.Index;
                style1.TopBorderColor = HSSFColor.Black.Index;

                //设置字体
                IFont font = workBook.CreateFont();
                font.FontName = "宋体";
                font.FontHeightInPoints = 11;
                style1.SetFont(font);

                //设置背景色
                style1.FillBackgroundColor = HSSFColor.Blue.Index;
                style1.FillPattern = FillPattern.SolidForeground;

                ICellStyle style = workBook.CreateCellStyle();
                style.FillForegroundColor = NPOI.HSSF.Util.HSSFColor.Red.Index;
                style.FillPattern = FillPattern
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值