zoukankan      html  css  js  c++  java
  • (五)POI-设置单元格的对齐方式

    原文链接:https://blog.csdn.net/class157/article/details/92817149

    package com.java.poi;
     
    import org.apache.poi.hssf.usermodel.HSSFRichTextString;
    import org.apache.poi.hssf.usermodel.HSSFWorkbook;
    import org.apache.poi.ss.usermodel.*;
     
    import java.io.FileOutputStream;
     
    /**
     * @program: IdeaProjects
     * @description:
     * @author: Lxy
     * @create: 2019-06-19 09:22
     **/
    public class Test6 {
     
        public static void main(String[] args) throws Exception {
            Workbook wb = new HSSFWorkbook();
            Sheet sheet = wb.createSheet("创建sheet页");
            Row row = sheet.createRow(2);//创建行
            row.setHeightInPoints(30);
            createCell(wb, row, (short) 0, (short)2, (short)1);
     
            FileOutputStream fileOutputStream = new FileOutputStream("D:\4.xls");
            wb.write(fileOutputStream);
            fileOutputStream.close();
        }
     
        /**
         * 创建一个单元格,并为其指定对其的方式
         *
         * @param wb
         * @param row
         * @param colunm
         * @param halign
         * @param valign
         */
        private static void createCell(Workbook wb, Row row, short colunm, short halign, short valign) {
            Cell cell = row.createCell(colunm);
            cell.setCellValue(new HSSFRichTextString(" Align  it")); //设置值
            CellStyle cellStyle = wb.createCellStyle();  //设置样式
            cellStyle.setAlignment(HorizontalAlignment.forInt(halign)); //设置水平方向的对其方式
            cellStyle.setVerticalAlignment(VerticalAlignment.forInt(valign)); //设置垂直方法的对齐方式
           //  cellStyle.setAlignment(HorizontalAlignment.CENTER);
           // cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
            cell.setCellStyle(cellStyle); //设置单元格样式
     
        }
    }
    

      

  • 相关阅读:
    vue中使用第三方UI库的移动端rem适配方案
    前端规范--eslint standard
    从上往下打印二叉树
    栈的压入,弹出序列
    随机森林
    LR
    顺时针打印矩阵
    包含min函数的栈
    树的子结构
    合并两个有序链表
  • 原文地址:https://www.cnblogs.com/lvchengda/p/12941395.html
Copyright © 2011-2022 走看看