java setting operation of Excel cell poi its way

Setting the cell to its embodiment
com.java.poi package;

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;

/**
 * Set the cell its way
 * @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); // create a row
        row.setHeightInPoints(30);
        createCell(wb,row,(short) 0, (short)600,(short) 600);

        FileOutputStream fileOutputStream=new FileOutputStream("E:\\3.xls");
        wb.write(fileOutputStream);
        fileOutputStream.close();
    }

    /**
     * Create a cell, and assign its way
     * @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")); // set value
        CellStyle cellStyle = wb.createCellStyle (); // set the style
        cellStyle.setAlignment (HorizontalAlignment.forInt (halign)); // set the horizontal direction thereof manner
        cellStyle.setVerticalAlignment (VerticalAlignment.forInt (valign)); // Sets the vertical alignment method
        cell.setCellStyle (cellStyle); // Set the cell style

    }
}

  

Guess you like

Origin www.cnblogs.com/nidegui/p/11038801.html