excelize icon indicating copy to clipboard operation
excelize copied to clipboard

Support insert the Kingsoft WPS Office embedded image cells via the DISPIMG formula function

Open LinLiang66 opened this issue 1 year ago • 2 comments

有些业务场景需要将图片嵌入到单元格内,因为如果图片浮动在单元格上面的话,业务筛选的时候会特别卡,甚至筛选后图片对位置混乱, 支持将图片嵌入到单元格后会很好的解决这一重大资源占用问题

LinLiang66 avatar Apr 09 '24 10:04 LinLiang66

Thanks for your issue. Sorry, there no plan to add this feature recently, but I'll certainly accept that patch if somebody did that. Note that, please enable the AutoFit options to make picture size fit with the cell when inserting pictures

xuri avatar Apr 10 '24 01:04 xuri

`

func HandleExcel(fileBytes []byte, fileheader *multipart.FileHeader) { newFile := bytes.NewReader(fileBytes) f, err := excelize.OpenReader(newFile) if err != nil { return } sheetIndex := 1 // 假设要获取第1个工作表(下标从0开始) sheetName := f.GetSheetName(sheetIndex) rows, err := f.GetRows(sheetName) columnMap := make(map[string]int) pro := "AC" for i, header := range rows[0] { columnMap[header] = i + 1 // 行号从1开始,所以加1 if header == "申诉凭证" { pro = NumToExcelCol(i + 1) } }

for i, row := range rows[1:] {
	waybillNo := row[columnMap["快递单号"]-1]
	resp, err := http.Get("http://101.227.48.127:81/img/weightimg?waybillNo=" + waybillNo)
	if err != nil {
		continue
	}
	if !strings.HasPrefix(resp.Header.Get("Content-Type"), "image/png") {
		continue
	}
	body, err := io.ReadAll(resp.Body)
	if err != nil {
		continue
	}
	if err := f.AddPictureFromBytes(sheetName, pro+strconv.Itoa(i+2), &excelize.Picture{
		Extension: ".png",
		File:      body,
		Format: &excelize.GraphicOptions{
			AutoFit: true,
		},
	}); err != nil {
		continue
	}
}
Filename := strconv.FormatInt(time.Now().Unix()/1000, 10) + fileheader.Filename
filePath := "/gofile/" + Filename
if err := f.SaveAs(filePath); err != nil {
	fmt.Println("保存文件失败" + err.Error())
}

}

`

#Yes, the current method is to insert the picture, download it to the local area, open the selected picture through WPS, and right-click to embed the cell.

LinLiang66 avatar Apr 13 '24 02:04 LinLiang66