SVN记录转excel文件的小程序
用于将SVN记录转成excel文件的小程序,程序包见附件。下载地址:http://download.csdn.net/detail/setsail_wu/5144664
使用方法如下:
1、 将压缩包里的文件解压至linux服务器任意目录下。
2、 在该目录下执行 ./svnlog2excel.shSVNPATH如
3、 即会在当前目录下生成一excel文件,文件名与SVN路径有关,如下:
源码如下
SvnLog.java,用于保存每条记录的信息。
package com.tony;import java.io.File;import java.io.FileInputStream;import java.io.IOException;import java.io.InputStream;import java.util.List;import javax.xml.parsers.SAXParser;import javax.xml.parsers.SAXParserFactory;import jxl.Workbook;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;public class toExcel {public static List<SvnLog> getSvnLogs(String filename) throws Exception {InputStream inStream = new FileInputStream(new File(filename)); SAXParserFactory spf = SAXParserFactory.newInstance(); // 初始化sax解析器 SAXParser sp = spf.newSAXParser(); // 创建sax解析器 svnlogXMLHandler handler = new svnlogXMLHandler(); sp.parse(inStream, handler); return handler.getSvnLogs(); } /** * @param args */ public static void main(String[] args) { if(args.length != 2) { System.out.println("Please input src file(***.xml) and target file(***.xls)"); System.out.println("ex: java -jar svnlog2excel.jar changlog.xml test2.xls"); return; } String targetFile = args[1]; String srcFile = args[0]; File file = new File(targetFile); Label label; try { List<SvnLog> svnlogs = getSvnLogs(srcFile); WritableWorkbook workbook = Workbook.createWorkbook(file); WritableSheet sheet = workbook.createSheet("test1", 0); WritableFont wtf = new WritableFont(WritableFont.createFont("宋体"),14,WritableFont.BOLD,false); WritableCellFormat wcfmt = new WritableCellFormat(wtf); wcfmt.setAlignment(jxl.format.Alignment.CENTRE); int c= 0; sheet.setColumnView(c, 14); label = new Label(c++, 0, svnlogXMLHandler.REVISION, wcfmt); sheet.addCell(label); sheet.setColumnView(c, 14); label = new Label(c++, 0, svnlogXMLHandler.AUTHOR, wcfmt); sheet.addCell(label); sheet.setColumnView(c, 11); label = new Label(c++, 0, svnlogXMLHandler.DATE, wcfmt); sheet.addCell(label); sheet.setColumnView(c, 40); label = new Label(c++, 0, svnlogXMLHandler.MSG, wcfmt); sheet.addCell(label); sheet.setColumnView(c, 100); label = new Label(c++, 0, svnlogXMLHandler.PATHS, wcfmt); sheet.addCell(label); WritableFont wtf2 = new WritableFont(WritableFont.createFont("Arial"),10,WritableFont.NO_BOLD,false); WritableCellFormat wcfmt2 = new WritableCellFormat(wtf2); wcfmt2.setVerticalAlignment(jxl.format.VerticalAlignment.TOP); WritableCellFormat wcfmt3 = new WritableCellFormat(wtf2); wcfmt3.setVerticalAlignment(jxl.format.VerticalAlignment.TOP); wcfmt3.setAlignment(jxl.format.Alignment.CENTRE); for (int i=0; i<svnlogs.size(); i++){ int j = 0; label = new Label(j++, i+1, svnlogs.get(i).getRevision(), wcfmt3); sheet.addCell(label); label = new Label(j++, i+1, svnlogs.get(i).getAuthor(), wcfmt2); sheet.addCell(label); label = new Label(j++, i+1, svnlogs.get(i).getDate(), wcfmt2); sheet.addCell(label); label = new Label(j++, i+1, svnlogs.get(i).getMsg(), wcfmt2); sheet.addCell(label); label = new Label(j++, i+1, svnlogs.get(i).getPaths(), wcfmt2); sheet.addCell(label); } workbook.write(); workbook.close(); } catch (IOException e) { e.printStackTrace(); } catch (RowsExceededException e) { e.printStackTrace(); } catch (WriteException e) { e.printStackTrace(); } catch (Exception e) {// TODO Auto-generated catch blocke.printStackTrace();} }}
- 1楼setsail_wu前天 15:47
- 下载地址:http://download.csdn.net/detail/setsail_wu/5144664