Bläddra i källkod

表头高度定制,地址支持url

4.1.3.A
jueyue 7 år sedan
förälder
incheckning
f6114e3d30
4 ändrade filer med 52 tillägg och 26 borttagningar
  1. +32
    -18
      easypoi-base/src/main/java/cn/afterturn/easypoi/cache/manager/FileLoaderImpl.java
  2. +12
    -0
      easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/ExportParams.java
  3. +7
    -7
      easypoi-base/src/main/java/cn/afterturn/easypoi/excel/export/ExcelExportService.java
  4. +1
    -1
      easypoi-base/src/main/java/cn/afterturn/easypoi/excel/export/template/ExcelExportOfTemplateUtil.java

+ 32
- 18
easypoi-base/src/main/java/cn/afterturn/easypoi/cache/manager/FileLoaderImpl.java Visa fil

@@ -1,13 +1,13 @@
/**
* Copyright 2013-2015 JueYue (qrb.jueyue@gmail.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
@@ -21,6 +21,8 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.*;
import java.net.URL;
import java.net.URLConnection;

/**
* 文件加载类,根据路径加载指定文件
@@ -37,18 +39,30 @@ public class FileLoaderImpl implements IFileLoader {
InputStream fileis = null;
ByteArrayOutputStream baos = null;
try {
//先用绝对路径查询,再查询相对路径
try {
fileis = new FileInputStream(url);
} catch (FileNotFoundException e) {
//获取项目文件
fileis = FileLoaderImpl.class.getClassLoader().getResourceAsStream(url);
if (fileis == null) {
//最后再拿相对文件路径
String path = PoiPublicUtil.getWebRootPath(url);
fileis = new FileInputStream(path);

//判断是否是网络地址
if (url.startsWith("http")) {
URL urlObj = new URL(url);
URLConnection urlConnection = urlObj.openConnection();
urlConnection.setConnectTimeout(30);
urlConnection.setReadTimeout(60);
urlConnection.setDoInput(true);
fileis = urlConnection.getInputStream();
} else {
//先用绝对路径查询,再查询相对路径
try {
fileis = new FileInputStream(url);
} catch (FileNotFoundException e) {
//获取项目文件
fileis = FileLoaderImpl.class.getClassLoader().getResourceAsStream(url);
if (fileis == null) {
//最后再拿相对文件路径
String path = PoiPublicUtil.getWebRootPath(url);
fileis = new FileInputStream(path);
}
}
}

baos = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int len;


+ 12
- 0
easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/ExportParams.java Visa fil

@@ -83,6 +83,11 @@ public class ExportParams extends ExcelBaseParams {
* Excel 导出style
*/
private Class<?> style = ExcelExportStylerDefaultImpl.class;
/**
* 表头高度
*/
private double headerHeight = 9D;
/**
* 是否创建表头
*/
@@ -272,4 +277,11 @@ public class ExportParams extends ExcelBaseParams {
this.height = height;
}
public short getHeaderHeight() {
return (short) (titleHeight * 50);
}
public void setHeaderHeight(double headerHeight) {
this.headerHeight = headerHeight;
}
}

+ 7
- 7
easypoi-base/src/main/java/cn/afterturn/easypoi/excel/export/ExcelExportService.java Visa fil

@@ -55,9 +55,9 @@ public class ExcelExportService extends BaseExportService {
List<ExcelExportEntity> excelParams) {
int rows = 0, fieldLength = getFieldLength(excelParams);
if (entity.getTitle() != null) {
rows += createHeaderRow(entity, sheet, workbook, fieldLength);
rows += createTitle2Row(entity, sheet, workbook, fieldLength);
}
rows += createTitleRow(entity, sheet, workbook, rows, excelParams);
rows += createHeaderRow(entity, sheet, workbook, rows, excelParams);
sheet.createFreezePane(0, rows, 0, rows);
return rows;
}
@@ -65,7 +65,7 @@ public class ExcelExportService extends BaseExportService {
/**
* 创建 表头改变
*/
public int createHeaderRow(ExportParams entity, Sheet sheet, Workbook workbook,
public int createTitle2Row(ExportParams entity, Sheet sheet, Workbook workbook,
int fieldWidth) {

Row row = sheet.createRow(0);
@@ -212,15 +212,15 @@ public class ExcelExportService extends BaseExportService {
/**
* 创建表头
*/
private int createTitleRow(ExportParams title, Sheet sheet, Workbook workbook, int index,
List<ExcelExportEntity> excelParams) {
private int createHeaderRow(ExportParams title, Sheet sheet, Workbook workbook, int index,
List<ExcelExportEntity> excelParams) {
Row row = sheet.createRow(index);
int rows = getRowNums(excelParams);
row.setHeight((short) 450);
row.setHeight(title.getHeaderHeight());
Row listRow = null;
if (rows == 2) {
listRow = sheet.createRow(index + 1);
listRow.setHeight((short) 450);
listRow.setHeight(title.getHeaderHeight());
}
int cellIndex = 0;
int groupCellLength = 0;


+ 1
- 1
easypoi-base/src/main/java/cn/afterturn/easypoi/excel/export/template/ExcelExportOfTemplateUtil.java Visa fil

@@ -302,7 +302,7 @@ public final class ExcelExportOfTemplateUtil extends BaseExportService {
cell = row.getCell(i);
if (row.getCell(i) != null && (cell.getCellType() == Cell.CELL_TYPE_STRING
|| cell.getCellType() == Cell.CELL_TYPE_NUMERIC)) {
String text = PoiCellUtil.getCellValue(cell); // plq modify at 2017-11-11
String text = PoiCellUtil.getCellValue(cell);
if (text.contains(FOREACH_COL) || text.contains(FOREACH_COL_VALUE)) {
foreachCol(cell, map, text);
}


Laddar…
Avbryt
Spara