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;
}
}