导出excel代码

 

import java.io.File;

import java.io.IOException;

 

import jxl.Workbook;

import jxl.WorkbookSettings;

import jxl.format.Border;

import jxl.format.BorderLineStyle;

import jxl.format.Colour;

import jxl.write.Label;

import jxl.write.WritableCellFormat;

import jxl.write.WritableFont;

import jxl.write.WritableSheet;

import jxl.write.WritableWorkbook;

import jxl.write.WriteException;

import jxl.write.biff.RowsExceededException;

 

import com.bstek.common.log.Logger;

import com.bstek.common.log.LoggerFactory;

 

/**

 * 分析日志

 * @author fengbin

 *

 */

public class SplitLog {

 

private static Logger logger = LoggerFactory.getInstance().getLogger(SplitLog.class);

 

public static void main(String[] args) throws RowsExceededException, WriteException, IOException {

 

SplitLog l = new SplitLog();

l.splitLoanLog();

}

 

 

public void splitLoanLog() throws IOException, RowsExceededException, WriteException{

 

//保存到excel中

WritableWorkbook book = null;

WorkbookSettings wbSetting = new WorkbookSettings();

wbSetting.setUseTemporaryFileDuringWrite(true);

wbSetting.setTemporaryFileDuringWriteDirectory(new File("C:\\temp\\"));// 临时文件夹的位置

book = Workbook.createWorkbook(new File("C:\\temp\\loan_log.xls"), wbSetting);

 

int sheetNum =0;

WritableSheet curSheet = book.createSheet("导出金融数据", sheetNum);

int col=0;

int row=0;

curSheet.setColumnView(col, 15);

curSheet.addCell(new Label(col, row, "公司",getHead()));

 

curSheet.addCell(new Label(col, row+1, "0001"));

 

book.write();  

book.close();

 

}

 

/**

* 设置头样式

* @return

*/

private static WritableCellFormat getHead() {

WritableFont font = new WritableFont(WritableFont.COURIER, 11, WritableFont.BOLD);

try {

font.setColour(Colour.BLUE);

} catch (Exception e) {

logger.error(e, "设置头样式失败!");

}

WritableCellFormat format = new WritableCellFormat(font);

try {

format.setAlignment(jxl.format.Alignment.CENTRE);// 左右居中

format.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE);// 上下居中

format.setBorder(Border.ALL, BorderLineStyle.THIN, Colour.BLACK);// 黑色边框

//format.setBackground(Colour.YELLOW);// 黄色背景

return format;

} catch (Exception e) {

logger.error(e, "设置头样式失败!");

}

return format;

}

 

}

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值