当然,首先要下载POI的jar包。官网自己去下载吧 代码: import java.io.File;import java.io.FileOutputStream;import java.io.IOException;import org.apache.poi.hssf.usermodel.HSSFCell;import org.apache.poi.hssf.usermodel.HSSFCellStyle;import org.apache.poi.hssf.usermodel.HSSFRow;import org.apache.poi.hssf.usermodel.HSSFSheet;import org.apache.poi.hssf.usermodel.HSSFWorkbook;import org.apache.poi.hssf.util.HSSFColor;public class Temp1{/** * @param args * @throws IOException */public static void main(String[] args) throws IOException{File resultFile = null;HSSFWorkbook wb = null;FileOutputStream fos = null;HSSFSheet sheet = null;HSSFRow row = null;HSSFCell cell = null;HSSFCellStyle cellType = null;// result fileresultFile = new File("D:/result.xls");// create a workbookwb = new HSSFWorkbook();// create a cell stylecellType = wb.createCellStyle();cellType.setBorderTop(HSSFCellStyle.BORDER_THIN);cellType.setBorderBottom(HSSFCellStyle.BORDER_THIN);cellType.setBorderLeft(HSSFCellStyle.BORDER_THIN);cellType.setBorderRight(HSSFCellStyle.BORDER_THIN);cellType.setAlignment(HSSFCellStyle.ALIGN_CENTER);cellType.setFillForegroundColor(HSSFColor.GOLD.index);cellType.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);// create a sheet named "hello"sheet = wb.createSheet("hello");// create a rowrow = sheet.createRow(1);// create a cellcell = row.createCell(1);// set style of cellcell.setCellStyle(cellType);// set value of cellcell.setCellValue("hello world!");fos = new FileOutputStream(resultFile);// save workbookwb.write(fos);fos.flush();fos.close();}}import ja 你的当前访问异常,请进行认证后继续阅读剩余内容。 提交