Commit bea3477f authored by shulidong's avatar shulidong

委托单产值导出方法2

parent a5b58c15
......@@ -81,10 +81,12 @@ public class EntrustController {
public void export(String startDate, String endDate, Integer status,
Integer clientId, String projectName, String projectCode,
String fileName, HttpServletResponse response) {
long a = System.currentTimeMillis();
try {
entrustService.export(startDate, endDate, status,
entrustService.exportConsignation(startDate, endDate, status,
clientId, projectName, projectCode,
fileName, response);
System.out.println(System.currentTimeMillis()-a);
} catch (Exception e) {
log.debug("委托列表导出{}", e);
}
......
......@@ -144,6 +144,10 @@ public interface IEntrustService extends IService<Entrust> {
Integer clientId, String projectName, String projectCode,
String fileName, HttpServletResponse response);
void exportConsignation(String startDate, String endDate, Integer status,
Integer clientId, String projectName, String projectCode,
String fileName, HttpServletResponse response);
BaseResponse<EntrustVo> getBaseDtail(Integer id);
BaseResponse<EntrustVo> getBaseDtailClient(Integer id);
......
package cn.wise.sc.cement.business.util;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import cn.afterturn.easypoi.excel.annotation.Excel;
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.HSSFWorkbook;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.FontFormatting;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.VerticalAlignment;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.wp.usermodel.Paragraph;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFCellStyle;
import org.apache.poi.xssf.usermodel.XSSFFont;
......@@ -26,6 +19,15 @@ import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Arrays;
import java.util.List;
/**
* excel工具类
*
......@@ -159,6 +161,42 @@ public class ExcelUtil {
}
}
public static void excelExportNew(String fileName, Workbook workbook,
HttpServletResponse response) {
if (workbook != null) {
ByteArrayOutputStream byteArrayOutputStream = null;
try {
byteArrayOutputStream = new ByteArrayOutputStream();
workbook.write(byteArrayOutputStream);
String suffix = ".xls";
response.setContentType("application/vnd.ms-excel;charset=utf-8");
response.setHeader("Content-Disposition",
"attachment;filename=" + new String((fileName + suffix).getBytes(), "iso-8859-1"));
OutputStream outputStream = response.getOutputStream();
outputStream.write(byteArrayOutputStream.toByteArray());
outputStream.close();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (byteArrayOutputStream != null) {
byteArrayOutputStream.close();
}
} catch (IOException e) {
e.printStackTrace();
}
try {
workbook.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
/**
* @param headers 列头
* @param datas 数据
......@@ -244,7 +282,7 @@ public class ExcelUtil {
applyRichStringFontsub(value, richString, xxsfFont);
cell.setCellValue(richString);
// value = cell.getStringCellValue();
}else{
} else {
cell.setCellValue(value);
cell.setCellStyle(style);
}
......@@ -259,7 +297,6 @@ public class ExcelUtil {
}*/
}
}
}
......@@ -287,6 +324,19 @@ public class ExcelUtil {
}
}
public static XSSFRichTextString applyFontsub(String sub, XSSFFont xxsfFont) {
XSSFRichTextString richString = new XSSFRichTextString();
if (sub.contains("<sub>") || sub.contains("</sub>")) {
xxsfFont.setTypeOffset(FontFormatting.SS_SUB);
richString.setString(sub.replaceAll("</sub>", "<sub>").replaceAll("<sub>", ""));
//提取下标位置
applyRichStringFontsub(sub, richString, xxsfFont);
} else {
richString.setString(sub);
}
return richString;
}
private static void applyRichStringFontsup(String sup, XSSFRichTextString richString, XSSFFont xxsfFont) {
String[] split = sup.replaceAll("</sup>", "<sup>").split("<sup>");
String it_str = "";
......@@ -371,7 +421,7 @@ public class ExcelUtil {
private static XSSFWorkbook generatoronsignationWorkbook(List<String> infoHeader, List<String> teamsHeader) {
XSSFWorkbook wb = new XSSFWorkbook();
XSSFSheet sheet = wb.createSheet("sheet1");
XSSFCellStyle style=wb.createCellStyle();
XSSFCellStyle style = wb.createCellStyle();
//水平居中
style.setAlignment(HorizontalAlignment.CENTER);
//垂直居中
......@@ -409,7 +459,7 @@ public class ExcelUtil {
tempCell2.setCellValue(header);
tempCell2.setCellStyle(style);
//合并表头
sheet.addMergedRegion(new CellRangeAddress(0, 0, i-1, i ));
sheet.addMergedRegion(new CellRangeAddress(0, 0, i - 1, i));
}
//创建第二行
XSSFRow row1 = sheet.createRow(rownum++);
......@@ -434,7 +484,7 @@ public class ExcelUtil {
tempCell.setCellStyle(style);
}
//处理检测项信息表头
for (int i = teamsHeader.size()+1 + infoHeader.size(); i < infoHeader.size()+1 + teamsHeader.size() * 3; i++) {
for (int i = teamsHeader.size() + 1 + infoHeader.size(); i < infoHeader.size() + 1 + teamsHeader.size() * 3; i++) {
XSSFCell tempCell1 = row1.createCell(i);
tempCell1.setCellValue("单价");
tempCell1.setCellStyle(style);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment