excel导出

这篇博客详细介绍了如何使用Java进行Excel导出,涵盖了从Controller到各种工具类如ExportExcelUtil、EnumUtils、DateUtil和MoneyFormatUtil的使用,同时还探讨了Excel的代码公式和截图展示。
摘要由CSDN通过智能技术生成

摘要

查询数据库,完成对查询数据的excel导出。

一、controller

/**
	 * ebs EXCEL数据导出
	 * @param ebsChargingDetailQuery
	 * @param request
	 * @param response
	 */
	@RequestMapping(value = "/export")
	@Authorization(HrmPrivilegeConstants.EBS_MANAGE)
	public void export(@ModelAttribute(value = "ebsChargingDetailQuery") EbsChargingDetailQuery ebsChargingDetailQuery,
					   HttpServletRequest request, HttpServletResponse response) {
		try {
			Map<String, Object> context = new HashMap<>(6);
			logger.info("ebs模板导出开始");
			PaginatedList<EbsChargingDetailVo> exportList = ebsChargingDetailService.pageSearch(ebsChargingDetailQuery);
			context.put("templateName", "ebsChargingDetailExport");
			context.put("moneyFormatUtil", new MoneyFormatUtil());
			context.put("dateUtil", new DateUtil());
			context.put("enumUtils", new EnumUtils());
			context.put("payCourseMap", payCourseMap);
			context.put("exportList", exportList);
			ExportExcelUtil.exportExcel(request, response, "WEB-INF/exportTemplates/ebsChargingDetailExport.xls", "ebsChargingDetail_"+System.currentTimeMillis()+".xls", context);
			logger.info("ebs模板导出结束");
		} catch (Exception e) {
			logger.error("EbsChargingDetailController.export.Exception", e);
		}
	}

二、EbsChargingDetailVo

package com.jd.fms.proxyinvoice.project.domain;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;

import com.jd.fms.proxyinvoice.project.custenum.domainTypeEnum.PlatFlagFeeWriteOffEnum;
import com.jd.fms.proxyinvoice.project.custenum.domainTypeEnum.TransferNaturePersonEnum;

/**
 * @author  CodeRobot
 */
public class EbsChargingDetailVo implements Serializable {

	private static final long serialVersionUID = 1L;
	/**
	 * ID
	 */
	private Long id;
	/**
	 * 计费明细ID
	 */
	private Long chargingDetailId;
	/**
	 * 订单号
	 */
	private String invoiceOrderNo;
	/**
	 * ebs财务机构
	 */
	private Integer ou;
	/**
	 * 计费日期,开票完成日期
	 */
	private Date chargingDate;
	/**
	 * 商家编码 目前和平台编码一致
	 */
	private String supplierId;
	/**
	 * 商家名称
	 */
	private String supplierName;
	/**
	 * 内部公司填写相关ORG_ID;金融公司填写纳税识别号;外部主体不填
	 */
	private String orgnizationCode;
	/**
	 * 费用承担部门编码
	 */
	private String feeDeptCode;
	
	/**
	 * 费用承担部门全路径名称
	 */
	private String feeDeptAllPathName;
	
	/**
	 * 费用科目编号
	 */
	private String feeItemCode;
	/**
	 * 发票号码(单据编号)
	 */
	private String invoiceNo;
	/**
	 * 收付款方向(1:收款;-1:付款)
	 */
	private Integer direaction;
	/**
	 * 费用类型
	 */
	private Integer feetypeId;
	/**
	 * 费用名称
	 */
	private String feetypeName;
	/**
	 * 金额
	 */
	private BigDecimal amount;
	/**
	 *平台简码
	 */
	private String platformCode;
	/**
	 *平台名称
	 */
	private String platformName;
	/**
	 * 客户类别(内部,外部,金融)
	 */
	private Integer supplierType;
	/**
	 * 行业
	 */
	private String industry;
	/**
	 * 品目
	 */
	private String category;
	/**
	 * 开票完成时间
	 */
	private Date invoiceCompleteDate;
	/**
	 * 创建时间
	 */
	private Date createdDate;
	/**
	 * 最后一次更新时间
	 */
	private Date updateDate;
	/**
	 * ebs抽取标志 y 集成 n 不集成
 	 */
	private String ebsFlag;
	/**
	 * 币种
	 */
	private String currency;
	
	/**
	 * 服务费是否转嫁自然人
	 */
	private TransferNaturePersonEnum transferNaturePerson;
	
	/**
     * 是否核销
     */
    private PlatFlagFeeWriteOffEnum feeWriteOff;
    

	public String getCurrency() {
		return currency;
	}

	public void setCurrency(String currency) {
		this.currency = currency;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Long getChargingDetailId() {
		return chargingDetailId;
	}

	public void setChargingDetailId(Long chargingDetailId) {
		this.chargingDetailId = chargingDetailId;
	}

	public String getInvoiceOrderNo() {
		return invoiceOrderNo;
	}

	public void setInvoiceOrderNo(String invoiceOrderNo) {
		this.invoiceOrderNo = invoiceOrderNo;
	}

	public Integer getOu() {
		return ou;
	}

	public void setOu(Integer ou) {
		this.ou = ou;
	}

	public Date getChargingDate() {
		return chargingDate;
	}

	public void setChargingDate(Date chargingDate) {
		this.chargingDate = chargingDate;
	}

	public String getSupplierId() {
		return supplierId;
	}

	public void setSupplierId(String supplierId) {
		this.supplierId = supplierId;
	}

	public String getSupplierName() {
		return supplierName;
	}

	public void setSupplierName(String supplierName) {
		this.supplierName = supplierName;
	}

	public String getOrgnizationCode() {
		return orgnizationCode;
	}

	public void setOrgnizationCode(String orgnizationCode) {
		this.orgnizationCode = orgnizationCode;
	}

	public String getFeeDeptCode() {
		return feeDeptCode;
	}

	public void setFeeDeptCode(String feeDeptCode) {
		this.feeDeptCode = feeDeptCode;
	}

	public String getFeeDeptAllPathName() {
		return feeDeptAllPathName;
	}

	public void setFeeDeptAllPathName(String feeDeptAllPathName) {
		this.feeDeptAllPathName = feeDeptAllPathName;
	}

	public String getFeeItemCode() {
		return feeItemCode;
	}

	public void setFeeItemCode(String feeItemCode) {
		this.feeItemCode = feeItemCode;
	}

	public String getInvoiceNo() {
		return invoiceNo;
	}

	public void setInvoiceNo(String invoiceNo) {
		this.invoiceNo = invoiceNo;
	}

	public Integer getDireaction() {
		return direaction;
	}

	public void setDireaction(Integer direaction) {
		this.direaction = direaction;
	}

	public Integer getFeetypeId() {
		return feetypeId;
	}

	public void setFeetypeId(Integer feetypeId) {
		this.feetypeId = feetypeId;
	}

	public String getFeetypeName() {
		return feetypeName;
	}

	public void setFeetypeName(String feetypeName) {
		this.feetypeName = feetypeName;
	}

	public BigDecimal getAmount() {
		return amount;
	}

	public void setAmount(BigDecimal amount) {
		this.amount = amount;
	}

	public String getPlatformCode() {
		return platformCode;
	}

	public void setPlatformCode(String platformCode) {
		this.platformCode = platformCode;
	}

	public String getPlatformName() {
		return platformName;
	}

	public void setPlatformName(String platformName) {
		this.platformName = platformName;
	}

	public Integer getSupplierType() {
		return supplierType;
	}

	public void setSupplierType(Integer supplierType) {
		this.supplierType = supplierType;
	}

	public String getIndustry() {
		return industry;
	}

	public void setIndustry(String industry) {
		this.industry = industry;
	}

	public String getCategory() {
		return category;
	}

	public void setCategory(String category) {
		this.category = category;
	}

	public Date getInvoiceCompleteDate() {
		return invoiceCompleteDate;
	}

	public void setInvoiceCompleteDate(Date invoiceCompleteDate) {
		this.invoiceCompleteDate = invoiceCompleteDate;
	}

	public Date getCreatedDate() {
		return createdDate;
	}

	public void setCreatedDate(Date createdDate) {
		this.createdDate = createdDate;
	}

	public Date getUpdateDate() {
		return updateDate;
	}

	public void setUpdateDate(Date updateDate) {
		this.updateDate = updateDate;
	}

	public String getEbsFlag() {
		return ebsFlag;
	}

	public void setEbsFlag(String ebsFlag) {
		this.ebsFlag = ebsFlag;
	}

	public TransferNaturePersonEnum getTransferNaturePerson() {
		return transferNaturePerson;
	}

	public void setTransferNaturePerson(TransferNaturePersonEnum transferNaturePerson) {
		this.transferNaturePerson = transferNaturePerson;
	}

	public PlatFlagFeeWriteOffEnum getFeeWriteOff() {
		return feeWriteOff;
	}

	public void setFeeWriteOff(PlatFlagFeeWriteOffEnum feeWriteOff) {
		this.feeWriteOff = feeWriteOff;
	}

}

三、ExportExcelUtil

package com.jd.fms.proxyinvoice.common.util;

import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.poi.hssf.usermodel.HSSFWorkbook;

import net.sf.jxls.transformer.XLSTransformer;

public class ExportExcelUtil {

	public static String exportExcel(HttpServletRequest request, HttpServletResponse response, String templateFilePath,
			String outputName, Map beans) {
		InputStream is = null;
		OutputStream os = null;
		try {
			response.setContentType("application/vnd.ms-excel");
			outputName = new String(outputName.getBytes("gbk"), "iso8859-1");
			response.setHeader("Content-Disposition", "attachment; filename=" + outputName);
			XLSTransformer transformer = new XLSTransformer();
			is = new BufferedInputStream(new FileInputStream(request.getSession().getServletContext()
					.getRealPath(templateFilePath)));
			HSSFWorkbook workbook = (HSSFWorkbook) transformer.transformXLS(is, beans);
			os = response.getOutputStream();
			workbook.write(os);
		} catch (Exception e) {
			throw new RuntimeException("exportExcel error", e);
		} finally {
			if (is != null)
				try {
					is.close();
				} catch (IOException e) {
					throw new RuntimeException("exportExcel 关闭inputStream error", e);
				}
			if (os != null)
				try {
					os.close();
				} catch (IOException e) {
					throw new RuntimeException("exportExcel 关闭outputStream error", e);
				}
		}
		return null;
	}
}

四、EnumUtils

package com.jd.fms.proxyinvoice.project.util;


import com.jd.fms.proxyinvoice.project.custenum.domainTypeEnum.*;

/**
 * @author by chenguanxu.
 * @description
 * @data 2018/9/13 18:39
 */
public class EnumUtils {

    /**
     * 纸票开票状态
     */
    public static String getPaperInvoiceApplyStatus(Integer status) {
        PaperInvoiceApplyStatusEnum[] s = PaperInvoiceApplyStatusEnum.values();
        for (PaperInvoiceApplyStatusEnum se : s) {
            if (se.getValue().equals(status)) {
                return se.getText();
            }
        }
        return null;
    }
    /**
     * 客户类别
     */
    public static String getCustomerType(Integer status) {
        CustomerTypeEnum[] s = CustomerTypeEnum.values();
        for (CustomerTypeEnum se : s) {
            if (se.getValue().equals(status)) {
                return se.getText();
            }
        }
        return null;
    }
    /**
     * 对接方式
     */
    public static String getPlatformConnectWay(Integer status) {
        PlatformConnectWayEnum[] s = PlatformConnectWayEnum.values();
        for (PlatformConnectWayEnum se : s) {
            if (se.getValue().equals(status)) {
                return se.getText();
            }
        }
        return null;
    }
    /**
     * 电票是否生成
     */
    public static String getPdfFlag(Integer status) {
        PdfFlagEnum[] s = PdfFlagEnum.values();
        for (PdfFlagEnum se : s) {
            if (se.getCode().equals(status)) {
                return se.getDescription();
            }
        }
        return null;
    }

    /**
     * 纸质是否首次开票
     */
    public static String getFirstInvoice(Integer value){
        FirstInvoiceEnum[] s = FirstInvoiceEnum.values();
        for (FirstInvoiceEnum se : s) {
            if (se.value().equals(value)) {
                return se.getMsg();
            }
        }
        return null;
    }

    /**
     * 首付款方向
     */
    public static String getPaymentDirection(Integer status) {
        PaymentDirectionEnum[] s = PaymentDirectionEnum.values();
        for (PaymentDirectionEnum se : s) {
            if (se.getValue().equals(status)) {
                return se.getText();
            }
        }
        return null;
    }
    /**
     * 是否转嫁自然人
     */
    public static String getOu(Integer status) {
        OuEnum[] s = OuEnum.values();
        for (OuEnum se : s) {
            if (se.value().equals(status)) {
                return se.getText();
            }
        }
        return null;
    }
}

五、DateUtil

package com.jd.fms.proxyinvoice.common.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.TimeZone;


/**
 * 
 * 日期处理类
 * 
 * @author yaolizong
 *
 */
public class DateUtil {

	public static final String FORMATTEXT01 = "yyyy-MM-dd";

	public static final String FORMATTEXT02 = "yyyy-MM-dd HH:mm:ss";

	public static final String FORMATTEXT03 = "yyyyMMddHHmmss";

	public static final String FORMATTEXT04 = "yyyyMMdd";

	public static final String FORMATTEXT05 = "yyyyMMdd_HHmmss";
	
	public static final String FORMATTEXT06 = "yyyy-MM";
	
	public static final String FORMATTEXT07 = "yyyy_MM_dd";
	
	public static final String FORMATTEXT08 = "yyyy";

	public static final String FORMATTEXT09 = "MM";
	
	public static final String FORMATTEXT10 = "dd";
	
	public static final String FORMATTEXT11 = "yyyyMMddHHmmssSSS";
	
	public static final String FORMATTEXT12 = "yyyy-MM-dd HH:mm:ss.SSS";
	
    public static final String FORMATTEXT13 = "yyyy/MM/dd";
	
    public static final String FORMATTEXT14 = "yyyyMM";
    
    public static final String FORMATTEXT15 = "yyyyMMdd";
    
    public static final String FORMATTEXT16 = "MM/dd/yyyy";
    
    public static final String FORMATTEXT17 = "yyyy-MM-dd HH:mm";
    
    public static final String FORMATTEXT18 = "yyyy-M";
    
	/**
	 * 判断某个日期是星期几
	 * 
	 * @param Date
	 * @return int
	 */
	public static final int getWeek(Date date) {

		Calendar c = Calendar.getInstance();

		c.setTime(date);

		int week = c.get(Calendar.DAY_OF_WEEK) - 1;

		if (week == 0) {
			return week = 7;
		} else {
			return week;
		}
	}
	
	
	/**
	 * @param 根据给定的日期格式格式化日期
	 * @return String
	 */
	public static final String formatDate(long time, String formatText) {
		
		SimpleDateFormat format = new SimpleDateFormat(formatText);

		String result = format.format(new Date(time));

		return result;
	}

	/**
	 * 将日期对象转换成指定格式的字符串
	 * 
	 * @param date
	 *            日期对象
	 * @param formatText
	 *            日期格式
	 * @return 日期格式的字符串
	 */
	public static final String formatDate(Date date, String formatText) {

		if (CheckUtil.isNull(date) || CheckUtil.isNull(formatText)) {

			return "";
		}

		SimpleDateFormat formats = new SimpleDateFormat(formatText);

		return formats.format(date);
	}

	public static final String formatDate(String date, String formatText) {

		SimpleDateFormat formats = new SimpleDateFormat(formatText);

		return formats.format(parseDate(date, formatText));
	}
	
	
	/**
	 * 获得当前时间的年部分
	 * 
	 * @return
	 */
	public static final int getCurrentYear() {

		Calendar calendar = Calendar.getInstance();

		return calendar.get(calendar.YEAR);

	}
	
	/**
	 * 获得当前时间的月部分
	 * 
	 * @return
	 */
	public static final int getCurrentMonth() {

		Calendar calendar = Calendar.getInstance();

		return calendar.get(calendar.MONTH) +1;

	}
	
	
	/**
	 * 获得当前时间的日部分
	 * 
	 * @return
	 */
	public static final int getCurrentDay() {

		Calendar calendar = Calendar.getInstance();

		return calendar.get(calendar.DATE);

	}
	

	/**
	 * 获得当前的时间,以给定的格式输出
	 * 
	 * @param formatStr
	 * @return
	 */
	public static final String getCurrentTime(String formatText) {

		SimpleDateFormat format = new SimpleDateFormat(formatText);

		String result = format.format(new Date());

		return result;
	}

	/**
	 * 将日期由字符串格式转换成Date类型
	 * @param strDate
	 * @param format
	 * @return
	 */
	public static final Date parseDate(String strDate, String formatText) {

        SimpleDateFormat df = null;
        Date date = null;
        df = new SimpleDateFormat(formatText);

        try {
            date = df.parse(strDate);
        } catch (ParseException e) {
        	e.printStackTrace();
        }

        return (date);
    }

	/**
	 * 在给定时间基础上加减指定的月份,返回加减之后的日期
	 * @param value
	 * @return
	 */
	public static final Date addMonth(Date date, int value){
		if (CheckUtil.isNull(date)){
			date = new Date();
		}
		Calendar c = Calendar.getInstance();
		c.setTime(date);
		c.add(Calendar.MONTH, value);
		return c.getTime();
	}
	
	/**
	 * 获取给定时间的年
	 * @param date
	 * @return
	 */
	public static final int getDateYear(Date date){
		Calendar c = Calendar.getInstance();
		c.setTime(date);
		return c.get(Calendar.YEAR);
	}
	
	/**
	 * 获取给定时间的月份
	 * @param date
	 * @return
	 */
	public static final int getDateMonth(Date date){
		Calendar c = Calendar.getInstance();
		c.setTime(date);
		return c.get(Calendar.MONTH)+1;
	}
	
	/**
	 * 在给定时间基础上加减指定的日期,返回加减之后的日期
	 * @param value
	 * @return
	 */
	public static final Date addDay(Date date, int value){
		if (CheckUtil.isNull(date)){
			return null;
		}
		Calendar c = Calendar.getInstance();
		c.setTime(date);
		c.add(Calendar.DAY_OF_MONTH, value);
		return c.getTime();
	}
	
	
	/**
	 * 获取指定日期所在月的第一天日期
	 * @return
	 */
	public static final Date getFirstDayOfMonth(Date date){
		if (CheckUtil.isNull(date)){
			return null;
		}
		Calendar c = Calendar.getInstance();
		c.setTime(date);
		c.set(Calendar.DATE,1);
		c.set(Calendar.HOUR_OF_DAY, 0);
		c.set(Calendar.MINUTE, 0);
		c.set(Calendar.SECOND, 0);
		return c.getTime();
	}
	/**
	 * 获取指定两个年份的区间年份
	 * @param date
	 * @return
	 */
	public static final List<Integer> getIntervalYear(int startYear, int endYear){
		if (CheckUtil.isNull(startYear) || CheckUtil.isNull(endYear)){
			return null;
		}
		if(startYear > endYear){
			return null;
		}
		List<Integer> intervalYear = new ArrayList<Integer>();
		int interval = endYear - startYear;
		for(int i = 0; i <= interval; i++){
			intervalYear.add(startYear+i);
		}
		return intervalYear;
	}
	
	/**
	 * 获取美国东部标准时间
	 * @param formatText
	 * @return
	 */
	public static String getESTTime(String formatText){
		TimeZone tz = TimeZone.getTimeZone("EST");
		Calendar calendar = Calendar.getInstance();
		SimpleDateFormat sdf = new SimpleDateFormat(formatText);
		sdf.setTimeZone(tz);
		return sdf.format(calendar.getTime());
	}
	
	
	public static final Date getMonthEnd(String date, String formatText) {
		SimpleDateFormat dateFormat = new SimpleDateFormat(formatText);
		Calendar calendar = Calendar.getInstance();
		try{
			calendar.setTime(dateFormat.parse(date));
		} catch (Exception e){
			e.printStackTrace();
		}
		calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
		return calendar.getTime();
	}
	
	public static final Date getMonthStart(String date, String formatText) {
		SimpleDateFormat dateFormat = new SimpleDateFormat(formatText);
		Calendar calendar = Calendar.getInstance();
		try{
			calendar.setTime(dateFormat.parse(date));
		} catch (Exception e){
			e.printStackTrace();
		}
		calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMinimum(Calendar.DAY_OF_MONTH));
		return calendar.getTime();
	}
	
	public static void main(String[] args) throws ParseException {
		Calendar calendar = Calendar.getInstance();
		System.out.println(formatDate(getMonthEnd("2016-10", FORMATTEXT06), FORMATTEXT01));
		System.out.println(getDateYear(new Date()));
		System.out.println(getDateMonth(new Date()));
		System.out.println(formatDate(addMonth(new Date(), -9), FORMATTEXT06));
		calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMinimum(Calendar.DAY_OF_MONTH));
		Date date = calendar.getTime();
		System.out.println();
		System.out.println(DateUtil.formatDate(DateUtil.addMonth(new Date(), +2), "yyyy-M"));
	}

}

六、MoneyFormatUtil

package com.jd.fms.proxyinvoice.common.util;

import java.math.BigDecimal;

public class MoneyFormatUtil {
	private final static String [] PATTERN ={"零","壹","贰","叁","肆","伍","陆","柒","捌","玖"};  
	private final static String [] C_PATTERN ={"","拾","佰","仟","万","拾","佰","仟","亿"};  
	private final static String [] CF_PATTERN = {"","角","分"};  
	private final static String ZEOR = "零";  
	
	/**
	 * 阿拉伯转化为汉字
	 * @param moneyString
	 * @return
	 */
	public static String toCn(String moneyString) {
		int dotPoint = moneyString.indexOf("."); // 判断是否为小数
		String moneyStr;
		if (dotPoint != -1) {
			moneyStr = moneyString.substring(0, moneyString.indexOf("."));
		} else {
			moneyStr = moneyString;
		}
		StringBuffer fraction = null; // 小数部分的处理,以及最后的yuan.
		StringBuffer ms = new StringBuffer();
		for (int i = 0; i < moneyStr.length(); i++) {
			ms.append(PATTERN[moneyStr.charAt(i) - 48]); // 按数组的编号加入对应大写汉字
		}

		int cpCursor = 1;
		for (int j = moneyStr.length() - 1; j > 0; j--) {
			ms.insert(j, C_PATTERN[cpCursor]); // 在j之后加字符,不影响j对原字符串的相对位置
			// 只是moneyStr.length()不断增加
			// insert(j,"string")就在j位置处插入,j=0时为第一位
			cpCursor = cpCursor == 8 ? 1 : cpCursor + 1; // 亿位之后重新循环
		}

		while (ms.indexOf("零拾") != -1) { // 当十位为零时用一个"零"代替"零拾"
			// replace的起始于终止位置
			ms.replace(ms.indexOf("零拾"), ms.indexOf("零拾") + 2, ZEOR);
		}
		while (ms.indexOf("零佰") != -1) { // 当百位为零时,同理
			ms.replace(ms.indexOf("零佰"), ms.indexOf("零佰") + 2, ZEOR);
		}
		while (ms.indexOf("零仟") != -1) { // 同理
			ms.replace(ms.indexOf("零仟"), ms.indexOf("零仟") + 2, ZEOR);
		}
		while (ms.indexOf("零万") != -1) { // 万需保留,中文习惯
			ms.replace(ms.indexOf("零万"), ms.indexOf("零万") + 2, "万");
		}
		while (ms.indexOf("零亿") != -1) { // 同上
			ms.replace(ms.indexOf("零亿"), ms.indexOf("零亿") + 2, "亿");
		}
		while (ms.indexOf("零零") != -1) {// 有连续数位出现零,即有以下情况,此时根据习惯保留一个零即可
			ms.replace(ms.indexOf("零零"), ms.indexOf("零零") + 2, ZEOR);
		}
		while (ms.indexOf("亿万") != -1) { // 特殊情况,如:100000000,根据习惯保留高位
			ms.replace(ms.indexOf("亿万"), ms.indexOf("亿万") + 2, "亿");
		}
		while (ms.lastIndexOf("零") == ms.length() - 1) { // 当结尾为零j,不必显示,经过处理也只可能出现一个零
			ms.delete(ms.lastIndexOf("零"), ms.lastIndexOf("零") + 1);
		}

		int end;
		if ((dotPoint = moneyString.indexOf(".")) != -1) { // 是小数的进入
			String fs = moneyString.substring(dotPoint + 1,
					moneyString.length());
			if (fs.indexOf("00") == -1 || fs.indexOf("00") >= 2) {// 若前两位小数全为零,则跳过操作
				end = fs.length() > 2 ? 2 : fs.length(); // 仅保留两位小数
				fraction = new StringBuffer(fs.substring(0, end));
				for (int j = 0; j < fraction.length(); j++) {
					fraction.replace(j, j + 1,
							PATTERN[fraction.charAt(j) - 48]); // 替换大写汉字
				}
				for (int i = fraction.length(); i > 0; i--) { // 插入中文标识
					fraction.insert(i, CF_PATTERN[i]);
				}
				fraction.insert(0, "元"); // 为整数部分添加标识
			} else {
				fraction = new StringBuffer("元整");
			}

		} else {
			fraction = new StringBuffer("元整");
		}

		ms.append(fraction); // 加入小数部分
		return ms.toString();
	}
	
	// 页面格式化金额工具
	public static String fromatDecimal(String value) {
		if (CheckUtil.isNull(value)) {
			return "";
		} else if (value.equals("-")) {
			return value;
		}
		return Arith.thousandCharacterformat(
				new BigDecimal(value).doubleValue(), 2);
	}
	
	public static String formatDecimal(double value) {
		return Arith.thousandCharacterformat(value, 2);
	}

	// 页面格式化金额工具
	public static String fromatDecimal(BigDecimal value) {
		if (null == value) {
			return "";
		}
		return Arith.thousandCharacterformat(value.doubleValue(), 2);
	}
	
	// 页面格式化金额工具
	public static String fromatDecimalNoScale(BigDecimal value) {
		if (null == value) {
			return "";
		}
		return String.valueOf(value.longValue());
	}
	
	/**
	 * 去掉千分号以及空格
	 * @param value
	 * @return
	 */
	public static String money2String(String value) {
		if (null == value || "".equals(value.trim())) {
			return null;
		} else {
			return value.replace(" ", "").replace(",", "");
		}
	}
	
	/**
	 * 小数转百分比
	 * @param v
	 * @return
	 */
	public static String formartPercent(BigDecimal v)
	{
		return  Arith.thousandCharacterformat(v.multiply(new BigDecimal(100)), 1) + "%";
	}
	
	public static void main(String[] args) {
		System.out.println(fromatDecimal(new BigDecimal("10000000.4567")));
	}
}

七、excel代码公式

订单号	财务机构	商家名称	费用承担部门编码	费用承担部门名称	费用科目编码	费用科目名称	发票号码	费用名称	服务费是否转嫁自然人	服务费是否内部核销	税费是否内部核销	收付款方向	金额	平台简码	平台名称	客户类型	开票日期
<jx:forEach items="${exportList}" var="line">																	
${line.invoiceOrderNo}	${enumUtils.getOu(line.ou)}	${line.supplierName}	${line.feeDeptCode}	${line.feeDeptAllPathName}	${line.feeItemCode}	${payCourseMap.get(line.feeItemCode)}	${line.invoiceNo}	${line.feetypeName}	${line.transferNaturePerson}	${line.fwfWriteOff}	${line.taxWriteOff}	${enumUtils.getPaymentDirection(line.direaction)}	${line.amount}	${line.platformCode}	${line.platformName}	${enumUtils.getCustomerType(line.supplierType)}	${dateUtil.formatDate(line.invoiceCompleteDate, dateUtil.FORMATTEXT01)}
</jx:forEach>																	

八、excel截图

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值