RCP项目_poi下载Excel

poi所用的包:
poi-3.8-20120326.jar
poi-examples-3.8-20120326.jar
poi-excelant-3.8-20120326.jar
poi-ooxml-3.8-20120326.jar
poi-ooxml-schemas-3.8-20120326.jar
poi-scratchpad-3.8-20120326.jar
xmlbeans-2.3.0.jar
xwork-core-2.2.1.1.jar
注意:要在plugin.xml文件的Runtime中的ClassPath加入包,没有加载会访问不到
/**
 * 存储sheet的数据
 * @author suhuafu
 *
 */
public class PaperDataVO {
	  public PaperDataVO() {
	  }

	  public PaperDataVO(String workbookName, List<String[]> list) {
	    this.workbookName = workbookName;
	    this.list = list;
	  }

	  private String workbookName="default";//工作表名称
	  private List<String[]> list = new ArrayList<String[]>();//动态值队

	  public String getWorkbookName() {
	    return workbookName;
	  }


 

 

@Override
	public void widgetSelected(SelectionEvent e) {
		int count = table.getColumnCount();
	  	TableItem[] items =  table.getItems();
	  	final List<String[]> list = new ArrayList<String[]>();
	  	String[] str = null; 
	  	for (int i = 0; i < items.length; i++) {
	  		str = new String[count];
	  		for (int j = 0; j < count; j++) {
				str[j] = items[i].getText(j);
			}
	  		list.add(str);
		}
	  	//创建文件夹对话框
		DirectoryDialog  direcory = new DirectoryDialog(getSite().getShell());
		direcory.open();
		final String path = direcory.getFilterPath();
		
		//打开处理窗口
		ProgressMonitorDialog pmd = new ProgressMonitorDialog(getSite().getShell());  
		//创建进度条对象
		IRunnableWithProgress rwp = new IRunnableWithProgress() {
			  @Override  
			    public void run(IProgressMonitor monitor){  
			          //totalWork为IProgressMonitor.UNKNOWN时表示不知道任务的总量   
			          //将在进度条上显示一个来回移动的进度条   
				   monitor.beginTask("正在下载..." , IProgressMonitor.UNKNOWN); 
			          //TODO 相应的业务逻辑  
				  	monitor.subTask("读取数据...");
				  	if(path != ""){
						List<PaperDataVO> pdvs = new ArrayList<PaperDataVO>();
					  	PaperDataVO paper = new PaperDataVO();
					  	paper.setWorkbookName("报销单");
					  	paper.setList(list);
					  	pdvs.add(paper);
					  
					  	OutputStream tempOut = null;
						InputStream in = null;
						try {
							//获取插件,获取文件的相对路径
							in = Platform.getBundle("com.welldell.rcp.render.db")
						  			.getEntry("fileTemplate/renderMain.xlsx").openStream();
							//生成文件路径
							String src = path+"\\报销单"+ 
						  			DateFormatUtil.formatDateToString(new Date(System.currentTimeMillis()), DateFormatUtil.V_LONG_YMD) +".xlsx";
							tempOut = new FileOutputStream(src);
							WriteExcelUtil.buildExcel(in, tempOut, pdvs);
						} catch (FileNotFoundException e1) {
							// TODO Auto-generated catch block
							e1.printStackTrace();
						} catch (IOException ioe) {
							// TODO Auto-generated catch block
							ioe.printStackTrace();
						}
					  	
					}
				  	monitor.subTask("处理完成!");
			        monitor.done();  
			       }
		};  
		try {
			pmd.run(true, false, rwp);
		} catch (Exception e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}  

		
	}
});


 

public static void buildExcel(InputStream ins, OutputStream os, List<PaperDataVO> pdvs) {
		if (pdvs == null || pdvs.size() == 0) {
			return;
		}
		try {
			Sheet sheet = null;
			Row row = null;//行
			Cell cell = null;//单元格
			Workbook wb = new XSSFWorkbook(ins);
			int sheetNum = wb.getActiveSheetIndex();//模板sheet的数量
			for (int i = 0; i < pdvs.size(); i++) {
				PaperDataVO pdv =  pdvs.get(i);
				if(sheetNum < i){
					sheet = wb.getSheetAt(wb.getActiveSheetIndex());//获取激活中的sheet
				}else{
					sheet = wb.getSheetAt(i);
					if(sheet == null)
						sheet = wb.createSheet(pdv.getWorkbookName()+i);
				}
				List<String[]> list = pdv.getList();
				int rowNum = list.size()+1;
				int cellNum = sheet.getRow(0).getPhysicalNumberOfCells();
				for (int j = 1; j < rowNum ; j++) {//循环行
					row = sheet.createRow(j);
					for (int k = 0; k < cellNum; k++) {//循环行的列
						cell = row.createCell(k);
						cell.setCellValue(list.get(j-1)[k]);
					}
				}
			}
			wb.write(os);
			os.flush();
			os.close();
		} catch (Exception ex) {
			ex.printStackTrace();
		}

	}


 

Use of NWAI-WG data   So far, NWAI-WG data have been used on a collaborative basis in publications (see the attached file). The major reasons are the data were not widely distributed. They were only used in our group and our collaborative networks. There were some cases with requests of the data made after people read Liu and Zou's (2012) paper. You have two options for using the data. Option 1: Collaboration with us. In this case, we will help you to describe the downscaling method and contribute to other parts of the paper such as comments/suggestions on the papers, if the fields are within our expertise. Option 2: Use of the data on your own. While option 1 for collaboration with us is welcome, option 2 is also highly encouraged, particularly, when the data are used for these research disciplines, rather than agricultural related. Thanks to Professor Yu who provides us with his group's web site (www.agrivy.com) as a media for distribution of the data.   Acknowledgment for option 1  “We acknowledge the modelling groups, the Program for Climate Model Diagnosis and Intercomparison (PCMDI) and the WCRP’s Working Group on Coupled Modelling (WGCM) for their roles in making available the WCRP CMIP5 multi-model dataset. Support of this dataset is provided by the Office of Science, US Department of Energy. Dr. Ian Macadam of the University of New South Wales downloaded the raw GCM monthly data. ”   Acknowledgment for option 2  “We acknowledge the modelling groups, the Program for Climate Model Diagnosis and Intercomparison (PCMDI) and the WCRP’s Working Group on Coupled Modelling (WGCM) for their roles in making available the WCRP CMIP5 multi-model dataset. Support of this dataset is provided by the Office of Science, US Department of Energy. Dr. Ian Macadam of the University of New South Wales downloaded the raw GCM monthly data. Dr. De Li Liu of the NSW Department of Primary Industries used NWAI-WG to downscale downscaled daily data. Also, thanks to AGRIVY (www.agrivy.com) provides us the data for this study.”
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值