现在这篇文章,讲的是如何使用前一篇文章导出通用工具类

    具体如下:

    ackage com.xuahua.utils.export;
    
    import java.text.SimpleDateFormat;
    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.List;
    import java.util.Map;
    
    import jxl.CellView;
    import jxl.write.Label;
    import jxl.write.Number;
    
    import com.xuahua.pojo.TMemCashTradeRecordVo;
    import com.xuahua.utils.ExportExcelUtils;
    
    public class TradeExportUtils extends ExportExcelUtils {
    	
    	@Override
    	public List<Map<String, Object>> getHeaders() {
    		List<Map<String, Object>> headers = new ArrayList<Map<String, Object>>();
    
    		Map<String, Object> header = new HashMap<String, Object>();
    		header.put("value", "序");
    		headers.add(header);
    
    		header = new HashMap<String, Object>();
    		header.put("value", "用户名");
    		headers.add(header);
    
    		header = new HashMap<String, Object>();
    		header.put("value", "交易号");
    		headers.add(header);
    
    		header = new HashMap<String, Object>();
    		header.put("value", "交易前余额");
    		headers.add(header);
    
    		header = new HashMap<String, Object>();
    		header.put("value", "交易金额");
    		headers.add(header);
    
    		header = new HashMap<String, Object>();
    		header.put("value", "交易后余额");
    		headers.add(header);
    
    		header = new HashMap<String, Object>();
    		header.put("value", "交易类型");
    		headers.add(header);
    
    		header = new HashMap<String, Object>();
    		header.put("value", "收入支出");
    		headers.add(header);
    		
    		header = new HashMap<String, Object>();
    		header.put("value", "交易支出");
    		headers.add(header);
    		
    		header = new HashMap<String, Object>();
    		header.put("value", "订单号");
    		headers.add(header);
    		
    		header = new HashMap<String, Object>();
    		header.put("value", "摘要");
    		headers.add(header);
    		return headers;
    	}
    
    	@Override
    	public void writeContent(List list) throws Exception{
    		List<TMemCashTradeRecordVo> currencyCardList = list;
    		CellView cellView = new CellView();  
    	    cellView.setAutosize(true); //设置自动大小
    		for (int i = 0; i < currencyCardList.size(); i++) {
    			TMemCashTradeRecordVo vo = currencyCardList.get(i);
    
    			number = new jxl.write.Number(0, rowIndex, (i + 1), cellFormat1);
    			ws.addCell(number);
    			
    			label = new jxl.write.Label(1, rowIndex, vo.getUsername(),cellFormat1); // 用户名
    			ws.addCell(label);
    
    			label = new jxl.write.Label(2, rowIndex, vo.getTradeno(),cellFormat1); // 交易流水号
    			ws.addCell(label);
    			
    			number = new Number(3, rowIndex, vo.getAccountcashmoney().add(vo.getAccountfrzoenmoney()).doubleValue(),cellFormat1); // 交易前金额
    			ws.addCell(number);
    			
    			number = new Number(4, rowIndex, vo.getTradetotalmoney().doubleValue(),cellFormat1); // 交易金额
    			ws.addCell(number);
    			
    			number = new Number(5, rowIndex, vo.getCashmoney().add(vo.getFrzoenmoney()).doubleValue(),cellFormat1); // 交易后金额
    			ws.addCell(number);
    			
    			label = new jxl.write.Label(6, rowIndex,vo.getTradetype(), cellFormat1); // 交易类型
    			ws.addCell(label);
    			
    			label = new jxl.write.Label(7, rowIndex,vo.getInorout(), cellFormat1); // 收入支出类型
    			ws.addCell(label);
    
    			label = new Label(8, rowIndex, new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(vo.getCreatetime()),cellFormat1);
    			ws.addCell(label);
    			
    			label = new Label(9, rowIndex, vo.getGeneralno(),cellFormat1); // 订单号
    			ws.addCell(label);
    
    			label = new Label(10, rowIndex, vo.getRemark(),cellFormat1); // 备注
    			
    			ws.setColumnView(i, cellView);
    			ws.addCell(label);
    
    			rowIndex++;
    		}
    
    	}
    	
    }

    看了上面的代码以后,怎么样?会使用了么?

    联系QQ:343886028 --加QQ群 145315854