미리 엑셀 파일을 생성 및 편집하고 스타일을 설정해야 합니다.
출력 데이터를 편집하고 엑셀 좌표에 따라 일대일 대응을 해보세요.
목록 데이터 출력 및 목록의 열 병합을 지원합니다.
코드는 다음과 같습니다.
package com.icourt.util;import org.apache.commons.collections4.CollectionUtils;import org.apache.poi.openxml4j.exceptions.InvalidFormatException;import org.apache.poi.ss.usermodel.*;import org.apache.poi.ss.util.CellRangeAddress;import java.io.*;import java.util.ArrayList;import java.util.HashMap;import java.util.List;import java.util.Map;import java.util.Map.Entry;import java.util.regex.Matcher;import java.util.regex.Pattern;/** * 描述:poi根据模板导出excel,根据excel坐标赋值,如(B1) */public class ExcelExportUtil {//模板mapprivate Map<string> tempWorkbook = new HashMap<string>();//模板输入流mapprivate Map<string> tempStream = new HashMap<string>();/** * 功能:按模板向Excel中相应地方填充数据 */public void writeData(String templateFilePath, Map<string> dataMap, int sheetNo) throws IOException, InvalidFormatException {if (dataMap == null || dataMap.isEmpty()) {return; }//读取模板Workbook wbModule = getTempWorkbook(templateFilePath);//数据填充的sheetSheet wsheet = wbModule.getSheetAt(sheetNo);for (Entry<string> entry : dataMap.entrySet()) { String point = entry.getKey(); Object data = entry.getValue(); TempCell cell = getCell(point, data, wsheet);//指定坐标赋值 setCell(cell, wsheet); }//设置生成excel中公式自动计算wsheet.setForceFormulaRecalculation(true); }/** * 功能:按模板向Excel中列表填充数据.只支持列合并 */public void writeDateList(String templateFilePath, String[] heads, List<map>> datalist, int sheetNo) throws IOException, InvalidFormatException {if (heads == null || heads.length tempCells = new ArrayList<tempcell>(heads.length);for (String point : heads) { TempCell tempCell = getCell(point, null, wsheet);//取得合并单元格位置 -1:表示不是合并单元格int pos = isMergedRegion(wsheet, tempCell.getRow(), tempCell.getColumn());if (pos > -1) { CellRangeAddress range = wsheet.getMergedRegion(pos); tempCell.setColumnSize(range.getLastColumn() - range.getFirstColumn()); } tempCells.add(tempCell); }//赋值for (int i = 0; i dataMap = datalist.get(i);for (int j = 0; j -1) { CellRangeAddress rangeAddress = mergeRegion(sheet, tempCell.getRow(), tempCell.getRow(), tempCell.getColumn(), tempCell.getColumn() + tempCell.getColumnSize()); setRegionStyle(tempCell.getCellStyle(), rangeAddress, sheet); } Row rowIn = sheet.getRow(tempCell.getRow());if (rowIn == null) { copyRows(tempCell.getRow() - 1, tempCell.getRow() - 1, tempCell.getRow(), sheet);//复制上一行rowIn = sheet.getRow(tempCell.getRow()); } Cell cellIn = rowIn.getCell(tempCell.getColumn());if (cellIn == null) { cellIn = rowIn.createCell(tempCell.getColumn()); }//根据data类型给cell赋值if (tempCell.getData() instanceof String) { cellIn.setCellValue((String) tempCell.getData()); } else if (tempCell.getData() instanceof Integer) { cellIn.setCellValue((int) tempCell.getData()); } else if (tempCell.getData() instanceof Double) { cellIn.setCellValue((double) tempCell.getData()); } else { cellIn.setCellValue((String) tempCell.getData()); }//样式if (tempCell.getCellStyle() != null && tempCell.getColumnSize() == -1) { cellIn.setCellStyle(tempCell.getCellStyle()); } }/** * 功能:写到输出流并移除资源 */public void writeAndClose(String templateFilePath, OutputStream os) throws IOException, InvalidFormatException {if (getTempWorkbook(templateFilePath) != null) { getTempWorkbook(templateFilePath).write(os); tempWorkbook.remove(templateFilePath); }if (getInputStream(templateFilePath) != null) { getInputStream(templateFilePath).close(); tempStream.remove(templateFilePath); } }/** * 功能:判断指定的单元格是否是合并单元格 */private Integer isMergedRegion(Sheet sheet, int row, int column) {for (int i = 0; i = firstRow && row = firstColumn && column = pStartRow)&& (region.getLastRow() dataMap = new HashMap<string>(); dataMap.put("B1", "03_Alpha_项目工作时间统计表"); dataMap.put("B2", "统计时间:2017/01/01 - 2017/03/31"); excel.writeData(templateFilePath, dataMap, 0); List<map>> datalist = new ArrayList<map>>(); Map<integer> data = new HashMap<integer>(); data.put(1, "3/10/17"); data.put(2, "18:50"); data.put(3, "19:00"); data.put(4, "李子鹏"); data.put(5, "新增项目键值对接口,供任务计时调用"); data.put(6, "代码开发"); data.put(7, "3.17"); datalist.add(data); data = new HashMap<integer>(); data.put(1, "3/10/17"); data.put(2, "18:50"); data.put(3, "19:00"); data.put(4, "李子鹏"); data.put(5, "新增项目键值对接口,供任务计时调用"); data.put(6, "代码开发"); data.put(7, "3.17"); datalist.add(data); data = new HashMap<integer>(); data.put(1, "3/10/17"); data.put(2, "18:50"); data.put(3, "19:00"); data.put(4, "李子鹏"); data.put(5, "新增项目键值对接口,供任务计时调用"); data.put(6, "代码开发"); data.put(7, "3.17"); datalist.add(data); data = new HashMap<integer>(); data.put(1, "3/10/17"); data.put(2, "18:50"); data.put(3, "19:00"); data.put(4, "李子鹏"); data.put(5, "新增项目键值对接口,供任务计时调用"); data.put(6, "代码开发"); data.put(7, "3.17"); datalist.add(data); data = new HashMap<integer>(); data.put(1, "3/10/17"); data.put(2, "18:50"); data.put(3, "19:00"); data.put(4, "李子鹏"); data.put(5, "新增项目键值对接口,供任务计时调用"); data.put(6, "代码开发"); data.put(7, "3.17"); datalist.add(data); data = new HashMap<integer>(); data.put(1, "3/10/17"); data.put(2, "18:50"); data.put(3, "19:00"); data.put(4, "李子鹏"); data.put(5, "新增项目键值对接口,供任务计时调用"); data.put(6, "代码开发"); data.put(7, "3.17"); datalist.add(data); data = new HashMap<integer>(); data.put(1, "3/10/17"); data.put(2, "18:50"); data.put(3, "19:00"); data.put(4, "李子鹏"); data.put(5, "新增项目键值对接口,供任务计时调用"); data.put(6, "代码开发"); data.put(7, "3.17"); datalist.add(data); data = new HashMap<integer>(); data.put(1, "3/10/17"); data.put(2, "18:50"); data.put(3, "19:00"); data.put(4, "李子鹏"); data.put(5, "新增项目键值对接口,供任务计时调用"); data.put(6, "代码开发"); data.put(7, "3.17"); datalist.add(data); data = new HashMap<integer>(); data.put(1, "3/10/17"); data.put(2, "18:50"); data.put(3, "19:00"); data.put(4, "李子鹏"); data.put(5, "新增项目键值对接口,供任务计时调用新增项目键值对接口,供任务计时调用新增项目键值对接口,供任务计时调用新增项目键值对接口,供任务计时调用新增项目键值对接口,供任务计时调用新增项目键值对接口,供任务计时调用新增项目键值对接口,供任务计时调用新增项目键值对接口,供任务计时调用"); data.put(6, "代码开发"); data.put(7, "3.17"); datalist.add(data); data = new HashMap<integer>(); data.put(1, ""); data.put(2, ""); data.put(3, ""); data.put(4, ""); data.put(5, ""); data.put(6, ""); data.put(7, ""); datalist.add(data); String[] heads = new String[]{"B4", "C4", "D4", "E4", "F4", "G4", "H4"}; excel.writeDateList(templateFilePath, heads, datalist, 0);//写到输出流并移除资源 excel.writeAndClose(templateFilePath, os); os.flush(); os.close(); } }</integer></integer></integer></integer></integer></integer></integer></integer></integer></integer></integer></map></map></string></tempcell></map></string></string></string></string></string></string>
일반 아이디어:
가장 중요한 것은 좋은 템플릿을 만드는 것입니다
코드는 다음에 따라 읽혀집니다. 템플릿 열 형식을 설정하고, 루프 데이터 행에서 해당 행을 읽고, 행이 존재하지 않으면 해당 행을 복사해야 하는지 확인합니다. 지정된 형식이 없는 행을 선택한 다음 행의 각 열에 해당하는 데이터를 추가합니다. 각 셀에 대한 형식과 데이터를 지정합니다.
위 내용은 Apache Poi는 템플릿을 기반으로 Excel을 내보냅니다.의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

Java는 플랫폼 독립성으로 인해 엔터프라이즈 수준의 응용 프로그램에서 널리 사용됩니다. 1) 플랫폼 독립성은 JVM (Java Virtual Machine)을 통해 구현되므로 JAVA를 지원하는 모든 플랫폼에서 코드가 실행될 수 있습니다. 2) 크로스 플랫폼 배포 및 개발 프로세스를 단순화하여 유연성과 확장 성을 더 많이 제공합니다. 3) 그러나 성능 차이 및 타사 라이브러리 호환성에주의를 기울이고 순수한 Java 코드 사용 및 크로스 플랫폼 테스트와 같은 모범 사례를 채택해야합니다.

javaplaysaSignificantroleiniotduetoitsplatformincentence.1) itallowscodetobewrittenonceandevices.2) java'secosystemprovidesusefullibrariesforiot.3) itssecurityfeaturesenhanceiotiotsystemsafety.hormormory.hormory.hustupletety.houghmormory

thejava.nio.filepackage.1) withsystem.getProperty ( "user.dir") andtherelativeatthereplattHefilePsiple.2) thepathtopilebtoafne 컨버터링 주제

Java'SplatformIndenceSnictIficantIficantBecauseItAllowsDeveloperstowRiteCodeOnceAntOnitonAnyplatformwithajvm.이 "WriteOnce, Runanywhere"(WORA) 접근자 : 1) 교차 플랫폼 컴퓨팅 성, DeploymentAcrossDifferentoSwithoutissswithoutissuesswithoutissuesswithoutswithoutisssues를 활성화합니다

Java는 크로스 서버 웹 응용 프로그램을 개발하는 데 적합합니다. 1) Java의 "Write Once, Run Everywhere"철학은 JVM을 지원하는 모든 플랫폼에서 코드를 실행합니다. 2) Java는 Spring 및 Hibernate와 같은 도구를 포함하여 개발 프로세스를 단순화하는 풍부한 생태계를 가지고 있습니다. 3) Java는 성능 및 보안에서 훌륭하게 성능을 발휘하여 효율적인 메모리 관리 및 강력한 보안 보증을 제공합니다.

JVM은 바이트 코드 해석, 플랫폼 독립 API 및 동적 클래스 로딩을 통해 Java의 Wora 기능을 구현합니다. 1. 바이트 코드는 크로스 플랫폼 작동을 보장하기 위해 기계 코드로 해석됩니다. 2. 표준 API 추상 운영 체제 차이; 3. 클래스는 런타임에 동적으로로드되어 일관성을 보장합니다.

JAVA의 최신 버전은 JVM 최적화, 표준 라이브러리 개선 및 타사 라이브러리 지원을 통해 플랫폼 별 문제를 효과적으로 해결합니다. 1) Java11의 ZGC와 같은 JVM 최적화는 가비지 수집 성능을 향상시킵니다. 2) Java9의 모듈 시스템과 같은 표준 라이브러리 개선은 플랫폼 관련 문제를 줄입니다. 3) 타사 라이브러리는 OpenCV와 같은 플랫폼 최적화 버전을 제공합니다.

JVM의 바이트 코드 검증 프로세스에는 네 가지 주요 단계가 포함됩니다. 1) 클래스 파일 형식이 사양을 준수하는지 확인, 2) 바이트 코드 지침의 유효성과 정확성을 확인하고 3) 유형 안전을 보장하기 위해 데이터 흐름 분석을 수행하고 4) 검증의 철저한 성능 균형을 유지합니다. 이러한 단계를 통해 JVM은 안전하고 올바른 바이트 코드 만 실행되도록하여 프로그램의 무결성과 보안을 보호합니다.


핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

Video Face Swap
완전히 무료인 AI 얼굴 교환 도구를 사용하여 모든 비디오의 얼굴을 쉽게 바꾸세요!

인기 기사

뜨거운 도구

드림위버 CS6
시각적 웹 개발 도구

PhpStorm 맥 버전
최신(2018.2.1) 전문 PHP 통합 개발 도구

WebStorm Mac 버전
유용한 JavaScript 개발 도구

메모장++7.3.1
사용하기 쉬운 무료 코드 편집기

Atom Editor Mac 버전 다운로드
가장 인기 있는 오픈 소스 편집기
