|
@@ -19,6 +19,7 @@ import java.util.Set;
|
|
|
import java.util.UUID;
|
|
|
import java.util.stream.Collectors;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
+import org.apache.poi.ooxml.POIXMLDocumentPart;
|
|
|
import org.apache.poi.ss.usermodel.BorderStyle;
|
|
|
import org.apache.poi.ss.usermodel.Cell;
|
|
|
import org.apache.poi.ss.usermodel.CellStyle;
|
|
@@ -33,6 +34,7 @@ import org.apache.poi.ss.usermodel.FillPatternType;
|
|
|
import org.apache.poi.ss.usermodel.Font;
|
|
|
import org.apache.poi.ss.usermodel.HorizontalAlignment;
|
|
|
import org.apache.poi.ss.usermodel.IndexedColors;
|
|
|
+import org.apache.poi.ss.usermodel.PictureData;
|
|
|
import org.apache.poi.ss.usermodel.Row;
|
|
|
import org.apache.poi.ss.usermodel.Sheet;
|
|
|
import org.apache.poi.ss.usermodel.VerticalAlignment;
|
|
@@ -43,6 +45,12 @@ import org.apache.poi.util.IOUtils;
|
|
|
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
|
|
|
import org.apache.poi.xssf.usermodel.XSSFClientAnchor;
|
|
|
import org.apache.poi.xssf.usermodel.XSSFDataValidation;
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFDrawing;
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFPicture;
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFShape;
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFSheet;
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
+import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTMarker;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import com.ruoyi.common.annotation.Excel;
|
|
@@ -57,6 +65,7 @@ import com.ruoyi.common.utils.DateUtils;
|
|
|
import com.ruoyi.common.utils.DictUtils;
|
|
|
import com.ruoyi.common.utils.StringUtils;
|
|
|
import com.ruoyi.common.utils.file.FileTypeUtils;
|
|
|
+import com.ruoyi.common.utils.file.FileUtils;
|
|
|
import com.ruoyi.common.utils.file.ImageUtils;
|
|
|
import com.ruoyi.common.utils.reflect.ReflectUtils;
|
|
|
|
|
@@ -176,7 +185,7 @@ public class ExcelUtil<T>
|
|
|
{
|
|
|
throw new IOException("文件sheet不存在");
|
|
|
}
|
|
|
-
|
|
|
+ Map<String, PictureData> pictures = getSheetPictrues((XSSFSheet) sheet, (XSSFWorkbook) wb);
|
|
|
// 获取最后一个非空行的行下标,比如总行数为n,则返回的为n-1
|
|
|
int rows = sheet.getLastRowNum();
|
|
|
|
|
@@ -309,6 +318,20 @@ public class ExcelUtil<T>
|
|
|
{
|
|
|
val = reverseDictByExp(Convert.toStr(val), attr.dictType(), attr.separator());
|
|
|
}
|
|
|
+ else if (ColumnType.IMAGE == attr.cellType())
|
|
|
+ {
|
|
|
+ if (StringUtils.isNull(pictures))
|
|
|
+ {
|
|
|
+ val = "";
|
|
|
+ }
|
|
|
+ PictureData image = pictures.get(row.getRowNum() + "_" + entry.getKey());
|
|
|
+ if (image == null)
|
|
|
+ {
|
|
|
+ val = "";
|
|
|
+ }
|
|
|
+ byte[] data = image.getData();
|
|
|
+ val = FileUtils.writeImportBytes(data);
|
|
|
+ }
|
|
|
ReflectUtils.invokeSetter(entity, propertyName, val);
|
|
|
}
|
|
|
}
|
|
@@ -1154,4 +1177,36 @@ public class ExcelUtil<T>
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取Excel图片
|
|
|
+ *
|
|
|
+ * @param sheet 当前sheet对象
|
|
|
+ * @param workbook 工作簿对象
|
|
|
+ * @return Map key:图片单元格索引(1_1)String,value:图片流PictureData
|
|
|
+ */
|
|
|
+ public static Map<String, PictureData> getSheetPictrues(XSSFSheet sheet, XSSFWorkbook workbook)
|
|
|
+ {
|
|
|
+ Map<String, PictureData> sheetIndexPicMap = new HashMap<String, PictureData>();
|
|
|
+ for (POIXMLDocumentPart dr : sheet.getRelations())
|
|
|
+ {
|
|
|
+ if (dr instanceof XSSFDrawing)
|
|
|
+ {
|
|
|
+ XSSFDrawing drawing = (XSSFDrawing) dr;
|
|
|
+ List<XSSFShape> shapes = drawing.getShapes();
|
|
|
+ for (XSSFShape shape : shapes)
|
|
|
+ {
|
|
|
+ if (shape instanceof XSSFPicture)
|
|
|
+ {
|
|
|
+ XSSFPicture pic = (XSSFPicture) shape;
|
|
|
+ XSSFClientAnchor anchor = pic.getPreferredSize();
|
|
|
+ CTMarker ctMarker = anchor.getFrom();
|
|
|
+ String picIndex = ctMarker.getRow() + "_" + ctMarker.getCol();
|
|
|
+ sheetIndexPicMap.put(picIndex, pic.getPictureData());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return sheetIndexPicMap;
|
|
|
+ }
|
|
|
}
|