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;

    }

  • 相关阅读:
    ROS安装
    安装octomap的问题与解决方案
    陀螺仪和加速度计MPU6050的单位换算方法
    概率基础
    Ubuntu使用多线程cmake时出现undefined reference to `pthread_create'
    C++中的static关键字的总结
    QSignalMapper的使用和使用场景
    Linux下C ,C ++, Qt开发环境
    void operator()()的功能
    C++11多线程编程--线程创建
  • 原文地址:https://www.cnblogs.com/imust2008/p/15068509.html
Copyright © 2011-2022 走看看