Execl 导出 import java.io.IOException; import java.io.OutputStream; import java.net.URLEncoder; import java.util.ArrayList; import java.util.List; import javax.servlet.http.HttpServletResponse; import org.apache.poi.hssf.usermodel.HSSFCel
Execl 导出
import java.io.IOException;
import java.io.OutputStream;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.hssf.usermodel.HSSFRichTextString;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.ss.util.CellRangeAddress;
public class ExportExcelUtils {
/**
* 导出表格的表名
*/
private String title;
/**
* 导出表格的列名
*/
private String[] rowName;
/**
* 对象数组的List集合
*/
private List
使用
public void export (String[] ***, HttpServletResponse response) {
List<***> list = null;
try {
list = service.export(Arrays.asList(**));
} catch (Exception e) {
e.printStackTrace();
return;
}
String title = "title";
String[] rowsName = new String[]{"序号","***", "***", "***", "***", "***"};
List
dataList = new ArrayList<>();
Object[] objects = null;
int i = 1;
for (*** record: list) {
objects = new Object[rowsName.length];
objects[0] = i;
objects[1] = record.get***();
objects[2] = record.get***();
objects[3] = record.get***();
objects[4] = record.get***();
objects[5] = record.get***();
dataList.add(objects);
i++;
}
ExportExcelUtils excelUtils = new ExportExcelUtils(title, rowsName, dataList, response);
excelUtils.exportData();
}