public class Excel {
static String xml_path="";
static String[] days;
static String server="";
//读取配置文件信息
static{
InputStream is=Excel.class.getResourceAsStream("config.properties");
Properties p=new Properties();
try {
p.load(is);
xml_path=p.getProperty("xml_path").trim();
server=p.getProperty("server").trim();
if(!xml_path.endsWith("/"))xml_path=xml_path+"/";
days=p.getProperty("day").trim().split(",");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
* @param args
* @throws DocumentException
* @throws IOException
*/
public static void main(String[] args) throws IOException, DocumentException {
for (String day : days){
createExcel(day);
System.out.println("----------"+day.replace('-', '.')+"---------");
}
}
public static List paraXml(String day) throws IOException, DocumentException{
SAXReader reader = new SAXReader();
InputStream inputStream = new FileInputStream(new File(day+".xml"));
Document doc = reader.read(inputStream);
Element root = doc.getRootElement();
List _list = root.elements("time");
return _list;
}
public static void createExcel(String day){
System.out.println("开始");
try{
//打开文件
WritableWorkbook book=Workbook.createWorkbook(new File("vod+电视回看应用服务器数据监控表("+day.replace('-', '.')+"."+server+")"+".xls"));
WritableSheet sheet=book.createSheet("第一页",0);
//设置字体
WritableFont NormalFont = new WritableFont(WritableFont.createFont("宋体"), 12,WritableFont.BOLD,false,UnderlineStyle.NO_UNDERLINE,Colour.WHITE);
WritableFont BoldFont = new WritableFont(WritableFont.createFont("宋体"), 20 ,WritableFont.BOLD);
WritableFont tableFont = new WritableFont(WritableFont.createFont("宋体"), 11 , WritableFont.NO_BOLD);
WritableFont baodanFont = new WritableFont(WritableFont.ARIAL, 10 , WritableFont.BOLD);
//设置标题
WritableCellFormat wcf_title = new WritableCellFormat(BoldFont);
wcf_title.setBorder(Border.ALL, BorderLineStyle.THIN); // 线条
wcf_title.setVerticalAlignment(VerticalAlignment.CENTRE); // 垂直对齐
wcf_title.setAlignment(Alignment.CENTRE); // 水平对齐
wcf_title.setWrap( true ); // 是否换行
sheet.mergeCells(0, 0, 8, 0); //合并第一行的8列
Label label=new Label(0,0,"VOD+电视回看应用服务器数据监控表("+day.replace('-', '.')+"."+server+")",wcf_title);
sheet.addCell(label);
//设置行高
sheet.setRowView( 0 , 900 , false );
for(int i=0;i<=8;i++){
if(i==2||i==6||i==8){
sheet.setColumnView(i, 21); //设置列宽
}else if(i==5||i==7){
sheet.setColumnView(i, 19);
}else{
sheet.setColumnView(i, 17);
}
}
for(int i=1;i<=25;i++){
sheet.setRowView( i , 500 , false );
}
//设置正文
WritableCellFormat wcf = new WritableCellFormat(NormalFont);
wcf.setBorder(Border.ALL, BorderLineStyle.THIN);
wcf.setVerticalAlignment(VerticalAlignment.CENTRE);
wcf.setAlignment(Alignment.LEFT);
wcf.setBackground(Colour.GREEN);
wcf.setWrap( true );
//将定义好的单元格添加到工作表中
/*生成一个保存数字的单元格
必须使用Number的完整包路径,否则有语法歧义
单元格位置是第二列,第一行,值为789.123*/
//jxl.write.Number number=new jxl.write.Number(1,1,123);
//sheet.addCell(number);
//Label(colum,row,string,style);
Label label0=new Label(0,1,"时间/监控项",wcf);
Label label1=new Label(1,1,"毫秒级并发数",wcf);
Label label2=new Label(2,1,"服务器在线用户数",wcf);
Label label3=new Label(3,1,"服务器访问量",wcf);
Label label4=new Label(4,1,"服务器连接数",wcf);
Label label5=new Label(5,1,"最大并发用户数",wcf);
Label label6=new Label(6,1,"最大并发用户时间",wcf);
Label label7=new Label(7,1,"最大并发连接数",wcf);
Label label8=new Label(8,1,"最大并发连接时间",wcf);
sheet.addCell(label0);
sheet.addCell(label1);
sheet.addCell(label2);
sheet.addCell(label3);
sheet.addCell(label4);
sheet.addCell(label5);
sheet.addCell(label6);
sheet.addCell(label7);
sheet.addCell(label8);
WritableCellFormat wcf_time = new WritableCellFormat(tableFont);
wcf_time.setBorder(Border.ALL, BorderLineStyle.THIN);
wcf_time.setVerticalAlignment(VerticalAlignment.CENTRE);
wcf_time.setAlignment(Alignment.RIGHT);
wcf_time.setWrap( true );
//将xml里的数据放到excel里
for (int i = 0; i <paraXml(day).size(); i++) {
Element _item = (Element) paraXml(day).get(i);
String time=_item.attributeValue("value");
String millse_count = _item.element("millse_count").attributeValue("value");
String server_users = _item.element("server_users").attributeValue("value");
String server_visitors = _item.element("server_visitors").attributeValue("value");
String server_connctors = _item.element("server_connctors").attributeValue("value");
String max_users = _item.element("max_users").attributeValue("value");
String max_users_time = _item.element("max_users").attributeValue("time");
String max_connectors = _item.element("max_connectors").attributeValue("value");
String max_connectors_time = _item.element("max_connectors").attributeValue("time");
Label ltime=new Label(0,i+2,time,wcf_time);
jxl.write.Number lmillse_count=new jxl.write.Number(1,i+2,Integer.parseInt(millse_count),wcf_time);
jxl.write.Number lserver_users=new jxl.write.Number(2,i+2,Integer.parseInt(server_users),wcf_time);
jxl.write.Number lserver_visitors=new jxl.write.Number(3,i+2,Integer.parseInt(server_visitors),wcf_time);
jxl.write.Number lserver_connctors=new jxl.write.Number(4,i+2,Integer.parseInt(server_connctors),wcf_time);
jxl.write.Number lmax_users=new jxl.write.Number(5,i+2,Integer.parseInt(max_users),wcf_time);
Label lmax_users_time=new Label(6,i+2,max_users_time,wcf_time);
jxl.write.Number lmax_connectors=new jxl.write.Number(7,i+2,Integer.parseInt(max_connectors),wcf_time);
Label lmax_connectors_time=new Label(8,i+2,max_connectors_time,wcf_time);
sheet.addCell(ltime);
sheet.addCell(lmillse_count);
sheet.addCell(lserver_users);
sheet.addCell(lserver_visitors);
sheet.addCell(lserver_connctors);
sheet.addCell(lmax_users);
sheet.addCell(lmax_users_time);
sheet.addCell(lmax_connectors);
sheet.addCell(lmax_connectors_time);
System.out.println("------"+time+"-----------:"+millse_count);
}
Label lt=new Label(0,25,"总计:",wcf_time);
sheet.addCell(lt);
for(int i=1;i<=8;i++){
Label ll=new Label(i,25,"",wcf_time);
sheet.addCell(ll);
}
//写入数据并关闭文件
book.write();
book.close();
}catch(Exception e){
System.out.println(e);
}
System.out.println("结束");
}
}
config.properties配置文件里:
day=2012-03-01
path=F:/log
xml_path=F:
server=204
分享到:
相关推荐
利用java,将excel数据转换为xml测试用例,转换后可将xml文件直接导入Testlink 1.9.3; 内含xml所有jar包,省去搜索相关jar麻烦,lib文件内含dom4j-1.6.1.jar jdom.jar org.apache.poi.jar jxl.jar; 源代码可扩展,...
一种基于XML的Excel向SVG图转换的解决方案,周运杰,杨俊,本文给出了一种以XML为中间文档格式的Excel电子表格向SVG图转换的解决方案。并采用基于Java的技术,利用开源工具包JXL, Batik等实现了这��
该代码支持奖excel(excel2003,.xls)用例转换为testlink用例文件xml。具体模板类型参照附件excel模板。用户需要自行使用eclipse导入工程与外部jxl.jar。祝使用愉快
自己做的使用jxl读Excel文件中的数据到内存 并根据xml配置验证规则和代码转换规则进行数据的验证以及转换 并可以自己扩展验证方法 如 字段是否为空 ; 男 女转换为 1 和2 等代码 压缩包中包括 打好的jar文件 一个...
基于jxl.jar解析Excel xls文件自动化生成android多语言strings.xml
通过iText不仅可以生成PDF或rtf的文档,而且可以将XML、Html文件转化为PDF文件。 iTextAsian.jar itext中关于亚洲编码的类库,在这里用于中文字体的输入。 junit.jar Junit包,当你运行Hibernate自带的测试...
poi.jar:Apache的操作数据转换的类库,能导入和到处Excel,与jxl.jar功能重复。 mysql-connector-java-5.1.6-bin.jar mysql驱动包 ojdbc5.jar jdbc驱动包 iTextAsian.jar 中文显示问题 jdt-compiler-3.1.1....
什么是BEW? 生物膜实验工作台(BEW)是用于操作和分析生物膜实验数据的新型软件... 用于读取和写入Excel工作表的JXL库 。 用于处理HTML文档的JSoup库 。 这些第三方支持主要数据处理和数据分析操作,同时支持将来的适
Struts 2需要的jar包: 1.commons-fileupload.jar(commons项目中的关于文件上传的包, struts...excel表格:jxl.jar 操作pdf文件:iText-5.0.5.jar 统计图(JFreechart两个):jcommon-1.0.10.jar,jfreechart-1.0.6.jar