当前位置:网站首页>JXL export Excel
JXL export Excel
2022-06-27 17:24:00 【Azure++】
<!-- https://mvnrepository.com/artifact/jexcelapi/jxl -->
<dependency>
<groupId>jexcelapi</groupId>
<artifactId>jxl</artifactId>
<version>2.4.2</version>
</dependency>
Parameter transmission path (String)、 The theme (list)、 Content (list)
package com.azure.tool;
import java.io.*;
import java.util.ArrayList;
import java.util.List;
import jxl.Workbook;
import jxl.write.Label;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
public class ExcelUtil {
public static void main(String[] args) {
String path = "C:\\Users\\Administrator\\Desktop\\excel\\test.xls";
List<String> name = new ArrayList<>();
name.add("id");
name.add("name");
name.add("age");
List<String> content = new ArrayList<>();
for (int i = 0; i < 17; i++) {
content.add("count" + (i + 1));
}
exportExcel(path, name, content);
}
/** * @param path Export file path * @param name excel First line subject * @param content excel The data content */
public static void exportExcel(String path, List<String> name, List<String> content) {
File file = new File(path);
WritableWorkbook workbook = null;
try {
//1、 Create a workbook
workbook = Workbook.createWorkbook(file);
//2、 Create a new page
WritableSheet sheet = workbook.createSheet("Sheet1", 0);
//3、 Create a new row ,i Representative column ,0 On behalf of the line ,name Represents the header
for (int i = 0; i < name.size(); i++) {
Label label = new Label(i, 0, name.get(i));
sheet.addCell(label);
}
for (int i = 0; i < name.size(); i++) {
for (int j = 0; j < content.size(); j++) {
// Parameter one : Column 、 Parameter two : That's ok 、 Parameter 3 : Content
Label label = new Label((j % name.size()), ((j / name.size()) + 1), content.get(j));
sheet.addCell(label);
}
}
//4、 Write the created content to the output stream , And close the output stream
workbook.write();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
//5、 The last step , Close workbook
workbook.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
边栏推荐
- d3dx9_ How to repair 40.dll? Win10 system d3dx9_ What if 40.dll is lost?
- leetcode 200. Number of islands
- Leetcode daily practice (sum of two numbers)
- Extract field year / quarter effect based on date
- 软件测试基础-软件测试历史流程,分类,好处,限制
- wheel ui
- 一个机器人位于一个 m x n 网格的左上角 。机器人每次只能向下或者向右移动一步。机器人试图达到网格的右下角。问总共有多少条不同的路径?【LeetCodeHot100】
- d3dx9_ How to repair 25.dll? d3dx9_ 25.dll where to download
- Leetcode 5. Longest Palindromic Substring
- Solving Poisson equation by tensorflow
猜你喜欢
P. Simple application of a.r.a method in Siyuan (friendly testing)

10 minutes to master the installation steps of MySQL

Raspberry pie preliminary use

Common optimization techniques for Web Performance

树莓派初步使用

10分钟掌握mysql的安装步骤

Use pyinstaller to package py files into exe. Precautions and error typeerror:_ get_ sysconfigdata_ name() missing 1...‘ check_ Solutions to exists'

Event listening mechanism

Defiato is an innovation that combines user-friendly features of a centralized platform with defi services

LeetCode每日一练(两数之和)
随机推荐
Common optimization techniques for Web Performance
Etcd visualization tool: kstone deployment (I), rapid deployment based on Helm
数组表示若干个区间的集合,请你合并所有重叠的区间,并返回 一个不重叠的区间数组,该数组需恰好覆盖输入中的所有区间 。【LeetCodeHot100】
06. First introduction to express
Kubernetes basic self-study series | introduction to ingress API
d3dx9_ How to repair 38.dll? d3dx9_ 38. How to download a missing DLL?
Ten common methods of arrays tools
Performance problems caused by redis cache invalidation and competitive loading
Community sharing jumpserver in the eyes of senior open source users: a fortress machine for "Crazy" iteration
C语言教师工作量管理系统
Generate zip package command
leetcode 70. climb stairs
d3dx9_ How to repair 33.dll? d3dx9_ What if 33.dll is lost?
树莓派初步使用
Leetcode daily practice (sum of two numbers)
A robot is located in the upper left corner of an M x n grid. The robot can only move down or right one step at a time. The robot attempts to reach the lower right corner of the grid. How many differe
C système de gestion de la charge de travail des enseignants en langues
Pragma once Usage Summary
【牛客刷题】NowCoder号称自己已经记住了1-100000之间所有的斐波那契数。 为了考验他,我们随便出一个数n,让他说出第n个斐波那契数。如果第n个斐波那契大于6位则只取后6位。
Part 30 supplement (30) ECMAScript object