JAVA编码(19)——java使用f1j9swing来生成excel文件

工程需要引入 f1j9swing.jar包

执行导出Excel案例:详见360云盘,“经典详例Demo”


package sinosoft_xsy; import java.io.IOException; import com.f1j.ss.BookModelImpl; import com.f1j.ss.CellFormat; import com.f1j.ss.Constants; import com.f1j.ss.WriteParams; import com.f1j.util.F1Exception; public class Sinosoft { static CellFormat mCellFormat = new CellFormat(); static CellFormat mLeftTopCF = new CellFormat(); static CellFormat mInputCF = new CellFormat(); public static void main(String[] args) { testExcel(); } /** * 使用f1j9swing来生成excel */ public static void testExcel(){ BookModelImpl book = new BookModelImpl(); BookModelImpl modelBook = new BookModelImpl(); try { book.initWorkbook(); setCellFormat(); //读取已有的模板 modelBook.read("E:\\workspace3.7\\gs_acc\\hkcwweblogic\\account\\yd_work\\BulletinReport\\BulletinReport_1.xls"); //读取模版Excel,所有cell的样式在这里面定义好 ,每生成一个sheet就copy下,最省事 book.copyRange(0, 0, modelBook.getLastRow(), modelBook.getLastCol(), modelBook, 0, 0, modelBook.getLastRow(), modelBook.getLastCol(), Constants.eCopyAll); for (int i = 0; i <= modelBook.getLastCol(); i++) { book.setColWidth(i, modelBook.getColWidth(i));//设置列宽,即模板中的列为多宽,则生成的excel的列也为多宽 } book.setText(2,0,"2015年05月21日"); for (int m = 9; m <= 34; m++) {//实际要显示的xls要放值的开始行和结束行 System.out.println(m); book.setNumber(m-1, 3, 11); book.setNumber(m-1, 4, 11); book.setNumber(m-1, 5, 11); } book.setSheetName(0, "本季度快报"); book.insertSheets(0, 1); // Excel文件输出 book.write("E:\\workspace3.7\\gs_acc\\hkcwweblogic\\account\\yd_work\\BulletinReport\\BulletinReport_111111.xls", new WriteParams(BookModelImpl.eFileExcel97));// Excel文件输出 } catch (OutOfMemoryError e) { e.printStackTrace(); } catch (F1Exception e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } public static void setCellFormat() throws F1Exception{ //生成单元格格式 mCellFormat.setLeftBorder(CellFormat.eBorderThin); mCellFormat.setRightBorder(CellFormat.eBorderThin); mCellFormat.setTopBorder(CellFormat.eBorderThin); mCellFormat.setBottomBorder(CellFormat.eBorderThin); mCellFormat.setVerticalInsideBorder(CellFormat.eBorderThin); mCellFormat.setFontName("宋体"); //左上角格式 mLeftTopCF.setFontName("宋体"); mLeftTopCF.setFontSize(200);//10号 mLeftTopCF.setFontBold(true);//粗体 mLeftTopCF.setHorizontalAlignment(CellFormat.eHorizontalAlignmentLeft);//居左 mLeftTopCF.setVerticalAlignment(CellFormat.eVerticalAlignmentCenter);//垂直居中 //输入数据的单元格的格式 mInputCF.setLeftBorder(CellFormat.eBorderThin); mInputCF.setRightBorder(CellFormat.eBorderThin); mInputCF.setTopBorder(CellFormat.eBorderThin); mInputCF.setBottomBorder(CellFormat.eBorderThin); mInputCF.setFontName("宋体"); mInputCF.setFontSize(200); mInputCF.setHorizontalAlignment(CellFormat.eHorizontalAlignmentCenter);//居中 mInputCF.setVerticalAlignment(CellFormat.eVerticalAlignmentCenter);//垂直居中 } }

  

转载于:https://www.cnblogs.com/xushuyi/articles/4520545.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值