zoukankan      html  css  js  c++  java
  • EPPlus单元格和样式(含文字竖排)

    using (var package = new ExcelPackage())
    {
    ExcelWorksheet worksheet = package.Workbook.Worksheets.Add("Sheet1");

    //1,赋值
    worksheet.Cells[int row, int col].Value = "xxx";
    //或者
    worksheet.Cells["A1"].Value = "xxx";
    //或者
    worksheet.SetValue(row,col,value);

    //2,单元格合并

    //指定开始行,开始列,结束行,结束列
    worksheet.Cells[fromRow, fromCol, toRow, toCol].Merge = true;

    //行合并
    worksheet.Cells["A1:A5"].Merge = true;//合并A列的1-5行

    //列合并
    worksheet.Cells["A1:G1"].Merge = true;//合并第1行的A-G列

    //3,样式

    worksheet.Cells.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;//水平居中,全局
    worksheet.Cells.Style.VerticalAlignment = ExcelVerticalAlignment.Center;//垂直居中,全局
    worksheet.Cells.AutoFitColumns();//全局
    worksheet.Cells.Style.WrapText = true;//自动换行,全局
    worksheet.Cells.Style.Font.Name = "宋体";//全局

    worksheet.Cells["A1"].Style.VerticalAlignment = ExcelVerticalAlignment.Center;//垂直居中,只针对特定单元格

    worksheet.Cells["A1:A5"].Style.VerticalAlignment = ExcelVerticalAlignment.Center;//垂直居中,只针对某范围单元格

    worksheet.Cells["A5"].Style.TextRotation = 180;//内容旋转

    worksheet.Cells["P5"].Style.SetTextVertical(); //文字竖排

    //调整行高
    double rowHeight = 15;
    worksheet.Row(1).Height = rowHeight;

    //调整列宽
    double columnWidth = 50;
    worksheet.Column(1).Width = columnWidth;

    //自动适应长宽

    worksheet.Column(1).BestFit = true;

    }

  • 相关阅读:
    aa
    MySQL5.8下载及安装——免安装版
    eclipse中修改项目名
    利用kibana学习 elasticsearch restful api (DSL)
    https://www.cnblogs.com/shwee/p/9084535.html
    springboot+mybatis实现动态切换数据源
    docker-machine命令安装
    Docker 安装 RabbitMq
    yum 找不到程序,yum更换国内阿里源
    CentOS安装etcd和flannel实现Docker跨物理机通信
  • 原文地址:https://www.cnblogs.com/imust2008/p/15068509.html
Copyright © 2011-2022 走看看