struts2框架的报表打印谁会做?

[复制链接]
查看11 | 回复4 | 2011-10-31 04:36:18 | 显示全部楼层 |阅读模式
回复

使用道具 举报

千问 | 2011-10-31 04:36:18 | 显示全部楼层
在IE下面导出吗?这个需要在你项目的更目录放一个,Excel文件!赞同
回复

使用道具 举报

千问 | 2011-10-31 04:36:18 | 显示全部楼层
packagecom.ss.util.excel;importjava.lang.annotation.Documented;importjava.lang.annotation.ElementType;importjava.lang.annotation.Retention;importjava.lang.annotation.RetentionPolicy;importjava.lang.annotation.Target;/***Excel实体BEAN的属性注解*@authorMrGao*2010-7-12下午05:10:37*/@Documented@Retention(RetentionPolicy.RUNTIME)@Target(ElementType.FIELD)public@interfaceExcelAnnotation{Stringname();//Excel列名intwidth();//Excel列宽intid();//Excel列ID}packagecom.ss.util.excel;importjava.lang.reflect.Field;importjava.util.Comparator;@SuppressWarnings(\"unchecked\")publicclassFieldComparatorimplementsComparator{publicintcompare(Objectarg0,Objectarg1){FieldfieldOne=(Field)arg0;FieldfieldTwo=(Field)arg1;ExcelAnnotationannoOne=fieldOne.getAnnotation(ExcelAnnotation.class);ExcelAnnotationannoTwo=fieldTwo.getAnnotation(ExcelAnnotation.class);returnannoOne.id()-annoTwo.id();}}packagecom.ss.util.excel;importjava.awt.Color;importjava.io.FileNotFoundException;importjava.io.FileOutputStream;importjava.io.IOException;importjava.io.OutputStream;importjava.lang.reflect.Field;importjava.lang.reflect.InvocationTargetException;importjava.lang.reflect.Method;importjava.util.Arrays;importjava.util.List;importjxl.Workbook;importjxl.format.Alignment;importjxl.format.Border;importjxl.format.BorderLineStyle;importjxl.format.Colour;importjxl.format.Pattern;importjxl.format.RGB;importjxl.format.UnderlineStyle;importjxl.format.VerticalAlignment;importjxl.write.Label;importjxl.write.WritableCellFormat;importjxl.write.WritableFont;importjxl.write.WritableSheet;importjxl.write.WritableWorkbook;importjxl.write.WriteException;/***导出Excel文件**@authorMrGao2010-7-13下午02:19:51*/publicclassExcelExport{/***生成Excel**@parammodels*封装需要到处的数据BEAN结合*@paramclassName*导成Excel的实体BEAN包名.类名*@paramtempPath*生成Excel存放的临时路径*@paramexcelName*生成的Excel名*/@SuppressWarnings(\"unchecked\")publicstaticvoidcreateExcel(Listmodels,StringclassName,StringtempPath,StringexcelName){ClassclasVo=null;try{clasVo=Class.forName(className);OutputStreamos=newFileOutputStream(tempPath\"\\\\\"excelName\".xls\");WritableWorkbookworkbook=Workbook.createWorkbook(os);WritableSheetsheet=workbook.createSheet(excelName,0);//用于标题WritableFonttitleFont=newWritableFont(WritableFont.ARIAL,17,WritableFont.BOLD,false,UnderlineStyle.NO_UNDERLINE,jxl.format.Colour.WHITE);WritableCellFormatwcf_title=newWritableCellFormat(titleFont);wcf_title.setBackground(Colour.TEAL,Pattern.SOLID);wcf_title.setBorder(Border.ALL,BorderLineStyle.DOUBLE,Colour.OCEAN_BLUE);wcf_title.setVerticalAlignment(VerticalAlignment.CENTRE);//垂直对齐wcf_title.setAlignment(Alignment.CENTRE);//用于正文WritableFontNormalFont=newWritableFont(WritableFont.TAHOMA,11);WritableCellFormatwcf_center=newWritableCellFormat(NormalFont);wcf_center.setBorder(Border.ALL,BorderLineStyle.DOUBLE,Colour.GRAY_25);wcf_center.setVerticalAlignment(VerticalAlignment.CENTRE);//垂直对齐wcf_center.setAlignment(Alignment.CENTRE);wcf_center.setWrap(true);//是否换行sheet.addCell(newLabel(0,0,excelName,wcf_title));sheet.mergeCells(0,0,clasVo.getDeclaredFields().length-1,0);//获取属性Field[]fields=clasVo.getDeclaredFields();//按照注解id排序Excel列Arrays.sort(fields,newFieldComparator());for(inti=0;ifields.length;i){Fieldfield=fields;if(field.isAnnotationPresent(ExcelAnnotation.class)){//获取该字段的注解对象ExcelAnnotationanno=field.getAnnotation(ExcelAnnotation.class);sheet.setColumnView(i,anno.width());sheet.addCell(newLabel(i,1,anno.name(),wcf_center));}}introwId=2;//写入第几行第一行为列头数据从第二行开始写for(ObjectssTopModel:models){intcolumnId=0;//写入第几列第一列为自动计算的行号数据从第二列开始写//获取该类并获取自身方法Classclazz=ssTopModel.getClass();for(inti=0;ifields.length;i){Fieldfield=fields;if(field.isAnnotationPresent(ExcelAnnotation.class)){StringmethodName=\"get\"field.getName().substring(0,1).toUpperCase()field.getName().substring(1);Methodmethod=clazz.getMethod(methodName);try{sheet.addCell(newLabel(columnId,rowId,method.invoke(ssTopModel)==null?\"\":method.invoke(ssTopModel).toString(),wcf_center));}catch(IllegalArgumentExceptione){e.printStackTrace();}catch(IllegalAccessExceptione){e.printStackTrace();}catch(InvocationTargetExceptione){e.printStackTrace();}columnId;}}rowId;}workbook.write();workbook.close();os.flush();os.close();}catch(WriteExceptione){e.printStackTrace();}catch(FileNotFoundExceptione){e.printStackTrace();}catch(IOExceptione){e.printStackTrace();}catch(ClassNotFoundExceptione){e.printStackTrace();}catch(SecurityExceptione){e.printStackTrace();}catch(NoSuchMethodExceptione){e.printStackTrace();}}}追问你这个是导出吧?打印呢?
回复

使用道具 举报

千问 | 2011-10-31 04:36:18 | 显示全部楼层
您所说的打印是什么意思?直接用打印机打印吗?
回复

使用道具 举报

千问 | 2011-10-31 04:36:18 | 显示全部楼层
打印直接js调用window.print()赞同
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行