zoukankan      html  css  js  c++  java
  • NPOI导出自动换行效果

    string filename = "test.xls";
                Response.ContentType = "application/vnd.ms-excel";
                Response.AddHeader("Content-Disposition", string.Format("attachment;filename={0}", filename));
                Response.Clear();
                string reuslt = "0.8锌铁板制做烤漆字、食人鱼防水LED模组(三颗灯)、4mm厚黑白板(特殊材料,白天黑色,打灯后发白光) ";
                int splitnum = 25;
                int num = reuslt.Length;
                int rownum = num / splitnum + ((num % splitnum) > 0 ? 1 : 0);
                HSSFWorkbook workbook = new HSSFWorkbook();
                HSSFSheet sheet = (HSSFSheet)workbook.CreateSheet();
                int rowIndex = 0;
                int cellIndex = 0;
                HSSFRow row = (HSSFRow)sheet.CreateRow(rowIndex);
                row.HeightInPoints = rownum * 17;
                HSSFCell cell = (HSSFCell)row.CreateCell(cellIndex);
                HSSFCellStyle style = (HSSFCellStyle)workbook.CreateCellStyle();
                style.WrapText = true;
                string modify = "";
                for (int i = 0; i < rownum; i++)
                {
                    int start = splitnum * i;
                    int leave = num%(num - start);
                    modify+=(reuslt.Substring(start, leave == 0 ? splitnum : leave + 1) + "
    ");
                }
                cell.CellStyle = style;
                cell.SetCellValue(modify.TrimEnd('
    '));
                MemoryStream file = new MemoryStream();
                workbook.Write(file);
                file.WriteTo(Response.OutputStream);
                Response.End();
  • 相关阅读:
    docker部署数据库
    JAVA 删除Map中元素(JDK8)
    Docker 学习记录基于Linux
    Liunx 操作命令学习记录
    NACOS 认识和学习
    SpringCloud 学习及其相关组件的认识
    springBoot 配置文件的优先级
    配置redisTemplate的序列化
    springBoot 使用测试类报错
    注解反射的认识
  • 原文地址:https://www.cnblogs.com/youhaoxinqin/p/4143259.html
Copyright © 2011-2022 走看看