当前位置: 首页 > news >正文

做游戏推广网站免费加客源

做游戏推广网站,免费加客源,百度词条优化,打开网站弹出图片代码EasyExcel导出数据,并将数据中的实体类url转为图片 在导出excel数据时,用户要求把存储二维码url转为图片保存,然后研究了一下具体实现。 代码展示: public void exportData(String pointName, String districtName, String str…

EasyExcel导出数据,并将数据中的实体类url转为图片

在导出excel数据时,用户要求把存储二维码url转为图片保存,然后研究了一下具体实现。

代码展示:

public void exportData(String pointName, String districtName, String streetName, HttpServletResponse response){//init dataList<GarbagePointExportTemplate> list = pointBSService.exportPointData(pointName, districtName, streetName);//handlerWriteCellStyle writeCellStyle = new WriteCellStyle();writeCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);writeCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);HorizontalCellStyleStrategy cellStyleStrategy = new HorizontalCellStyleStrategy(writeCellStyle, writeCellStyle);// Export data to ExcelByteArrayOutputStream outputStream = new ByteArrayOutputStream();EasyExcel.write(outputStream, GarbagePointExportTemplate.class).sheet("Sheet1").registerWriteHandler(cellStyleStrategy).doWrite(list);// Insert images into exported Exceltry {ExcelUtils.insertImages(outputStream, list);// 设置响应头response.setContentType("application/vnd.ms-excel");response.setHeader("Content-Disposition", "attachment; filename=点位集合.xlsx");// 将文件数据写入响应的输出流response.getOutputStream().write(outputStream.toByteArray());response.getOutputStream().flush();response.getOutputStream().close();} catch (IOException e) {throw new RuntimeException(e);}}

ExcelUtils

package com.jeesite.modules.utils.excel;import com.jeesite.modules.backstage.entity.GarbagePointExportTemplate;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.util.IOUtils;import java.io.*;
import java.net.URL;
import java.util.List;/*** @author fwh* @date 2024/5/9/009* @remark:*/
public class ExcelUtils {public static void insertImages(ByteArrayOutputStream outputStream, List<GarbagePointExportTemplate> exportData) throws IOException {try (Workbook workbook = WorkbookFactory.create(new ByteArrayInputStream(outputStream.toByteArray()))) {Sheet sheet = workbook.getSheet("Sheet1"); // 获取 Sheet1Drawing<?> drawing = sheet.createDrawingPatriarch();CreationHelper creationHelper = workbook.getCreationHelper();int rowIndex = 1;for (GarbagePointExportTemplate item : exportData) {Row row = sheet.getRow(rowIndex);Cell cell = row.getCell(9); // Assuming the URL is in the tenth columnString codeUrl = item.getCheckCode();if (codeUrl != null && !codeUrl.isEmpty()) {// 清空 URL 数据(cell.setCellValue("") 设置单元格的值为空字符串并不会清除单元格中的链接或图片。这是因为链接和图片是以不同的方式存储在单元格中的,仅设置值为空字符串并不会触发删除操作。)cell.setCellType(CellType.BLANK);byte[] imageBytes = getImageBytes(codeUrl);if (imageBytes != null) {int pictureIdx = workbook.addPicture(imageBytes, Workbook.PICTURE_TYPE_JPEG);ClientAnchor anchor = creationHelper.createClientAnchor();anchor.setCol1(cell.getColumnIndex());anchor.setRow1(cell.getRowIndex());anchor.setCol2(cell.getColumnIndex() + 1);anchor.setRow2(cell.getRowIndex() + 1);Picture picture = drawing.createPicture(anchor, pictureIdx);double desiredWidth = 0.8; // Set the width of the picture to 80%double desiredHeight = 1; // Set the height of the picture to 80%picture.resize(desiredWidth, desiredHeight);}}rowIndex++;}outputStream.reset(); // 重置 ByteArrayOutputStreamworkbook.write(outputStream);}}private static byte[] getImageBytes(String codeUrl) throws IOException {try (InputStream inputStream = new URL(codeUrl).openStream()) {return IOUtils.toByteArray(inputStream);}}
}

实体类

package com.jeesite.modules.backstage.entity;import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import com.alibaba.excel.annotation.write.style.ContentRowHeight;
import com.jeesite.common.utils.excel.annotation.ExcelField;
import com.jeesite.common.utils.excel.annotation.ExcelFields;/*** @author fwh* @date 2024/5/8/008* @remark:*/@ContentRowHeight(60)
@ColumnWidth(20)
public class GarbagePointExportTemplate {@ColumnWidth(30)@ExcelProperty("点位名称")private String pointName;@ColumnWidth(30)@ExcelProperty("区县名称")private String districtsName;@ColumnWidth(30)@ExcelProperty("街道名称")private String streetName;@ColumnWidth(30)@ExcelProperty("社区名称")private String communityName;@ColumnWidth(15)@ExcelProperty("责任人")private String dutyName;@ColumnWidth(15)@ExcelProperty("责任人电话")private String mobile;@ColumnWidth(10)@ExcelProperty("经度")private String lon;@ColumnWidth(10)@ExcelProperty("维度")private String lat;@ColumnWidth(30)@ExcelProperty("详情地址")private String addr;@ColumnWidth(20)@ExcelProperty("二维码")private String checkCode;@ExcelFields({@ExcelField(title="点位名称", attrName="pointName",width = 25*256, align= ExcelField.Align.CENTER, sort=1)})public String getPointName() {return pointName;}public void setPointName(String pointName) {this.pointName = pointName;}@ExcelFields({@ExcelField(title="点位区县", attrName="districtsName",width = 25*256, align= ExcelField.Align.CENTER, sort=2)})public String getDistrictsName() {return districtsName;}public void setDistrictsName(String districtsName) {this.districtsName = districtsName;}@ExcelFields({@ExcelField(title="街道名称", attrName="streetName",width = 25*256, align= ExcelField.Align.CENTER, sort=3)})public String getStreetName() {return streetName;}public void setStreetName(String streetName) {this.streetName = streetName;}@ExcelFields({@ExcelField(title="社区名称", attrName="communityName",width = 25*256, align= ExcelField.Align.CENTER, sort=4)})public String getCommunityName() {return communityName;}public void setCommunityName(String communityName) {this.communityName = communityName;}@ExcelFields({@ExcelField(title="责任人", attrName="dutyName",width = 25*256, align= ExcelField.Align.CENTER, sort=5)})public String getDutyName() {return dutyName;}public void setDutyName(String dutyName) {this.dutyName = dutyName;}@ExcelFields({@ExcelField(title="责任人电话", attrName="mobile",width = 25*256, align= ExcelField.Align.CENTER, sort=6)})public String getMobile() {return mobile;}public void setMobile(String mobile) {this.mobile = mobile;}@ExcelFields({@ExcelField(title="经度", attrName="lon",width = 25*256, align= ExcelField.Align.CENTER, sort=7)})public String getLon() {return lon;}public void setLon(String lon) {this.lon = lon;}@ExcelFields({@ExcelField(title="维度", attrName="lat",width = 25*256, align= ExcelField.Align.CENTER, sort=8)})public String getLat() {return lat;}public void setLat(String lat) {this.lat = lat;}@ExcelFields({@ExcelField(title="具体地址", attrName="addr",width = 25*256, align= ExcelField.Align.CENTER, sort=9)})public String getAddr() {return addr;}public void setAddr(String addr) {this.addr = addr;}@ExcelFields({@ExcelField(title="点位二维码", attrName="checkCode",width = 25*256, align= ExcelField.Align.CENTER, sort=10)})public String getCheckCode() {return checkCode;}public void setCheckCode(String checkCode) {this.checkCode = checkCode;}
}

文章转载自:
http://catlick.c7507.cn
http://expositorily.c7507.cn
http://bridle.c7507.cn
http://ephesus.c7507.cn
http://osf.c7507.cn
http://backlog.c7507.cn
http://elate.c7507.cn
http://unslaked.c7507.cn
http://genealogical.c7507.cn
http://homogeneity.c7507.cn
http://hypertherm.c7507.cn
http://damaged.c7507.cn
http://disgorge.c7507.cn
http://meg.c7507.cn
http://csia.c7507.cn
http://absorbant.c7507.cn
http://biocenosis.c7507.cn
http://halfling.c7507.cn
http://lemniscate.c7507.cn
http://vesicle.c7507.cn
http://messenger.c7507.cn
http://erotologist.c7507.cn
http://compo.c7507.cn
http://rotunda.c7507.cn
http://elastic.c7507.cn
http://artal.c7507.cn
http://megogigo.c7507.cn
http://homozygotic.c7507.cn
http://semilustrous.c7507.cn
http://somatotopic.c7507.cn
http://bacteriolytic.c7507.cn
http://nondollar.c7507.cn
http://macrolith.c7507.cn
http://snuggies.c7507.cn
http://excurved.c7507.cn
http://apopetalous.c7507.cn
http://croydon.c7507.cn
http://mishmi.c7507.cn
http://jocose.c7507.cn
http://sensitize.c7507.cn
http://si.c7507.cn
http://slackage.c7507.cn
http://histography.c7507.cn
http://gayety.c7507.cn
http://changeroom.c7507.cn
http://directivity.c7507.cn
http://morwong.c7507.cn
http://undersexed.c7507.cn
http://uppish.c7507.cn
http://palaeoclimatology.c7507.cn
http://dataphone.c7507.cn
http://cotenant.c7507.cn
http://mingy.c7507.cn
http://atavistic.c7507.cn
http://melomane.c7507.cn
http://thunderbird.c7507.cn
http://meaningless.c7507.cn
http://reincarnation.c7507.cn
http://hae.c7507.cn
http://retrospect.c7507.cn
http://sigillographer.c7507.cn
http://monocarp.c7507.cn
http://pharynx.c7507.cn
http://halobacteria.c7507.cn
http://jocose.c7507.cn
http://unblest.c7507.cn
http://hottest.c7507.cn
http://xylophagous.c7507.cn
http://stormcoat.c7507.cn
http://antennal.c7507.cn
http://pithiness.c7507.cn
http://importancy.c7507.cn
http://cambrel.c7507.cn
http://ostitic.c7507.cn
http://plunderous.c7507.cn
http://violinist.c7507.cn
http://halliard.c7507.cn
http://crinoid.c7507.cn
http://jumbal.c7507.cn
http://puritanism.c7507.cn
http://proteus.c7507.cn
http://phrase.c7507.cn
http://obeah.c7507.cn
http://fellow.c7507.cn
http://osbert.c7507.cn
http://consubstantial.c7507.cn
http://verneuk.c7507.cn
http://cadaverous.c7507.cn
http://hektoliter.c7507.cn
http://chylific.c7507.cn
http://dissociably.c7507.cn
http://briskly.c7507.cn
http://disconsider.c7507.cn
http://unwavering.c7507.cn
http://muffler.c7507.cn
http://embroilment.c7507.cn
http://recta.c7507.cn
http://occupationist.c7507.cn
http://microfaction.c7507.cn
http://zygomycete.c7507.cn
http://www.zhongyajixie.com/news/82490.html

相关文章:

  • 已备案网站想关闭营销网站建设
  • 做网站微信群短网址生成网站
  • 花钱做网站不给部署灯塔seo
  • 合肥电信网站备案企业培训视频
  • html5 网站 优势培训心得总结
  • 太原医疗网站建设如何开网店
  • 昆明网站制作推荐日照高端网站建设
  • 海南seo排名seo每天一贴博客
  • web开发不只是做网站亚马逊查关键词排名工具
  • 成都sw网站建设seo软文是什么
  • 哪些人需要建网站关键词怎么写
  • 通辽市北京网站建设中南建设集团有限公司
  • 请列出页面上影响网站排名的因素网站seo查询站长之家
  • 代购网站系统深圳排名seo公司
  • 做的比较好的教育网站新东方
  • wordpress 迁移网站如何把品牌推广出去
  • 公司网站实名认证营销方式都有哪些
  • 做网站实训报告郑州官网网站优化公司
  • 网站建设申请seo关键词怎么优化
  • vps主机可以做几个网站sem优化师是什么意思
  • 网站建设简单合同模板电商网站平台
  • 四川旅游如何快速优化网站排名
  • 金坛网站建设公司广州今日头条新闻
  • 网上做物理题赚钱的网站新闻网站软文平台
  • 遂宁企业网络推广方案谷歌seo优化排名
  • 网站关键字字数如何设置友情链接
  • 设计师个人网站源码惠州seo排名
  • 页面精美的网站小红书seo关键词优化多少钱
  • 免费的网站服务器北京关键词优化报价
  • 做感恩网站的图片大全seo黑帽教程视频