国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

如何使用Java 實現(xiàn)excel模板導出---多sheet導出?

這篇具有很好參考價值的文章主要介紹了如何使用Java 實現(xiàn)excel模板導出---多sheet導出?。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

實現(xiàn)多個sheet的excel導出功能

效果展示:
如何使用Java 實現(xiàn)excel模板導出---多sheet導出?,項目,入門案例,知識點,java,spring boot

maven依賴

<dependency>
			<groupId>org.apache.poi</groupId>
			<artifactId>poi</artifactId>
			<version>3.17</version>
		</dependency>
		<dependency>
			<groupId>org.apache.poi</groupId>
			<artifactId>poi-ooxml</artifactId>
			<version>3.17</version>
		</dependency>

相關(guān)工具類
**此處省略異常處理類

ExcelReportUtil 類


import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;

import java.math.BigDecimal;
import java.util.*;

/**
 * 
* @ClassName: ExcelReportUtil 
* @Description: excel導出工具類 
* @version v1.0
 */
public class ExcelReportUtil {
	
	private static Log logger = LogFactory.getLog(ExcelReportUtil.class);
	
	/**
	 * clone the height, cells and cellRangeAddress to destRow from srcRow
	 * @param sheet
	 * @param srcRow
	 * @param destRow
	 */
	public static void cloneRow(Sheet sheet, Row srcRow, Row destRow) {
		if (sheet == null || srcRow == null || destRow == null)
			return;
		Set mergedRegions = new HashSet();
		destRow.setHeight(srcRow.getHeight());
		if (srcRow.getFirstCellNum() >= 0 && srcRow.getLastCellNum() >= 0) {
            for (int i = srcRow.getFirstCellNum(), j = srcRow.getLastCellNum(); i <= j; i++) {
				Cell srcCell = srcRow.getCell(i);
				Cell destCell = destRow.getCell(i);
                if (srcCell != null) {
                	logger.debug("cell is found at col[" + i + 
                			"], will be cloned to the destRow");
                    if (destCell == null) {
                        destCell = destRow.createCell(i);
                    }
                    cloneCell(srcCell, destCell);
                    CellRangeAddress mergedRegion = getMergedRegion(sheet, srcRow.getRowNum(),
                    		srcCell.getColumnIndex());
                    if (mergedRegion != null) {
                    	CellRangeAddress newMergedRegion = new CellRangeAddress(
                    			destRow.getRowNum(), 
                    			destRow.getRowNum() + mergedRegion.getLastRow() - mergedRegion.getFirstRow(), 
                    			mergedRegion.getFirstColumn(), 
                    			mergedRegion.getLastColumn());
                        if (isNewMergedRegion(newMergedRegion, mergedRegions)) {
                        	logger.debug("CellRangeAddress is found at col[" + i + 
                        			"], will be cloned to the destRow");
                            mergedRegions.add(newMergedRegion);
                            sheet.addMergedRegion(newMergedRegion);
                        }
                    }
                }
            }
		}
	}
	
	/**
	 * get the CellRangeAddress of sheet at [rowNum, colNum] if exists
	 * @param sheet
	 * @param rowNum
	 * @param colNum
	 * @return null if not exists
	 */
	public static CellRangeAddress getMergedRegion(Sheet sheet, int rowNum, int colNum) {
        for (int i = 0, c = sheet.getNumMergedRegions(); i < c; i++) {
            CellRangeAddress merged = sheet.getMergedRegion(i);
            if (isRangeContainsCell(merged, rowNum, colNum)) {
                return merged;
            }
        }
        return null;
    }
	
	/**
	 * to judge whether the CellRangeAddress includes the cell at [row, col]
	 * @param range
	 * @param row
	 * @param col
	 * @return 
	 * 	true if the CellRangeAddress includes the cell at [row, col]
	 */
    public static boolean isRangeContainsCell(CellRangeAddress range, int row, int col) {
        if ((range.getFirstRow() <= row) && (range.getLastRow() >= row)
                && (range.getFirstColumn() <= col)
                && (range.getLastColumn() >= col)) {
            return true;
        }
        return false;
    }
    
    /**
     * to judge if the CellRangeAddress is not included in mergedRegions,
     * using {@link #areRegionsEqual(CellRangeAddress, CellRangeAddress)} to compare
     * @param region
     * @param mergedRegions
     * @return 
     * 	true if the CellRangeAddress is not included in mergedRegions
     */
    private static boolean isNewMergedRegion(CellRangeAddress region,
            Collection mergedRegions) {
        for (Iterator iterator = mergedRegions.iterator(); iterator.hasNext();) {
            CellRangeAddress cellRangeAddress = (CellRangeAddress) iterator.next();
            if (areRegionsEqual(cellRangeAddress, region)) {
                return false;
            }
        }
        return true;
    }
    
    /**
     * compares region1 with region2
     * @param region1
     * @param region2
     * @return 
     * 	true if both of them are null or 
     * 	their firstColumn, lastColumn, firstRow and lastRow are all the same
     */
    public static boolean areRegionsEqual(CellRangeAddress region1,
            CellRangeAddress region2) {
        if ((region1 == null && region2 != null)
                || (region1 != null && region2 == null)) {
            return false;
        }
        if (region1 == null) {
            return true;
        }
        return (region1.getFirstColumn() == region2.getFirstColumn()
                && region1.getLastColumn() == region2.getLastColumn()
                && region1.getFirstRow() == region2.getFirstRow() 
                && region2.getLastRow() == region2.getLastRow());
    }
    
    /**
     * clone the style and value to destCell from srcCell
     * @param srcCell
     * @param destCell
     */
    public static void cloneCell(Cell srcCell, Cell destCell) {
		if (srcCell == null || destCell == null)
			return;
		destCell.setCellStyle(srcCell.getCellStyle());
		switch (srcCell.getCellTypeEnum()) {
			case NUMERIC :
				destCell.setCellValue(srcCell.getNumericCellValue());
				break;
			case STRING :
				destCell.setCellValue(srcCell.getRichStringCellValue());
				break;
			case FORMULA :
				destCell.setCellFormula(srcCell.getCellFormula());
				break;
			case ERROR:
				destCell.setCellErrorValue(srcCell.getErrorCellValue());
				break;
			case BOOLEAN:
				destCell.setCellValue(srcCell.getBooleanCellValue());
				break;
			default :
				destCell.setCellType(CellType.BLANK);
				break;
		}
	}
    
    /**
     * Set a value for the cell.
     * Value whose type is {@link Calendar}, {@link Date}, {@link Number}, {@link String}
     * is supported directly, otherwise will be processed as string.
     * @param cell
     * @param value
     */
    public static void setCellValue(Cell cell, Object value) {
    	if (cell == null)
    		return;
    	if (value == null) {
    		cell.setCellType(CellType.BLANK);
    	} else if (value instanceof Calendar) {
    		cell.setCellValue((Calendar) value);
    	//Date格式化日期輸出
		} else if (value instanceof Date) {
			//cell.setCellValue((Date) value);
			//cell.setCellValue(BaseUtils.Date2String((Date)value, CommonConstants.FORMAT_Date));
			cell.setCellValue(BaseUtils.Date2String((Date)value, "yyyy-MM-dd HH:mm:ss"));
		} else if (value instanceof Number) {
			setCellValue(cell, (Number) value);
		} else if (value instanceof String) {
			cell.setCellValue((String) value);
		} else {
			logger.warn("value type [" + value.getClass().getName() + 
					"] is not directly supported, will be processed as String");
			cell.setCellValue((String) value.toString());
		}
    }
	
    /**
     * set a number value for the cell
     * @param cell
     * @param value
     * @throws XLSReportException
     * 	if the Number can not be unwrapped
     */
	private static void setCellValue(Cell cell, Number value) {
		double doubleContent = 0.0;
		if (value instanceof Byte) {
			doubleContent = (Byte) value;
		} else if (value instanceof Double) {
			doubleContent = (Double) value;
		} else if (value instanceof Float) {
			doubleContent = (Float) value;
		//BigDecimal轉(zhuǎn)換為Double
		}else if (value instanceof BigDecimal) {
			doubleContent = TypeCaseHelper.convert2Double(value);
		} else if (value instanceof Integer) {
			float tmp = (Integer) value;
			doubleContent = tmp;
		} else if (value instanceof Long) {
			float tmp = (Long) value;
			doubleContent = tmp;
		} else if (value instanceof Short) {
			short tmp = (Short) value;
			doubleContent = tmp;
		} else {
			throw new XLSReportException("value type [" + value.getClass().getName() + 
					"] can not be processed as double");
		}
		cell.setCellValue(doubleContent);
	}
	
	/**
	 * get the string value of a cell
	 * @param cell
	 * @return "" if type of the cell is not in 
	 * 	{CELL_TYPE_NUMERIC, CELL_TYPE_STRING and CELL_TYPE_BOOLEAN}
	 * @see Cell#CELL_TYPE_BLANK
     * @see Cell#CELL_TYPE_NUMERIC
     * @see Cell#CELL_TYPE_STRING
     * @see Cell#CELL_TYPE_FORMULA
     * @see Cell#CELL_TYPE_BOOLEAN
     * @see Cell#CELL_TYPE_ERROR
	 */
	public static String getCellStringValue(Cell cell) {
		String cellStringValue = null;
		switch (cell.getCellTypeEnum()) {
			case NUMERIC:
				cellStringValue = cell.getNumericCellValue() + "";
				break;
			case STRING:
				cellStringValue = cell.getStringCellValue();
				break;
			case BOOLEAN:
				cellStringValue = cell.getBooleanCellValue() + "";
				break;
			default :
				logger.warn("can not get the string value of a cell whose type is " + cell.getCellTypeEnum());
				cellStringValue = "";
				break;
		}
		return cellStringValue;
	}
	
	/**
	 * remove a comment from sheet
	 * @param sheet
	 * @param comment
	 */
	public static void removeComment(Sheet sheet, Comment comment) {
		if (sheet != null && comment != null) {
			sheet.getRow(comment.getRow())
				.getCell(comment.getColumn())
				.removeCellComment();
		}
	}
	
}

excel 接口


import org.apache.poi.ss.usermodel.Sheet;
import java.util.Map;

/**
 * 
* @ClassName: ExcelProcessor 
* @Description: 自定義的excel接口
* @author huali
* @version v1.0
 */
public interface ExcelProcessor{
	
	/**
	 * initialize the CommentProcessor
	 */
	void init();
	

	boolean isInited();
	
	/**
	 * 
	* @Title: process 
	* @Description: fill the XLS sheet by data 
	* @param @param sheet
	* @param @param dataSource
	* @return void
	 */
	void process(Sheet sheet, Map dataSource);
}

實現(xiàn)類

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.ibatis.ognl.Ognl;
import org.apache.ibatis.ognl.OgnlException;
import org.apache.poi.ss.usermodel.*;

import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

/**
 * Implementation of {@link ExcelProcessor},
 * it fills a list in the XLS horizontally.
 * Besides 'type', 'expression', 'firstIndex' and 'dataMapping' are added to finish that,
 * 1) expression, mandatory, a OGNL expression, is used to get the list from XLS data
 * 2) firstIndex, mandatory, the beginning row index of filling list
 * 3) dataMapping, mandatory, a Map<Integer, String> value,
 * 		whose key is the cell column index and value is a OGNL expression to
 * 		get the cell value from list element.
 * In filling, the list element is transfered by {@link ExcelDataSource},
 * and the index of element is put in the transfered data as key 'index'.
 * A typical configuration is like this,
 * { type : 'I', expression : 'students', dataMapping : { 1 : 'index', 2 : 'name'...} }
 *
 */
public class ExcelIteratorNoLastRowProcessor implements ExcelProcessor {
//填充類型
	public static String TYPE_ID = "I";

	private static Log logger = LogFactory.getLog(ExcelIteratorNoLastRowProcessor.class);

	private boolean inited;
//批注
	private final Comment comment;
//填充數(shù)據(jù)的名稱
	private String expression;
//從第幾行開始填充
	private int firstIndex;
//填充的數(shù)據(jù)
	private Map<Integer, String> dataMapping;

	public ExcelIteratorNoLastRowProcessor(Comment comment) {
		this.comment = comment;
	}

	public String getExpression() {
		return expression;
	}

	public void setExpression(String expression) {
		this.expression = expression;
	}

	public int getFirstIndex() {
		return firstIndex;
	}

	public void setFirstIndex(int firstIndex) {
		this.firstIndex = firstIndex;
	}

	public Map<Integer, String> getDataMapping() {
		return dataMapping;
	}

	public void setDataMapping(Map<Integer, String> dataMapping) {
		this.dataMapping = dataMapping;
	}

	@Override
	public void init() {
		try {
			Map<String, Object> classMap = new HashMap<String, Object>();
			classMap.put("dataMapping", Map.class);
			Map<String, Object> cfg = JSON.parseObject(this.comment.getString().toString(),Map.class);
			Object expresionCfg = cfg.get("expression");
			Object firstIndexCfg = cfg.get("firstIndex");
			Object dataMappingCfg = cfg.get("dataMapping");
			if (expresionCfg == null || !(expresionCfg instanceof String)) {
				throw new XLSReportCfgException("expresion must be configured and its type must be String");
			}
			this.expression = (String) expresionCfg;
			if (firstIndexCfg == null || !(firstIndexCfg instanceof Integer)) {
				throw new XLSReportCfgException("firstIndex must be configured and its type must be Integer");
			}
			this.firstIndex = (Integer) firstIndexCfg;
			if (dataMappingCfg == null || !(dataMappingCfg instanceof Map)) {
				throw new XLSReportCfgException("dataMapping must be configured and its type must be Map");
			}
			this.dataMapping = (Map<Integer, String>) dataMappingCfg;
			this.inited = true;
		} catch (JSONException e) {
			throw new XLSReportCfgException("the comment configuration at [" +
					comment.getRow() + "," + comment.getColumn() + "] " + comment.getString().toString() +
					" is error", e);
		}
	}

	@Override
	public boolean isInited() {
		return this.inited;
	}

	@Override
	public void process(Sheet sheet, Map dataSource) {
		try {
			if (!isInited())
				throw new XLSReportException("the CommentProcessor has not inited yet");
				//從dataSource中找到填充目標名稱
			Object content = Ognl.getValue(this.expression, dataSource);
			if (content == null) {
				content = Collections.EMPTY_LIST;
			}
			if (!(content instanceof Iterable)) {
				content = Arrays.asList(content);
			}
			int index = 0;
			boolean isAddRow = false;
			for (Object element : (Iterable) content) {
				//clone row
				logger.debug("clone the row at index[" + (this.firstIndex + index + 1) + "] to the new row at index[" + (this.firstIndex + index) + "]");
				ExcelReportUtil.cloneRow(sheet, sheet.getRow(this.firstIndex + index + 1), sheet.createRow(this.firstIndex + index));
				//獲取填充行
				Row aimedRow = sheet.getRow(this.firstIndex + index);
				//fill data
				for (Integer key : this.dataMapping.keySet()) {
					int cellIndex = key;
					//獲取第一行的數(shù)據(jù)
					Map rowDS = new ExcelDataSource(element).getData();
					rowDS.put("index", index);
					Cell aimedCell = aimedRow.getCell(cellIndex);
					if (aimedCell == null)
						aimedCell = aimedRow.createCell(cellIndex);
						//找到列對應的數(shù)據(jù)
					Object value = Ognl.getValue(this.dataMapping.get(key), rowDS);
					//樣式
					if(Boolean.parseBoolean(rowDS.get("isBolded") == null ? "":rowDS.get("isBolded").toString())){
						Workbook workbook = sheet.getWorkbook();
						CellStyle cellStyle = workbook.createCellStyle();
						Font font = workbook.createFont();
						//font.setBoldweight(Font.BOLDWEIGHT_BOLD);
						font.setBold(true);
						cellStyle.setFont(font);
						aimedCell.setCellStyle(cellStyle);
					}
					logger.debug("set the value of cell[" + (this.firstIndex + index) + ", " + cellIndex + "] to " + value);
					//給列填值
					ExcelReportUtil.setCellValue(aimedCell, value);
				}
				index++;
			}
			//remove comment
			ExcelReportUtil.removeComment(sheet, this.comment);
		} catch (OgnlException e) {
			throw new XLSReportException("extracting data error while using OGNL expression[" +
					this.expression + "] with root object : " + dataSource);
		}
	}
}

excel填充數(shù)據(jù)處理類


import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.beans.BeanInfo;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

/**
 * Implementation of XLSReportDataSource, which is constructed by a original bean.
 * The original bean will be processed as following,
 * 1. Collections.emptyMap() if it is null
 * 2. used directly if its type is Map
 * 3. otherwise it will be transformed to Map, {@link #transformPropertiesToMap(Object)}
 */
public class ExcelDataSource  {
	
	private static Log logger = LogFactory.getLog(ExcelDataSource.class);
	
	/**
	 * the original bean 
	 */
	private Object dataSource;
	
	public ExcelDataSource(Object dataSource) {
		this.dataSource = dataSource;
	}
	
	public Map getData() {
		Map ds = null;
		if (this.dataSource == null) {
			ds = Collections.emptyMap();
		} else if (this.dataSource instanceof Map) {
			ds = (Map) this.dataSource;
		} else {
			logger.debug("the type of dataSource is [" + dataSource.getClass() + 
					"], will be transformed to Map");
			ds = transformPropertiesToMap(this.dataSource);
		}
		return ds;
	}
	
	/**
	 * Used locally to transform a bean to Map.
	 * The property names are transformed to the keys,
	 * theirs values are transformed to the value of the corresponding key.
	 * Besides, the property named 'class' is excluded.
	 * @param bean
	 * @return
	 */
	private Map transformPropertiesToMap(Object bean) {
		Map properties = new HashMap();
		BeanInfo beanInfo;
		try {
			beanInfo = Introspector.getBeanInfo(bean.getClass());
			PropertyDescriptor[] pds = beanInfo.getPropertyDescriptors();
			for (PropertyDescriptor pd : pds) {
				if (!"class".equals(pd.getName())) {
					properties.put(pd.getName(), pd.getReadMethod().invoke(bean));
				}
			}
		} catch (Exception e) {
			throw new XLSReportException(e);
		}
		return properties;
	}

}

excel填充處理類

import com.alibaba.fastjson.JSON;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.poi.ss.usermodel.*;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 
* @ClassName: ExcelReportFiller 
* @Description: 讀取模板數(shù)據(jù)處理
* @version v1.0
 */
public class ExcelReportFiller {
	
	private static final Log logger = LogFactory.getLog(ExcelReportFiller.class);
	
	public void fill(Workbook template, Map dataSource) {
		int sheetCount = template.getNumberOfSheets();
		for (int i = 0; i < sheetCount; i++) {
			logger.debug("scan the sheet at index[" + i + "]");
			fillSheet(template.getSheetAt(i), dataSource);
		}
	}
	
	public void fillSheetName(String sheetName, Workbook template,
			Map dataSource) {
		logger.debug("scan the sheet at [" + sheetName + "]");
		fillSheet(template.getSheet(sheetName), dataSource);
	}
	
	/**
	 * fill the XLS sheet by data
	 * @param sheet 模板template
	 * @param dataSource
	 */
	private void fillSheet(Sheet sheet, Map dataSource) {
		int rowCount = sheet.getLastRowNum();
		for (int i = 0; i <= rowCount; i++) {
			Row row = sheet.getRow(i);
			if (row != null) {
				int cellCount = row.getLastCellNum();
				for (int j = 0; j <= cellCount; j++) {
					Cell cell = row.getCell(j);
					if (cell != null ) {
						Comment comment = cell.getCellComment();
						if (comment != null) {
							logger.debug("comment is found at [" + i + ", " + j + "]");
							ExcelProcessor processor = ExcelProcessorFactory.getCommentProcessor(comment);
							processor.process(sheet, dataSource);
							//refresh rowCount
							rowCount = sheet.getLastRowNum();
						}
					}
				}
			}
		}
	}
}

excel模板處理


import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;

import javax.servlet.http.HttpServletRequest;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

/**
 * 
* @ClassName: ExcelReportTemplate 
* @Description: 通過模板創(chuàng)建流
* @version v1.0
 */
public class ExcelReportTemplate  {
	
	private static final Log logger = LogFactory.getLog(ExcelReportTemplate.class);
	
	private final String path;

	private ClassLoader classLoader;
	
	/**
	 * 
	 * @param path
	 */
	public ExcelReportTemplate(String path) {
		this(path, (ClassLoader) null);
	}
	
	/**
	 * 
	 * @param path
	 * @param classLoader
	 */
	public ExcelReportTemplate(String path, ClassLoader classLoader) {
		if (path == null) {
			throw new IllegalArgumentException("Path must not be null");
		}
		this.path = path;
		if (classLoader == null) {
			try {
				classLoader = Thread.currentThread().getContextClassLoader();
			} catch (Throwable ex) {
				logger.debug("Cannot access thread context ClassLoader - falling back to system class loader", ex);
				classLoader = ExcelReportTemplate.class.getClassLoader();
			}
		}
		this.classLoader = classLoader;
	}
	
	
	public Workbook getTemplate() throws IOException, InvalidFormatException {
		InputStream is =new FileInputStream(this.path);
		if (is == null) {
			throw new FileNotFoundException(
					"class path resource [" + this.path + "] cannot be opened because it does not exist");
		}
		//return new HSSFWorkbook(is);
		Workbook workbook = WorkbookFactory.create(is);
		if(is != null){
			is.close();
		}
		return workbook;
	}
	

	public Workbook getTemplate(HttpServletRequest resquest) throws IOException, InvalidFormatException {
		InputStream is = this.classLoader.getResourceAsStream(this.path);
		if (is == null) {
			throw new FileNotFoundException(
					"class path resource [" + this.path + "] cannot be opened because it does not exist");
		}
		Workbook workbook = WorkbookFactory.create(is);
		if(is != null){
			is.close();
		}
		return workbook;
	}

}

實現(xiàn)關(guān)鍵代碼展示
通過模板實現(xiàn)導出功能

 try {
            os = new FileOutputStream(excelPth);
            ExcelReportCreator.createXLS(new ExcelReportTemplate(excelTempletPath),
                    new ExcelDataSource(jsonMap),
                    new ExcelReportFiller(),
                    os);
            excelFilePathName = ftpPath + fileModel.getRealFileName();
        } catch (Exception e) {
            log.error("導出excel文件出錯" + " excel文件路徑=" + excelPth + " 模板路徑=" + excelTempletPath, e);
            log.error("excel內(nèi)容 " + jsonMap);
            throw e;
        } finally {
            if (os != null) {
                os.close();
            }
        }

ExcelReportCreator 中的代碼

	
	/**
	 * 
	 * @param dataSource
	 * @param filler
	 * @param os
	 * @throws IOException
	 * @throws InvalidFormatException
	 */
	public static void createXLS(ExcelReportTemplate template,
			ExcelDataSource dataSource, ExcelReportFiller filler,
			OutputStream os) throws IOException, InvalidFormatException {
		Workbook workbook = template.getTemplate();
		filler.fill(workbook, dataSource.getData());
		workbook.write(os);
	}
	

導入數(shù)據(jù)案例展示
如何使用Java 實現(xiàn)excel模板導出---多sheet導出?,項目,入門案例,知識點,java,spring boot
excel模板批注案例
每個sheet頁都需要寫批注,通過批注中的expression對應的值來判斷是哪個sheet頁的數(shù)據(jù),從而進行填充。dataMapping中的key值指的是列序號,value值指的是填充的字段名稱,通過名稱找對應的數(shù)據(jù)。
如何使用Java 實現(xiàn)excel模板導出---多sheet導出?,項目,入門案例,知識點,java,spring boot文章來源地址http://www.zghlxwxcb.cn/news/detail-612401.html

到了這里,關(guān)于如何使用Java 實現(xiàn)excel模板導出---多sheet導出?的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔相關(guān)法律責任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實不符,請點擊違法舉報進行投訴反饋,一經(jīng)查實,立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費用

相關(guān)文章

  • Java利用POI導入Excel數(shù)據(jù)(多個sheet、模板)

    Java利用POI導入Excel數(shù)據(jù)(多個sheet、模板)

    需求:根據(jù)excel模板導入數(shù)據(jù) ?????????? sheet1:1-6行為固定格式,且需要取值({xxx});7行開始為數(shù)據(jù)集合(list) ?????????? sheet2:都為固定格式,取值地方:{xxx}? ?????? 1、數(shù)據(jù)格式(兩個Sheet) ? 2、代碼

    2024年02月16日
    瀏覽(28)
  • 【Java】使用POI按模板樣式導出Excel

    根據(jù)模板樣式進行excel導出。 首先,當然是要有一個excel模板,excel的樣式用wps等進行設(shè)置。 然后就是代碼的實現(xiàn)了,先引入POI的依賴: 然后就是實現(xiàn)方法里的代碼,首先定義響應信息: 然后將excel模板轉(zhuǎn)為輸入流,這一步的實現(xiàn)方法有很多,具體選擇因人而異,我這里就舉

    2024年02月14日
    瀏覽(27)
  • 使用EasyPoi實現(xiàn)Excel的按模板樣式導出

    使用EasyPoi實現(xiàn)Excel的按模板樣式導出

    1690342020350導出測試.xlsx 如下 #fe 使用#fe命令可以實現(xiàn)集合數(shù)據(jù)的橫向拓展,比如模板代碼是 導出的excel里面就會顯示會自當前列,向右拓展,效果可參見下面的導出文件截圖 v_fe 使用v_fe命令可以實現(xiàn)不固定列的橫向遍歷,比如模板代碼是 分數(shù) ID {{#fe:maths t.score t.id}} 這種情況

    2024年02月15日
    瀏覽(27)
  • Springboot基于easyexcel實現(xiàn)一個excel文件包含多個sheet表格的數(shù)據(jù)導出

    Springboot基于easyexcel實現(xiàn)一個excel文件包含多個sheet表格的數(shù)據(jù)導出

    EasyExcel 是一款基于Java的開源Excel操作工具,它提供了簡單且強大的 API,使開發(fā)人員可以輕松地讀寫、操作和生成Excel文件。 EasyExcel 支持 Excel 文件的導入和導出,可以處理大量數(shù)據(jù),具有高性能和低內(nèi)存占用。它可以讀取 Excel 文件中的數(shù)據(jù),并將數(shù)據(jù)轉(zhuǎn)換為 Java 對象,也可

    2024年02月03日
    瀏覽(21)
  • EasyExcel導出工具類(支持模板導出多Sheet導出)

    EasyExcel導出工具類(支持模板導出多Sheet導出)

    最近寫需求發(fā)現(xiàn)沒有順手excel導出工具類, 于是自己造了個小輪子, 鏈式一\\\".\\\"到底, 代碼既注釋 特點: 支持多sheet 支持從模板導出 支持分頁拿數(shù)據(jù), 避免數(shù)據(jù)量過大一次拿出導致內(nèi)存溢出 數(shù)據(jù)類型支持業(yè)務(wù)實體類或Map, 無需easyExcel的注解, 低侵入 ? over

    2024年02月16日
    瀏覽(27)
  • Java導出Excel模板,導出數(shù)據(jù)到指定模板,通過模板導入數(shù)據(jù)(一)

    Java導出Excel模板,導出數(shù)據(jù)到指定模板,通過模板導入數(shù)據(jù)(一)

    本文章主要是介紹阿里巴巴的easyexcel的使用 1. 首先需要我們導入easyexcel的依賴包 2. 前期工作準備 編寫相關(guān)導出模板和導入模板。在項目的resources下創(chuàng)建文件夾,命名為excel 導出模板(此處僅做示例,字段根據(jù)自己項目來): ?導入模板(導入時需要哪些字段根據(jù)自己項目業(yè)

    2024年02月03日
    瀏覽(30)
  • java根據(jù)excel模板進行導出數(shù)據(jù)

    java根據(jù)excel模板進行導出數(shù)據(jù)

    ?一、pom文件添加以下依賴 二、添加util包 三、在resources目錄下添加template并添加xlsx模板 ?注意:xlsx模板使用${list.XXX}? ? ?XXX表示數(shù)據(jù)源list(map形式的list)的數(shù)據(jù)key值,如果list是對象形式的,那么就是該業(yè)務(wù)字段 ?四、業(yè)務(wù)層使用:

    2024年02月11日
    瀏覽(28)
  • 【Java】百萬數(shù)據(jù)excel導出功能如何實現(xiàn)

    【Java】百萬數(shù)據(jù)excel導出功能如何實現(xiàn)

    人不走空 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? ? 目錄 ? ????????個人主頁:人不走空?????? ??系列專欄:算法專題 ?詩詞歌賦:斯是陋室,惟吾德馨 前言 1.異步處理 1.1 使用job 1.2 使用mq 2.使用easyexcel 3.分頁查詢 4.多個she

    2024年02月20日
    瀏覽(26)
  • Java 導出Excel利器 JXLS(excel模板配置教程)

    Java 導出Excel利器 JXLS(excel模板配置教程)

    相信大家能經(jīng)常性的遇到項目上各類excel的導出,簡單的excel格式,用簡單的poi,easyExcel等工具都能導出。但是針對復雜的excel,有固定的樣式、合并單元格、動態(tài)列等各類要求,導致excel 導出需要花很大一部分精力去寫代碼。jxls在很大程度上解決了以上問題。 這里簡單介紹

    2023年04月08日
    瀏覽(19)
  • 【Go】excelize庫實現(xiàn)excel導入導出封裝(三),基于excel模板導出excel

    【Go】excelize庫實現(xiàn)excel導入導出封裝(三),基于excel模板導出excel

    大家好,這里是符華~ 關(guān)于excelize庫實現(xiàn)excel導入導出封裝,我已經(jīng)寫了兩篇了,我想要的功能基本已經(jīng)實現(xiàn)了,現(xiàn)在還差一個模板導出,這篇文章就來講講如何實現(xiàn)用模板導出excel。 前兩篇: 【Go】excelize庫實現(xiàn)excel導入導出封裝(一),自定義導出樣式、隔行背景色、自適應

    2024年01月25日
    瀏覽(64)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包