/**Tochangethislicenseheader,chooseLicenseHeadersinProjectProperties.*Tochangethistemplatefile,chooseTools|Templates*andopenthetemplateintheeditor.*/packagepoidemo1;impor...
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package poidemo1;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
/**
*
* @author Administrator
*/
public class PoiDemo5 {
public static void main(String[] args) throws IOException {
InputStream inputStream=new FileInputStream("f:/设置字体.xls");
POIFSFileSystem fSFileSystem=new POIFSFileSystem(inputStream);
Workbook wb=new HSSFWorkbook(fSFileSystem);
Sheet sheet= wb.getSheetAt(0);//获取一个sheet页
Row row=sheet.getRow(0);//获取第一行
Cell cell=row.getCell(0);//获取单元格
if (cell==null) {
cell=row.createCell(3);
}
cell.setCellType(Cell.CELL_TYPE_STRING);
cell.setCellValue("测试单元格");
FileOutputStream fileOutputStream=new FileOutputStream("f:/设置字体.xls");
wb.write(fileOutputStream);
fileOutputStream.close();
}
}
展开