• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录

gisoracle

  • 博客园
  • 联系
  • 订阅
  • 管理

公告

View Post

java org 写excel

java org 写excel

package com.csland.workflow.business;

import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.*;
import java.io.FileOutputStream;

public class ylexcel {
  public ylexcel() {

  }

  private static void createCellTitle(HSSFWorkbook wb, HSSFRow row, int column,
                                      String value) {
    HSSFCell cell = row.createCell((short)column);

    HSSFCellStyle cellStyle = wb.createCellStyle();
    cellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);

    HSSFFont font = wb.createFont();
    font.setFontHeightInPoints( (short) 11);   ;
    font.setFontName("宋体");
    font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);

    cellStyle.setFont(font);

    cell.setCellStyle(cellStyle);

    cell.setCellValue(value);

  }

  private static void createFile(String outputFile) {
    try {
      // Create a New XL Document
      HSSFWorkbook wb = new HSSFWorkbook();
      // Make a worksheet in the XL document created
      HSSFSheet sheet = wb.createSheet();
      // Create row at index zero ( Top Row)

      HSSFRow row = sheet.createRow( (short) 0);
      for (int i = 0; i < 10; i++) {
        createCellTitle(wb, row, i, "gisoracle" + i);

      }

      // The Output file is where the xls will be created
      FileOutputStream fOut = new FileOutputStream(outputFile);
      // Write the XL sheet
      wb.write(fOut);
      fOut.flush();
      // Done Deal..
      fOut.close();
      System.out.println("File Created ..");

    }
    catch (Exception e) {
      System.out.println("!!BANG!! xlCreate() : " + e);
    }
  }

  public static void ylb(String ym) {
    System.out.println("poi");
    createFile("c:/test.xls");
    System.out.println("==============");

  }

}

posted on 2009-07-02 11:18  gisai  阅读(251)  评论(0)    收藏  举报

刷新页面返回顶部
 
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3