精华内容
下载资源
问答
  • Excel设置图片固定某个单元格内部

    千次阅读 2020-07-06 19:27:32
    锁定纵横比的,我没有设置锁定,锁定的意思是长宽改变一个,另一个会按照原图比例改变,最下面那个随单元格改变位置和大小等于锁定那个位置上,你上方插入一个单元格的话,那个图和它所在单元格位置不变,比如:...

    选定需要修改的图片右击,选择大小和属性
    在这里插入图片描述

    修改图片性质
    在这里插入图片描述
    锁定纵横比的,我没有设置锁定,锁定的意思是长宽改变一个,另一个会按照原图比例改变,最下面那个随单元格改变位置和大小等于锁定在那个位置上,你在上方插入一个单元格的话,那个图和它所在单元格位置不变,比如:原来的样子
    在这里插入图片描述
    ,在上面添加单元格的样子:
    在这里插入图片描述

    博客创建时间:2020-7-6-19:27
    展开全文
  • Java导出excel如何使用poi实现一个单元格插入多个图片
  • freemarker 生成word,支持一个单元格生成多张图片
  • cxgrdbclmnGrid1DBTableView1IconImage的Properties设置为Imageprocedure TForm1.tvGrid1DBTableView1CustomDrawCell(  Sender: TcxCustomGridTableView; ACanvas: TcxCanvas;  AViewInfo: ...
    cxgrdbclmnGrid1DBTableView1IconImage的Properties设置为Image
    
    procedure TForm1.tvGrid1DBTableView1CustomDrawCell(
      Sender: TcxCustomGridTableView; ACanvas: TcxCanvas;
      AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
    var
      AEditValue: Variant;
      APicture: TPicture;
      FBounds:TRect;
    begin
      cxgrdbclmnGrid1DBTableView1IconImage.Options.Focusing:=False; //点上去图标不变
      if AViewInfo.Item <> cxgrdbclmnGrid1DBTableView1IconImage then
      begin
        Exit;
      end;
      AEditValue := AViewInfo.GridRecord.Values[cxgrdbclmnGrid1DBTableView1IconImage.Index];
      if VarIsStr(AEditValue) or VarIsArray(AEditValue) then
      begin
        APicture := TPicture.Create;
        try
          LoadPicture(APicture,
            TcxImageProperties(cxgrdbclmnGrid1DBTableView1IconImage.Properties).GraphicClass, AEditValue);
          APicture.Bitmap.Canvas.Brush.Style:=bsClear;
          APicture.Bitmap.Canvas.TextOut(10,40,AViewInfo.GridRecord.Values[cxgrdbclmnGrid1DBTableView1CName.Index]);   //文本显示的位置 自己根据需要调整把
          FBounds:=AViewInfo.Bounds;
          ACanvas.FillRect(FBounds);
          ACanvas.DrawComplexFrame(FBounds,   clBtnHighlight,   clBtnShadow,   [bBottom,   bLeft,   bRight],   1);
          InflateRect(FBounds,   -1,   -1);
          ACanvas.Font.Color   :=   clBlack;
          ACanvas.Brush.Style   :=   bsClear;
          ACanvas.DrawGlyph(FBounds.Left,FBounds.Top,APicture.Bitmap);
        finally
          APicture.Free;
        end;
      end;
      ADone:=True;
    end;
    

    展开全文
  • 要用EPPLUS输出一个Excel文档,图片要求居中单元格内,大小是单元格 列宽行高的0.5倍。图片是浮动的,不能固定到某个单元格,但是代码能控制图片的位置,Excel列宽和行高单位是不一致的,思考过转换成像素, 代码...
  • WPS表格如何实现单元格内粘贴图片

    千次阅读 2020-09-11 15:26:25
    WPS要实现在单元格内粘贴图片有两种方法。 选中要插入图片单元格,点击插入。 这样就可以把图片嵌入单元格了。 把复制的图片直接粘贴到单元格。 复制的图片在客户端可以直接粘贴到表格,但是不能直接粘贴到...

    WPS要实现在单元格内粘贴图片有两种方法。

    1. 选中要插入图片的单元格,点击插入。
      在这里插入图片描述
      这样就可以把图片嵌入单元格了。

    2. 把复制的图片直接粘贴到单元格。
      复制的图片在客户端可以直接粘贴到表格内,但是不能直接粘贴到单元格内。
      但是如果是在浏览器上直接编辑WPS表格,却可以把图片粘贴到单元格,前提是要打开单元格的编辑模式。

      那么如何把复制的图片插入单元格呢?

      1. 先粘贴图片,然后右键图片:
        在这里插入图片描述
        效果是这样的:
        在这里插入图片描述
        然后把这个单元格的内容复制到指定单元格即可。
    展开全文
  • 重写...添加 createImageCell 方法 此方法保证不设置宽高的情况下 图片会占满合并后的单元格 // // Source code recreated from a .class file by IntelliJ IDEA // (powered b...

    重写cn.afterturn.easypoi.excel.export.template.ExcelExportOfTemplateUtil
    添加 createImageCell 方法 此方法保证在不设置宽高的情况下 图片会占满合并后的单元格

    //
    // Source code recreated from a .class file by IntelliJ IDEA
    // (powered by Fernflower decompiler)
    //
    
    package cn.afterturn.easypoi.excel.export.template;
    
    import cn.afterturn.easypoi.cache.ExcelCache;
    import cn.afterturn.easypoi.cache.ImageCache;
    import cn.afterturn.easypoi.entity.ImageEntity;
    import cn.afterturn.easypoi.excel.annotation.ExcelTarget;
    import cn.afterturn.easypoi.excel.entity.TemplateExportParams;
    import cn.afterturn.easypoi.excel.entity.enmus.ExcelType;
    import cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity;
    import cn.afterturn.easypoi.excel.entity.params.ExcelForEachParams;
    import cn.afterturn.easypoi.excel.export.base.ExcelExportBase;
    import cn.afterturn.easypoi.excel.export.styler.IExcelExportStyler;
    import cn.afterturn.easypoi.excel.export.template.TemplateSumHanlder.TemplateSumEntity;
    import cn.afterturn.easypoi.excel.html.helper.MergedRegionHelper;
    import cn.afterturn.easypoi.exception.excel.ExcelExportException;
    import cn.afterturn.easypoi.exception.excel.enums.ExcelExportEnum;
    import cn.afterturn.easypoi.util.PoiElUtil;
    import cn.afterturn.easypoi.util.PoiExcelGraphDataUtil;
    import cn.afterturn.easypoi.util.PoiPublicUtil;
    import cn.afterturn.easypoi.util.PoiSheetUtility;
    import org.apache.commons.lang3.StringUtils;
    import org.apache.poi.hssf.usermodel.HSSFClientAnchor;
    import org.apache.poi.ss.usermodel.*;
    import org.apache.poi.ss.util.CellRangeAddress;
    import org.apache.poi.xssf.usermodel.XSSFClientAnchor;
    import org.apache.poi.xssf.usermodel.XSSFWorkbook;
    import org.slf4j.Logger;
    import org.slf4j.LoggerFactory;
    
    import java.lang.reflect.Field;
    import java.util.*;
    
    public final class ExcelExportOfTemplateUtil extends ExcelExportBase {
        private static final Logger LOGGER = LoggerFactory.getLogger(ExcelExportOfTemplateUtil.class);
        private Set<String> tempCreateCellSet = new HashSet();
        private TemplateExportParams teplateParams;
        private MergedRegionHelper mergedRegionHelper;
        private TemplateSumHanlder templateSumHanlder;
    
        public ExcelExportOfTemplateUtil() {
        }
    
        private void addDataToSheet(Class<?> pojoClass, Collection<?> dataSet, Sheet sheet, Workbook workbook) throws Exception {
            if(workbook instanceof XSSFWorkbook) {
                super.type = ExcelType.XSSF;
            }
    
            Map titlemap = this.getTitleMap(sheet);
            Drawing patriarch = PoiExcelGraphDataUtil.getDrawingPatriarch(sheet);
            Field[] fileds = PoiPublicUtil.getClassFields(pojoClass);
            ExcelTarget etarget = (ExcelTarget)pojoClass.getAnnotation(ExcelTarget.class);
            String targetId = null;
            if(etarget != null) {
                targetId = etarget.value();
            }
    
            ArrayList excelParams = new ArrayList();
            this.getAllExcelField((String[])null, targetId, fileds, excelParams, pojoClass, (List)null);
            this.sortAndFilterExportField(excelParams, titlemap);
            short rowHeight = this.getRowHeight(excelParams);
            int index = this.teplateParams.getHeadingRows() + this.teplateParams.getHeadingStartRow();
            sheet.shiftRows(this.teplateParams.getHeadingRows() + this.teplateParams.getHeadingStartRow(), sheet.getLastRowNum(), this.getShiftRows(dataSet, excelParams), true, true);
            if(excelParams.size() != 0) {
                Object t;
                for(Iterator its = dataSet.iterator(); its.hasNext(); index += this.createCells(patriarch, index, t, excelParams, sheet, workbook, rowHeight)) {
                    t = its.next();
                }
    
                this.mergeCells(sheet, excelParams, index);
            }
        }
    
        private int getShiftRows(Collection<?> dataSet, List<ExcelExportEntity> excelParams) throws Exception {
            int size = 0;
    
            Object t;
            for(Iterator its = dataSet.iterator(); its.hasNext(); size += this.getOneObjectSize(t, excelParams)) {
                t = its.next();
            }
    
            return size;
        }
    
        public int getOneObjectSize(Object t, List<ExcelExportEntity> excelParams) throws Exception {
            int maxHeight = 1;
            int k = 0;
    
            for(int paramSize = excelParams.size(); k < paramSize; ++k) {
                ExcelExportEntity entity = (ExcelExportEntity)excelParams.get(k);
                if(entity.getList() != null) {
                    Collection list = (Collection)entity.getMethod().invoke(t, new Object[0]);
                    if(list != null && list.size() > maxHeight) {
                        maxHeight = list.size();
                    }
                }
            }
    
            return maxHeight;
        }
    
        public Workbook createExcleByTemplate(TemplateExportParams params, Class<?> pojoClass, Collection<?> dataSet, Map<String, Object> map) {
            if(params != null && map != null && !StringUtils.isEmpty(params.getTemplateUrl())) {
                Workbook wb = null;
    
                try {
                    this.teplateParams = params;
                    wb = this.getCloneWorkBook();
                    this.setExcelExportStyler((IExcelExportStyler)this.teplateParams.getStyle().getConstructor(new Class[]{Workbook.class}).newInstance(new Object[]{wb}));
                    int e = 0;
    
                    for(int le = params.isScanAllsheet()?wb.getNumberOfSheets():params.getSheetNum().length; e < le; ++e) {
                        if(params.getSheetName() != null && params.getSheetName().length > e && StringUtils.isNotEmpty(params.getSheetName()[e])) {
                            wb.setSheetName(e, params.getSheetName()[e]);
                        }
    
                        this.tempCreateCellSet.clear();
                        this.parseTemplate(wb.getSheetAt(e), map, params.isColForEach());
                    }
    
                    if(dataSet != null) {
                        this.dataHanlder = params.getDataHanlder();
                        if(this.dataHanlder != null) {
                            this.needHanlderList = Arrays.asList(this.dataHanlder.getNeedHandlerFields());
                        }
    
                        this.addDataToSheet(pojoClass, dataSet, wb.getSheetAt(params.getDataSheetNum()), wb);
                    }
    
                    return wb;
                } catch (Exception var8) {
                    LOGGER.error(var8.getMessage(), var8);
                    return null;
                }
            } else {
                throw new ExcelExportException(ExcelExportEnum.PARAMETER_ERROR);
            }
        }
    
        private Workbook getCloneWorkBook() throws Exception {
            return ExcelCache.getWorkbook(this.teplateParams.getTemplateUrl(), this.teplateParams.getSheetNum(), this.teplateParams.isScanAllsheet());
        }
    
        private Map<String, Integer> getTitleMap(Sheet sheet) {
            Row row = null;
            HashMap titlemap = new HashMap();
    
            for(int j = 0; j < this.teplateParams.getHeadingRows(); ++j) {
                row = sheet.getRow(j + this.teplateParams.getHeadingStartRow());
                Iterator cellTitle = row.cellIterator();
    
                for(int i = row.getFirstCellNum(); cellTitle.hasNext(); ++i) {
                    Cell cell = (Cell)cellTitle.next();
                    String value = cell.getStringCellValue();
                    if(!StringUtils.isEmpty(value)) {
                        titlemap.put(value, Integer.valueOf(i));
                    }
                }
            }
    
            return titlemap;
        }
    
        private void parseTemplate(Sheet sheet, Map<String, Object> map, boolean colForeach) throws Exception {
            this.deleteCell(sheet, map);
            this.mergedRegionHelper = new MergedRegionHelper(sheet);
            this.templateSumHanlder = new TemplateSumHanlder(sheet);
            if(colForeach) {
                this.colForeach(sheet, map);
            }
    
            Row row = null;
            int index = 0;
    
            while(true) {
                do {
                    if(index > sheet.getLastRowNum()) {
                        this.hanlderSumCell(sheet);
                        return;
                    }
    
                    row = sheet.getRow(index++);
                } while(row == null);
    
                for(int i = row.getFirstCellNum(); i < row.getLastCellNum(); ++i) {
                    if(row.getCell(i) != null && !this.tempCreateCellSet.contains(row.getRowNum() + "_" + row.getCell(i).getColumnIndex())) {
                        this.setValueForCellByMap(row.getCell(i), map);
                    }
                }
            }
        }
    
        private void hanlderSumCell(Sheet sheet) {
            Iterator var2 = this.templateSumHanlder.getDataList().iterator();
    
            while(var2.hasNext()) {
                TemplateSumEntity sumEntity = (TemplateSumEntity)var2.next();
                Cell cell = sheet.getRow(sumEntity.getRow()).getCell(sumEntity.getCol());
                cell.setCellValue(cell.getStringCellValue().replace("sum:(" + sumEntity.getSumKey() + ")", sumEntity.getValue() + ""));
            }
    
        }
    
        private void colForeach(Sheet sheet, Map<String, Object> map) throws Exception {
            Row row = null;
            Cell cell = null;
            int index = 0;
    
            while(true) {
                do {
                    if(index > sheet.getLastRowNum()) {
                        return;
                    }
    
                    row = sheet.getRow(index++);
                } while(row == null);
    
                for(int i = row.getFirstCellNum(); i < row.getLastCellNum(); ++i) {
                    cell = row.getCell(i);
                    if(row.getCell(i) != null && (cell.getCellType() == 1 || cell.getCellType() == 0)) {
                        cell.setCellType(1);
                        String text = cell.getStringCellValue();
                        if(text.contains("#fe:") || text.contains("v_fe:")) {
                            this.foreachCol(cell, map, text);
                        }
                    }
                }
            }
        }
    
        private void foreachCol(Cell cell, Map<String, Object> map, String name) throws Exception {
            boolean isCreate = name.contains("v_fe:");
            name = name.replace("v_fe:", "").replace("#fe:", "").replace("{{", "");
            String[] keys = name.replaceAll("\\s{1,}", " ").trim().split(" ");
            Collection datas = (Collection)PoiPublicUtil.getParamsValue(keys[0], map);
            Object[] columnsInfo = this.getAllDataColumns(cell, name.replace(keys[0], ""), this.mergedRegionHelper);
            if(datas != null) {
                Iterator its = datas.iterator();
                int rowspan = ((Integer)columnsInfo[0]).intValue();
                int colspan = ((Integer)columnsInfo[1]).intValue();
    
                for(List columns = (List)columnsInfo[2]; its.hasNext(); cell = cell.getRow().getCell(cell.getColumnIndex() + colspan)) {
                    Object t = its.next();
                    this.setForEeachRowCellValue(true, cell.getRow(), cell.getColumnIndex(), t, columns, map, rowspan, colspan, this.mergedRegionHelper);
                    if(cell.getRow().getCell(cell.getColumnIndex() + colspan) == null) {
                        cell.getRow().createCell(cell.getColumnIndex() + colspan);
                    }
                }
    
                if(isCreate) {
                    cell = cell.getRow().getCell(cell.getColumnIndex() - 1);
                    cell.setCellValue(cell.getStringCellValue() + "}}");
                }
    
            }
        }
    
        private void deleteCell(Sheet sheet, Map<String, Object> map) throws Exception {
            Row row = null;
            Cell cell = null;
            int index = 0;
    
            while(true) {
                do {
                    if(index > sheet.getLastRowNum()) {
                        return;
                    }
    
                    row = sheet.getRow(index++);
                } while(row == null);
    
                for(int i = row.getFirstCellNum(); i < row.getLastCellNum(); ++i) {
                    cell = row.getCell(i);
                    if(row.getCell(i) != null && (cell.getCellType() == 1 || cell.getCellType() == 0)) {
                        cell.setCellType(1);
                        String text = cell.getStringCellValue();
                        if(text.contains("!if:")) {
                            if(Boolean.valueOf(PoiElUtil.eval(text.substring(text.indexOf("{{") + 2, text.indexOf("}}")).trim(), map).toString()).booleanValue()) {
                                PoiSheetUtility.deleteColumn(sheet, i);
                            }
    
                            cell.setCellValue("");
                        }
                    }
                }
            }
        }
    
        private void setValueForCellByMap(Cell cell, Map<String, Object> map) throws Exception {
            int cellType = cell.getCellType();
            if(cellType == 1 || cellType == 0) {
                cell.setCellType(1);
                String oldString = cell.getStringCellValue();
                if(oldString != null && oldString.indexOf("{{") != -1 && !oldString.contains("fe:")) {
                    Object params = null;
                    boolean isNumber = false;
                    if(this.isNumber(oldString)) {
                        isNumber = true;
                        oldString = oldString.replaceFirst("n:", "");
                    }
    
                    Object obj = PoiPublicUtil.getRealValue(oldString, map);
                    if(obj instanceof ImageEntity) {
                        ImageEntity img = (ImageEntity)obj;
                        cell.setCellValue("");
                        if(img.getUrl().indexOf(".")!=-1){
                            this.createImageCell(cell, (double)img.getHeight(), img.getUrl(), img.getData());
                        }
                    } else if(isNumber && StringUtils.isNotBlank(obj.toString())) {
                        cell.setCellValue(Double.parseDouble(obj.toString()));
                        cell.setCellType(0);
                    } else {
                        cell.setCellValue(obj.toString());
                    }
                }
    
                if(oldString != null && oldString.contains("fe:")) {
                    this.addListDataToExcel(cell, map, oldString.trim());
                }
    
            }
        }
    
    
        public void createImageCell(Cell cell, double height, String imagePath, byte[] data) throws Exception {
            if(height > (double)cell.getRow().getHeight()) {
                cell.getRow().setHeight((short)((int)height));
            }
            //获取当前单元格所在的sheet
            Sheet sheet = cell.getRow().getSheet();
            //获取当前sheet页中的所有合并单元格信息
            List<CellRangeAddress> mergedRegions = sheet.getMergedRegions();
            //获取当前单元格的开始列号
            int firstColumn = (short)cell.getColumnIndex();
            //获取当前单元格的开始行号
            int firstRow = cell.getRow().getRowNum();
            //获取当前单元格的结束列号
            int lastColumn = (short)(cell.getColumnIndex());
            //获取当前单元格的结束行号
            int lastRow = cell.getRow().getRowNum();
            for(CellRangeAddress mergedRegion : mergedRegions){
                //判断当前单元格是否包含合并行或和并列 当前单元格的所有行号和列号都包含在合并域内 则认为当前单元格存在合并行或和并列
                if(cell.getColumnIndex()>=mergedRegion.getFirstColumn()
                        && cell.getColumnIndex()<=mergedRegion.getLastColumn()
                        && cell.getRow().getRowNum()>=mergedRegion.getFirstRow()
                        && cell.getRow().getRowNum()<=mergedRegion.getLastRow()){
                    //获取合并域的开始行号
                    firstRow = mergedRegion.getFirstRow();
                    //获取合并域的结束行号
                    lastRow = mergedRegion.getLastRow();
                    //获取合并域的开始列号
                    firstColumn = mergedRegion.getFirstColumn();
                    //获取合并域的结束列号
                    lastColumn = mergedRegion.getLastColumn();
                    break;
                }
            }
    
            Object anchor;
            if(this.type.equals(ExcelType.HSSF)) {
                anchor = new HSSFClientAnchor(0, 0, 0, 0, (short)firstColumn, firstRow, (short)(lastColumn+1), lastRow+1);
            } else {
                anchor = new XSSFClientAnchor(0, 0, 0, 0, (short)firstColumn, firstRow, (short)(lastColumn+1), lastRow+1);
            }
    
            if(StringUtils.isNotEmpty(imagePath)) {
                data = ImageCache.getImage(imagePath);
            }
    
            if(data != null) {
                PoiExcelGraphDataUtil.getDrawingPatriarch(cell.getSheet()).createPicture((ClientAnchor)anchor, cell.getSheet().getWorkbook().addPicture(data, this.getImageType(data)));
            }
    
        }
    
        private boolean isNumber(String text) {
            return text.startsWith("n:") || text.contains("{n:") || text.contains(" n:");
        }
    
        private void addListDataToExcel(Cell cell, Map<String, Object> map, String name) throws Exception {
            boolean isCreate = !name.contains("!fe:");
            boolean isShift = name.contains("$fe:");
            name = name.replace("!fe:", "").replace("$fe:", "").replace("fe:", "").replace("{{", "");
            String[] keys = name.replaceAll("\\s{1,}", " ").trim().split(" ");
            Collection datas = (Collection)PoiPublicUtil.getParamsValue(keys[0], map);
            Object[] columnsInfo = this.getAllDataColumns(cell, name.replace(keys[0], ""), this.mergedRegionHelper);
            if(datas != null) {
                Iterator its = datas.iterator();
                int rowspan = ((Integer)columnsInfo[0]).intValue();
                int colspan = ((Integer)columnsInfo[1]).intValue();
                List columns = (List)columnsInfo[2];
                Row row = null;
                int rowIndex = cell.getRow().getRowNum() + 1;
                Object t;
                if(its.hasNext()) {
                    t = its.next();
                    this.setForEeachRowCellValue(isCreate, cell.getRow(), cell.getColumnIndex(), t, columns, map, rowspan, colspan, this.mergedRegionHelper);
                    rowIndex += rowspan - 1;
                }
    
                if(isShift && datas.size() * rowspan > 1 && cell.getRowIndex() + rowspan < cell.getRow().getSheet().getLastRowNum()) {
                    this.createRowNoRow(cell.getRowIndex() + rowspan, cell.getRow().getSheet().getLastRowNum(), (datas.size() - 1) * rowspan);
                    cell.getRow().getSheet().shiftRows(cell.getRowIndex() + rowspan, cell.getRow().getSheet().getLastRowNum(), (datas.size() - 1) * rowspan, true, true);
                    this.templateSumHanlder.shiftRows(cell.getRowIndex(), (datas.size() - 1) * rowspan);
                }
    
                while(its.hasNext()) {
                    t = its.next();
                    row = this.createRow(rowIndex, cell.getSheet(), isCreate, rowspan);
                    this.setForEeachRowCellValue(isCreate, row, cell.getColumnIndex(), t, columns, map, rowspan, colspan, this.mergedRegionHelper);
                    rowIndex += rowspan;
                }
    
            }
        }
    
        private void createRowNoRow(int startRow, int lastRowNum, int i1) {
        }
    
        private Row createRow(int rowIndex, Sheet sheet, boolean isCreate, int rows) {
            for(int i = 0; i < rows; ++i) {
                if(isCreate) {
                    sheet.createRow(rowIndex++);
                } else if(sheet.getRow(rowIndex++) == null) {
                    sheet.createRow(rowIndex - 1);
                }
            }
    
            return sheet.getRow(rowIndex - rows);
        }
    
        private void setForEeachRowCellValue(boolean isCreate, Row row, int columnIndex, Object t, List<ExcelForEachParams> columns, Map<String, Object> map, int rowspan, int colspan, MergedRegionHelper mergedRegionHelper) throws Exception {
            int k;
            int ci;
            int i;
            for(int params = 0; params < rowspan; ++params) {
                k = columns.size();
                ci = columnIndex;
    
                for(i = columnIndex + colspan; ci < i; ++ci) {
                    if(row.getCell(ci) == null) {
                        row.createCell(ci);
                        CellStyle isNumber = row.getRowNum() % 2 == 0?this.getStyles(false, k >= ci - columnIndex?null:(ExcelForEachParams)columns.get(ci - columnIndex)):this.getStyles(true, k >= ci - columnIndex?null:(ExcelForEachParams)columns.get(ci - columnIndex));
                        if(isNumber != null) {
                            row.getCell(ci).setCellStyle(isNumber);
                        }
                    }
                }
    
                if(params < rowspan - 1) {
                    row = row.getSheet().getRow(row.getRowNum() + 1);
                }
            }
    
            row = row.getSheet().getRow(row.getRowNum() - rowspan + 1);
    
            for(k = 0; k < rowspan; ++k) {
                ci = columnIndex;
                row.setHeight(((ExcelForEachParams)columns.get(0 * colspan)).getHeight());
    
                for(i = 0; i < colspan && i < columns.size(); ++i) {
                    boolean var19 = false;
                    ExcelForEachParams var18 = (ExcelForEachParams)columns.get(colspan * k + i);
                    this.tempCreateCellSet.add(row.getRowNum() + "_" + ci);
                    if(var18 != null) {
                        if(StringUtils.isEmpty(var18.getName()) && StringUtils.isEmpty(var18.getConstValue())) {
                            row.getCell(ci).setCellStyle(((ExcelForEachParams)columns.get(i)).getCellStyle());
                            ci += ((ExcelForEachParams)columns.get(i)).getColspan();
                        } else {
                            String val = null;
                            if(StringUtils.isEmpty(var18.getName())) {
                                val = var18.getConstValue();
                            } else {
                                String e = new String(var18.getName());
                                if(this.isNumber(e)) {
                                    var19 = true;
                                    e = e.replaceFirst("n:", "");
                                }
    
                                map.put(this.teplateParams.getTempParams(), t);
                                val = PoiElUtil.eval(e, map).toString();
                            }
    
                            if(var19 && StringUtils.isNotEmpty(val)) {
                                row.getCell(ci).setCellValue(Double.parseDouble(val));
                                row.getCell(ci).setCellType(0);
                            } else {
                                try {
                                    row.getCell(ci).setCellValue(val);
                                } catch (Exception var17) {
                                    LOGGER.error(var17.getMessage(), var17);
                                }
                            }
    
                            row.getCell(ci).setCellStyle(((ExcelForEachParams)columns.get(i)).getCellStyle());
                            if(var18.isNeedSum()) {
                                this.templateSumHanlder.addValueOfKey(var18.getName(), val);
                            }
    
                            this.setMergedRegionStyle(row, ci, (ExcelForEachParams)columns.get(i));
                            if((var18.getRowspan() != 1 || var18.getColspan() != 1) && !mergedRegionHelper.isMergedRegion(row.getRowNum() + 1, ci)) {
                                row.getSheet().addMergedRegion(new CellRangeAddress(row.getRowNum(), row.getRowNum() + var18.getRowspan() - 1, ci, ci + var18.getColspan() - 1));
                            }
    
                            ci += var18.getColspan();
                        }
                    }
                }
    
                row = row.getSheet().getRow(row.getRowNum() + 1);
            }
    
        }
    
        private CellStyle getStyles(boolean isSingle, ExcelForEachParams excelForEachParams) {
            return this.excelExportStyler.getTemplateStyles(isSingle, excelForEachParams);
        }
    
        private void setMergedRegionStyle(Row row, int ci, ExcelForEachParams params) {
            int i;
            for(i = 1; i < params.getColspan(); ++i) {
                row.getCell(ci + i).setCellStyle(params.getCellStyle());
            }
    
            for(i = 1; i < params.getRowspan(); ++i) {
                for(int j = 0; j < params.getColspan(); ++j) {
                    row.getCell(ci + j).setCellStyle(params.getCellStyle());
                }
            }
    
        }
    
        private Object[] getAllDataColumns(Cell cell, String name, MergedRegionHelper mergedRegionHelper) {
            ArrayList columns = new ArrayList();
            cell.setCellValue("");
            columns.add(this.getExcelTemplateParams(name.replace("}}", ""), cell, mergedRegionHelper));
            int rowspan = 1;
            int colspan = 1;
            int i;
            if(!name.contains("}}")) {
                i = cell.getColumnIndex();
                int startIndex = cell.getColumnIndex();
                Row row = cell.getRow();
    
                label70:
                while(true) {
                    while(true) {
                        int colSpan = columns.get(columns.size() - 1) != null?((ExcelForEachParams)columns.get(columns.size() - 1)).getColspan():1;
                        i += colSpan;
    
                        for(int cellStringString = 1; cellStringString < colSpan; ++cellStringString) {
                            columns.add((Object)null);
                        }
    
                        cell = row.getCell(i);
                        if(cell == null) {
                            columns.add((Object)null);
                        } else {
                            String var14;
                            try {
                                var14 = cell.getStringCellValue();
                                if(StringUtils.isBlank(var14) && colspan + startIndex <= i) {
                                    throw new ExcelExportException("for each 当中存在空字符串,请检查模板");
                                }
    
                                if(StringUtils.isBlank(var14) && colspan + startIndex > i) {
                                    columns.add(new ExcelForEachParams((String)null, cell.getCellStyle(), (short) 0));
                                    continue;
                                }
                            } catch (Exception var13) {
                                throw new ExcelExportException(ExcelExportEnum.TEMPLATE_ERROR, var13);
                            }
    
                            cell.setCellValue("");
                            if(var14.contains("}}")) {
                                columns.add(this.getExcelTemplateParams(var14.replace("}}", ""), cell, mergedRegionHelper));
                                break label70;
                            }
    
                            if(var14.contains("]]")) {
                                columns.add(this.getExcelTemplateParams(var14.replace("]]", ""), cell, mergedRegionHelper));
                                colspan = i - startIndex + 1;
                                i = startIndex - 1;
                                row = row.getSheet().getRow(row.getRowNum() + 1);
                                ++rowspan;
                            } else {
                                columns.add(this.getExcelTemplateParams(var14.replace("]]", ""), cell, mergedRegionHelper));
                            }
                        }
                    }
                }
            }
    
            colspan = 0;
    
            for(i = 0; i < columns.size(); ++i) {
                colspan += columns.get(i) != null?((ExcelForEachParams)columns.get(i)).getColspan():0;
            }
    
            colspan /= rowspan;
            return new Object[]{Integer.valueOf(rowspan), Integer.valueOf(colspan), columns};
        }
    
        private ExcelForEachParams getExcelTemplateParams(String name, Cell cell, MergedRegionHelper mergedRegionHelper) {
            name = name.trim();
            ExcelForEachParams params = new ExcelForEachParams(name, cell.getCellStyle(), cell.getRow().getHeight());
            if(name.startsWith("\'") && name.endsWith("\'")) {
                params.setName((String)null);
                params.setConstValue(name.substring(1, name.length() - 1));
            }
    
            if("&NULL&".equals(name)) {
                params.setName((String)null);
                params.setConstValue("");
            }
    
            if(mergedRegionHelper.isMergedRegion(cell.getRowIndex() + 1, cell.getColumnIndex())) {
                Integer[] colAndrow = mergedRegionHelper.getRowAndColSpan(cell.getRowIndex() + 1, cell.getColumnIndex());
                params.setRowspan(colAndrow[0].intValue());
                params.setColspan(colAndrow[1].intValue());
            }
    
            params.setNeedSum(this.templateSumHanlder.isSumKey(params.getName()));
            return params;
        }
    
        private void sortAndFilterExportField(List<ExcelExportEntity> excelParams, Map<String, Integer> titlemap) {
            for(int i = excelParams.size() - 1; i >= 0; --i) {
                if(((ExcelExportEntity)excelParams.get(i)).getList() != null && ((ExcelExportEntity)excelParams.get(i)).getList().size() > 0) {
                    this.sortAndFilterExportField(((ExcelExportEntity)excelParams.get(i)).getList(), titlemap);
                    if(((ExcelExportEntity)excelParams.get(i)).getList().size() == 0) {
                        excelParams.remove(i);
                    } else {
                        ((ExcelExportEntity)excelParams.get(i)).setOrderNum(i);
                    }
                } else if(titlemap.containsKey(((ExcelExportEntity)excelParams.get(i)).getName())) {
                    ((ExcelExportEntity)excelParams.get(i)).setOrderNum(i);
                } else {
                    excelParams.remove(i);
                }
            }
    
            this.sortAllParams(excelParams);
        }
    
        public Workbook createExcleByTemplate(TemplateExportParams params, Map<Integer, Map<String, Object>> map) {
            if(params != null && map != null && !StringUtils.isEmpty(params.getTemplateUrl())) {
                Workbook wb = null;
    
                try {
                    this.teplateParams = params;
                    wb = this.getCloneWorkBook();
                    int e = 0;
    
                    for(int le = params.isScanAllsheet()?wb.getNumberOfSheets():params.getSheetNum().length; e < le; ++e) {
                        if(params.getSheetName() != null && params.getSheetName().length > e && StringUtils.isNotEmpty(params.getSheetName()[e])) {
                            wb.setSheetName(e, params.getSheetName()[e]);
                        }
    
                        this.tempCreateCellSet.clear();
                        this.parseTemplate(wb.getSheetAt(e), (Map)map.get(Integer.valueOf(e)), params.isColForEach());
                    }
    
                    return wb;
                } catch (Exception var6) {
                    LOGGER.error(var6.getMessage(), var6);
                    return null;
                }
            } else {
                throw new ExcelExportException(ExcelExportEnum.PARAMETER_ERROR);
            }
        }
    }
    
    
    展开全文
  • 今天做导出Excel的时候遇到了一个单元格中需要导出多张图片的需求。之前也做过很多的导出Excel,网上研究了很久,总算导出成功了,但是还是有一点点的小瑕疵,就是根据图片的缩略图计算出单元格的宽高。希望有做过...
  • datagridview 一个单元格显示文字和图片 文字超出时显示... private void dgv_Test_CellPainting(object sender, DataGridViewCellPaintingEventArgs e) {/**/ if (e.ColumnIndex >= 0 && e.RowIndex = 0)
  • cxGrid单元格内显示图片和文本

    千次阅读 2014-07-16 17:51:12
    cxGrid单元格内显示图片和文本,效果
  • 判断当前单元格是否包含合并行或和并列 当前单元格的所有行号和列号都包含合并域 则认为当前单元格存在合并行或和并列 19 if (cell.getColumnIndex()>= mergedRegion.getFirstColumn() 20 && cell....
  • ![图片说明](https://img-ask.csdn.net/upload/201711/29/1511937678_781680.png) 注意:是同一个单元格中插入多个图片和文字,而不是不同单元格
  • EPPLUS读取指定单元格内图片

    千次阅读 2020-09-16 11:44:45
    百度,google找了好一会儿没找到怎么获取指定单元格内图片,只能自己研究了 添加引用 using OfficeOpenXml; using System.IO; using System.Linq; 完整代码 using (ExcelPackage pck = new ExcelPackage(path...
  • 原文链接 示例操作步骤如下: 1、首先打开duWORD文档,...6、再单元格中,单击鼠标右键选择”表格性“。 7、弹出的对话框中打开右下方的”选项“。 8、小窗口中再将上下左右边距设置为0,并勾选”..
  • Excel里面删除单元格内图片

    千次阅读 2016-12-19 21:44:19
    excel 单元格内粘贴入一个图片(或者说是一个嵌入对象),从网页上粘贴的 无法删除 解决办法 F5(ctrl G) 定位条件 对象 delete 1,选定 2,F5 3, 4,确定后,直接delete,OK 谢谢 from :...
  • ![图片说明](https://img-ask.csdn.net/upload/201507/02/1435806350_8141.jpg) 就向我图片上选中的那段文字一样,我怎么只给那段文字加下划线,求大神指点啊
  • 我用canvas画了一个表格,我想点击表格里一点,点击的那一点哪个单元格,怎么判断,有大神给点思路。![图片说明](https://img-ask.csdn.net/upload/201607/27/1469598966_806184.png)
  • 如何gridControl1 一个单元格中同时显示图片和文字? <br /> <br />???
  • 描述:Excel2019单元格插入图片位置大小随单元格变化 步骤: 复制图片到Excel2019单元格 调整图片到合适大小 双击图片,菜单栏会出现 图片工具格式 找到对齐,选择对齐网格 将图片对齐单元格 右键图片,选择...
  • 一般导出Excel中,创建工作表sheet后,初始化的sheet中row都是行的,每个单元格都是最小单位,所以问题1什么时候将单元格合并? 方案:先将数据组装成json格式方便插入Excel时进行遍历,接着以巡检项为每...
  • 如何把图片插入Excel的一个单元格

    千次阅读 2011-10-14 12:01:47
    前段时间做了用于winform的excel的插件程序,将从数据库中的image字段读出来后显示excel中,csdn上见过好几提出这方面的问题,现将我的部分代码贴出来,分享给有需要的朋友。 我的这是excel的插件程序,...
  • 有时数据库的表字段中存储的是图片的URL,我们又需要在单元格内引入此字段URL对应的图片,这时我们可以设置单元格类型为HTML来解决,我们来看一个简单的例子: 第一步:新建建数据集如下, 第二步:...
  • WORD里面如何让图片铺满整个单元格

    千次阅读 2014-04-19 13:11:58
    先插入图片再选中图片 —— 格式 —— 图片 —— 版式 —— 衬于文字下方 —— 高级 —— 图片位置 —— 水平对齐 —— 绝对位置栏选 “ 页面 ”—— 右侧值设为 0 —— 垂直对齐 —— ...
  • 我们有时需要当鼠标移到某单元格内时,显示单元格对应的图片,此小程序可用。要求图片名称与单元格内容一致,方可插入。
  • 1. 详细步骤见Excel单元格内插入图片(VBA创建函数,根据图片名称批量插入)2. VBA代码部分改为如下代码Sub 插入图形应用() For Each shap In Sheet1.Shapes If shap.Type &lt;&gt; 8 Then shap.Delete ...
  • excel空白单元格自动下下填充上一个单元格的值 适用情况 图片: [外链图片转存失败(img-PLzkQDdz-1566355138598)(]) vba代码 Sub test() Set sh = ActiveSheet i = 1 Text = sh.Cells(i, 4) '(i,j) i 代表行数 j代表...
  • java 语言 poi可以把图片插入到word 表格中的单元格内吗。另外求插入姿势方法
  • 比如我Sheet2中定义了几数据,这些都是简单的数字,而Sheet1中要被绑定的单元格等于Sheet2的对应单元格地址(比如Sheet2!B1,Sheet2!B2之类的)  然后就可以改全改了。但是我还要对当前的Sheet1...
  • 如何实现图片填满单元格

    千次阅读 2020-11-23 04:27:22
    大家可能经常需要工作表单元格中插入图片,为了满足OCD领导的要求,图片一定要占满整个单元格, 录制宏得到的代码,会存在过度缩放的问题,不同比率图片需要进一步调整代码。

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 66,350
精华内容 26,540
关键字:

如何让图片在一个单元格内