origin导出高质量清晰图片

origin导出高质量清晰图片

  1. 文件-导出图-打开对话框
  2. 选择图像类型为tif,选择图像设置的DIP为600
    在这里插入图片描述
  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
如果要在导出的 Excel 中包含图片,可以使用 "xlsx-populate" 库和 "jszip" 库。以下是一个示例: 1. 首先,安装 "xlsx-populate" 和 "jszip" 库: ``` npm install xlsx-populate jszip --save ``` 2. 然后,在组件中引入库: ``` import XlsxPopulate from "xlsx-populate"; import JSZip from "jszip"; ``` 3. 在组件中定义数据和图片: ``` const data = [ ["Name", "Age", "Gender", "Image"], ["John Doe", 30, "Male", "image1"], ["Jane Smith", 25, "Female", "image2"], ["Bob Johnson", 50, "Male", "image3"] ]; const images = { image1: "https://example.com/image1.jpg", image2: "https://example.com/image2.jpg", image3: "https://example.com/image3.jpg" }; ``` 4. 在组件中添加导出按钮,并定义导出函数: ``` async function exportToExcel() { const workbook = await XlsxPopulate.fromBlankAsync(); // 添加工作表 const sheet = workbook.addSheet("Sheet1"); // 添加表头 sheet.cell("A1").value("Name"); sheet.cell("B1").value("Age"); sheet.cell("C1").value("Gender"); sheet.cell("D1").value("Image"); // 添加数据和图片 data.forEach((row, rowIndex) => { row.forEach((cell, cellIndex) => { if (cellIndex === 3) { // 添加图片 const img = new Image(); img.crossOrigin = "Anonymous"; img.src = images[cell]; const promise = new Promise((resolve, reject) => { img.onload = () => { resolve(img); }; img.onerror = reject; }); promise.then(img => { const canvas = document.createElement("canvas"); canvas.width = img.width; canvas.height = img.height; const context = canvas.getContext("2d"); context.drawImage(img, 0, 0); const base64 = canvas.toDataURL(); const imgData = base64.replace(/^data:image\/\w+;base64,/, ""); const imgBuffer = Buffer.from(imgData, "base64"); const zip = new JSZip(); const imgFile = zip.folder("images").file("image.png", imgBuffer, { binary: true }); const imgPath = `images/image.png`; sheet.row(rowIndex + 1).cell(cellIndex + 1).value(imgPath); resolve(); }); } else { // 添加数据 sheet.row(rowIndex + 1).cell(cellIndex + 1).value(cell); } }); }); // 生成 Excel 文件并下载 const buffer = await workbook.outputAsync(); const blob = new Blob([buffer], { type: "application/octet-stream" }); const url = URL.createObjectURL(blob); const link = document.createElement("a"); link.href = url; link.download = "data.xlsx"; link.click(); URL.revokeObjectURL(url); } ``` 5. 最终的组件代码如下: ``` import React from "react"; import XlsxPopulate from "xlsx-populate"; import JSZip from "jszip"; const data = [ ["Name", "Age", "Gender", "Image"], ["John Doe", 30, "Male", "image1"], ["Jane Smith", 25, "Female", "image2"], ["Bob Johnson", 50, "Male", "image3"] ]; const images = { image1: "https://example.com/image1.jpg", image2: "https://example.com/image2.jpg", image3: "https://example.com/image3.jpg" }; async function exportToExcel() { const workbook = await XlsxPopulate.fromBlankAsync(); // 添加工作表 const sheet = workbook.addSheet("Sheet1"); // 添加表头 sheet.cell("A1").value("Name"); sheet.cell("B1").value("Age"); sheet.cell("C1").value("Gender"); sheet.cell("D1").value("Image"); // 添加数据和图片 data.forEach((row, rowIndex) => { row.forEach((cell, cellIndex) => { if (cellIndex === 3) { // 添加图片 const img = new Image(); img.crossOrigin = "Anonymous"; img.src = images[cell]; const promise = new Promise((resolve, reject) => { img.onload = () => { resolve(img); }; img.onerror = reject; }); promise.then(img => { const canvas = document.createElement("canvas"); canvas.width = img.width; canvas.height = img.height; const context = canvas.getContext("2d"); context.drawImage(img, 0, 0); const base64 = canvas.toDataURL(); const imgData = base64.replace(/^data:image\/\w+;base64,/, ""); const imgBuffer = Buffer.from(imgData, "base64"); const zip = new JSZip(); const imgFile = zip.folder("images").file("image.png", imgBuffer, { binary: true }); const imgPath = `images/image.png`; sheet.row(rowIndex + 1).cell(cellIndex + 1).value(imgPath); resolve(); }); } else { // 添加数据 sheet.row(rowIndex + 1).cell(cellIndex + 1).value(cell); } }); }); // 生成 Excel 文件并下载 const buffer = await workbook.outputAsync(); const blob = new Blob([buffer], { type: "application/octet-stream" }); const url = URL.createObjectURL(blob); const link = document.createElement("a"); link.href = url; link.download = "data.xlsx"; link.click(); URL.revokeObjectURL(url); } function ExportExcelWithImages() { return <button onClick={exportToExcel}>Export to Excel</button>; } export default ExportExcelWithImages; ``` 当用户点击 "Export to Excel" 按钮时,将会下载一个名为 "data.xlsx" 的文件,其中包含数据和图片

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值