我現(xiàn)在要做一個(gè)execl的導(dǎo)出,所用的.jar我已經(jīng)弄好了,現(xiàn)在我不知道要怎么實(shí)現(xiàn)這個(gè)功能,還請(qǐng)細(xì)致回答。不要湊數(shù)的評(píng)論。謝謝大家。 網(wǎng)上的例子都是 半截拉快的 實(shí)在不知從哪開(kāi)始。
我點(diǎn)擊按鈕之后,到后臺(tái),然后怎么弄。。。excel里面的列名字都是自己根據(jù)需要寫(xiě)死的嗎,還是怎么弄,需要展現(xiàn)的數(shù)據(jù),是在先查 還是已經(jīng)存在一個(gè)集合里面直接循環(huán)出來(lái)了,,,
4 回答

慕絲7291255
TA貢獻(xiàn)1859條經(jīng)驗(yàn) 獲得超6個(gè)贊
poi
版本。
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.9</version>
</dependency>
Hello World 示例
import java.io.FileOutputStream;
import java.util.HashMap;
import java.util.Map;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellUtil;
/**
* @author Kevin Zou (kevinz@weghst.com)
*/
public class HelloWorld {
public static void main(String[] args) throws Exception {
Workbook workbook = new HSSFWorkbook();
Sheet sheet = workbook.createSheet("HELLO");
Map<String, Object> properties = new HashMap<>();
// border around a cell
properties.put(CellUtil.BORDER_TOP, CellStyle.BORDER_MEDIUM);
properties.put(CellUtil.BORDER_BOTTOM, CellStyle.BORDER_MEDIUM);
properties.put(CellUtil.BORDER_LEFT, CellStyle.BORDER_MEDIUM);
properties.put(CellUtil.BORDER_RIGHT, CellStyle.BORDER_MEDIUM);
// Give it a color (RED)
properties.put(CellUtil.TOP_BORDER_COLOR, IndexedColors.RED.getIndex());
properties.put(CellUtil.BOTTOM_BORDER_COLOR, IndexedColors.RED.getIndex());
properties.put(CellUtil.LEFT_BORDER_COLOR, IndexedColors.RED.getIndex());
properties.put(CellUtil.RIGHT_BORDER_COLOR, IndexedColors.RED.getIndex());
// Apply the borders to the cell at B2
Row row = sheet.createRow(1);
Cell cell = row.createCell(1);
for (Map.Entry<String, Object> e : properties.entrySet()) {
CellUtil.setCellStyleProperty(cell, workbook, e.getKey(), e.getValue());
}
cell.setCellValue("First"); // 單元格值
// Apply the borders to a 3x3 region starting at D4
for (int ix = 3; ix <= 5; ix++) {
row = sheet.createRow(ix);
for (int iy = 3; iy <= 5; iy++) {
cell = row.createCell(iy);
for (Map.Entry<String, Object> e : properties.entrySet()) {
CellUtil.setCellStyleProperty(cell, workbook, e.getKey(), e.getValue());
}
cell.setCellValue(ix + " * " + iy); // 單元格值
}
}
FileOutputStream fileOut = new FileOutputStream("C:/helloworld.xls");
workbook.write(fileOut);
fileOut.close();
System.out.println("The end.");
}
}
poi Quick Guide

素胚勾勒不出你
TA貢獻(xiàn)1827條經(jīng)驗(yàn) 獲得超9個(gè)贊
我現(xiàn)在都是JS導(dǎo)出(Chrome),不過(guò)有一個(gè)利用Java反射導(dǎo)出Excel的工具類(lèi),分享給題主~
添加回答
舉報(bào)
0/150
提交
取消