Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
LinLiang66 opened this issue Apr 9, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@LinLiang66
Copy link

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

@xuri xuri changed the title 请问 有计划支持插入图片到单元格并嵌入到单元格吗【Kingsoft WPS™ Office】 Support the Kingsoft WPS Office embedded image cells via the DISPIMG formula function Apr 10, 2024
@xuri xuri added the enhancement New feature or request label Apr 10, 2024
@xuri
Copy link
Member

xuri commented Apr 10, 2024

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

@LinLiang66
Copy link
Author

LinLiang66 commented Apr 13, 2024

`

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.

@xuri xuri changed the title Support the Kingsoft WPS Office embedded image cells via the DISPIMG formula function Support insert the Kingsoft WPS Office embedded image cells via the DISPIMG formula function Apr 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants