Created
November 7, 2017 04:34
-
-
Save bxb100/f62f5bb3a5fc3c892bf9a704ebefcc94 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package cn.itcast.jx.util; | |
import org.apache.poi.ss.usermodel.*; | |
import org.apache.poi.xssf.usermodel.XSSFWorkbook; | |
import java.io.File; | |
import java.io.FileNotFoundException; | |
import java.io.FileOutputStream; | |
/** | |
* Created by JohnBi on 2017/11/7. 9:54 | |
* | |
* @author Lemon | |
*/ | |
public class POIUtil { | |
public static void main(String[] args) throws Exception { | |
Workbook wb = new XSSFWorkbook(); | |
// Create a new Sheet for this workbook and assign sheet name test1(must less than 31 char) | |
Sheet sheet = wb.createSheet("test1"); | |
// create a new row within the sheet | |
Row row = sheet.createRow(3); | |
Cell cell = row.createCell(3); | |
cell.setCellValue("测试 test 吾问无为谓吾问无为谓吾问无为谓吾问"); | |
// set cell font style | |
Font font = wb.createFont(); | |
font.setFontHeightInPoints((short) 24); | |
font.setFontName("宋体"); | |
CellStyle cellStyle = wb.createCellStyle(); | |
cellStyle.setFont(font); | |
cell.setCellStyle(cellStyle); | |
// save this .xlsx document | |
FileOutputStream fos = new FileOutputStream(new File("d:/test.xlsx")); | |
// write workbook into outputStream | |
wb.write(fos); | |
// flush buffered output stream | |
fos.flush(); | |
fos.close(); | |
// end | |
System.out.println("end"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment