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;

    }

  • 相关阅读:
    傻瓜教程:asp.net(c#) 如何配置authentication,完成基于表单的身份验证
    ajax与php交互的get和post两种实现方式
    php 存储过程
    一万小时天才理论
    servlet阅读
    post and get
    合并两个有序数组(重新开始)
    Java参数传递问题
    一万小时(如何实现)阅读
    java IO 流的学习(我们到底能走多远系列1)
  • 原文地址:https://www.cnblogs.com/imust2008/p/15068509.html
Copyright © 2011-2022 走看看