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;

    }

  • 相关阅读:
    STL简介
    Java语言实现简单FTP软件------>上传下载队列窗口的实现(七)
    c++模板
    10891
    错误处理:java.lang.NoSuchMethodException: org.apache.catalina.deploy.WebXml addFilter
    Linux crontab 语法和具体的例子
    LoadImage()使用
    matplotlib简单的新手教程和动画
    三白话经典算法系列 Shell排序实现
    AccountManager教程
  • 原文地址:https://www.cnblogs.com/imust2008/p/15068509.html
Copyright © 2011-2022 走看看