zoukankan      html  css  js  c++  java
  • java操作Excel的poi 设置单元格的对其方式

    设置单元格的对其方式
    package com.java.poi;
    
    import org.apache.poi.hssf.usermodel.HSSFCell;
    import org.apache.poi.hssf.usermodel.HSSFCellStyle;
    import org.apache.poi.hssf.usermodel.HSSFRichTextString;
    import org.apache.poi.hssf.usermodel.HSSFWorkbook;
    import org.apache.poi.ss.usermodel.*;
    
    import java.io.FileOutputStream;
    
    /**
     * 设置单元格的对其方式
     * @author nidegui
     * @create 2019-06-17 9:46
     */
    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)600,(short) 600);
    
            FileOutputStream fileOutputStream=new FileOutputStream("E:\3.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)); //设置垂直方法的对齐方式
            cell.setCellStyle(cellStyle); //设置单元格样式
    
        }
    }
    

      

  • 相关阅读:
    斐波那契(通项公式)
    数论--欧几里得定理(求最大公约数)
    5790 素数序数(筛素数版)
    数论--筛法求素数
    2491 玉蟾宫
    闭包详解
    ASP.NET 页生命周期概述1
    IIS 7.0 的 ASP.NET 应用程序生命周期概述
    IIS 5.0 和 6.0 的 ASP.NET 应用程序生命周期概述
    WeUI logo专为微信设计的 UI 库 WeUI
  • 原文地址:https://www.cnblogs.com/nidegui/p/11038801.html
Copyright © 2011-2022 走看看