|
@@ -5,15 +5,19 @@ import com.aspose.cells.Workbook;
|
|
import com.itextpdf.text.Document;
|
|
import com.itextpdf.text.Document;
|
|
import com.itextpdf.text.pdf.PdfCopy;
|
|
import com.itextpdf.text.pdf.PdfCopy;
|
|
import com.itextpdf.text.pdf.PdfReader;
|
|
import com.itextpdf.text.pdf.PdfReader;
|
|
|
|
+import com.spire.xls.*;
|
|
import com.sun.image.codec.jpeg.JPEGCodec;
|
|
import com.sun.image.codec.jpeg.JPEGCodec;
|
|
import com.sun.image.codec.jpeg.JPEGImageEncoder;
|
|
import com.sun.image.codec.jpeg.JPEGImageEncoder;
|
|
import org.apache.commons.lang.StringUtils;
|
|
import org.apache.commons.lang.StringUtils;
|
|
-import org.apache.poi.ss.usermodel.ClientAnchor;
|
|
|
|
-import org.apache.poi.ss.usermodel.Sheet;
|
|
|
|
-import org.apache.poi.ss.usermodel.WorkbookFactory;
|
|
|
|
|
|
+import org.apache.poi.hssf.usermodel.HSSFSheet;
|
|
|
|
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
|
|
+import org.apache.poi.ss.usermodel.*;
|
|
|
|
+import org.apache.poi.ss.usermodel.CellStyle;
|
|
import org.apache.poi.ss.util.CellRangeAddress;
|
|
import org.apache.poi.ss.util.CellRangeAddress;
|
|
|
|
+import org.apache.poi.util.IOUtils;
|
|
import org.apache.poi.util.Units;
|
|
import org.apache.poi.util.Units;
|
|
import org.springblade.common.utils.CommonUtil;
|
|
import org.springblade.common.utils.CommonUtil;
|
|
|
|
+import org.springblade.common.utils.SnowFlakeUtil;
|
|
import org.springblade.common.vo.DataVO;
|
|
import org.springblade.common.vo.DataVO;
|
|
import org.springblade.core.tool.utils.FileUtil;
|
|
import org.springblade.core.tool.utils.FileUtil;
|
|
import org.springblade.core.tool.utils.IoUtil;
|
|
import org.springblade.core.tool.utils.IoUtil;
|
|
@@ -25,8 +29,7 @@ import java.awt.image.BufferedImage;
|
|
import java.io.*;
|
|
import java.io.*;
|
|
import java.net.URL;
|
|
import java.net.URL;
|
|
import java.net.URLEncoder;
|
|
import java.net.URLEncoder;
|
|
-import java.util.Arrays;
|
|
|
|
-import java.util.List;
|
|
|
|
|
|
+import java.util.*;
|
|
import java.util.regex.Matcher;
|
|
import java.util.regex.Matcher;
|
|
import java.util.zip.ZipEntry;
|
|
import java.util.zip.ZipEntry;
|
|
import java.util.zip.ZipOutputStream;
|
|
import java.util.zip.ZipOutputStream;
|
|
@@ -297,20 +300,52 @@ public class FileUtils {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-/* public static void main(String[] args) throws Exception {
|
|
|
|
- String downloadUri="http://192.168.0.110:6831/cache/files/data/b6b30b1337cbdc522810_1914/output.xlsx/output.xlsx?md5=vJFs5dZlSpopqwWVH1PV7w&expires=1675247021&filename=output.xlsx";
|
|
|
|
- downloadUri = downloadUri.replaceAll("amp;","");
|
|
|
|
- URL url = new URL(downloadUri);
|
|
|
|
- java.net.HttpURLConnection connection = (java.net.HttpURLConnection) url.openConnection();
|
|
|
|
- InputStream stream = connection.getInputStream();
|
|
|
|
|
|
+ public static void main11(String[] args) throws Exception {
|
|
|
|
|
|
- String excelUrl ="/Users/hongchuangyanfa/Desktop/pdf/1615164421657591808.xlsx";
|
|
|
|
|
|
+ String excelPath="/Users/hongchuangyanfa/Desktop/pdf/1625671101419880450.xlsx";
|
|
|
|
+ File file_out = ResourceUtil.getFile("/Users/hongchuangyanfa/Desktop/pdf/123.xlsx");
|
|
|
|
+ InputStream exceInp = new FileInputStream(file_out);//CommonUtil.getOSSInputStream("https://bladex-test-info.oss-cn-chengdu.aliyuncs.com//upload/20230130/2d98b5a4d6270d5d4f98847216c17888.xlsx");
|
|
|
|
+ final org.apache.poi.ss.usermodel.Workbook workbook = WorkbookFactory.create(exceInp);
|
|
|
|
+ Sheet sheet = workbook.getSheetAt(0);
|
|
|
|
+ sheet.setForceFormulaRecalculation(true);
|
|
|
|
+ // fileName为图片完整路径,例:C:\images\EDG.jpg
|
|
|
|
+ InputStream ossInputStream = CommonUtil.getOSSInputStream("https://bladex-test-info.oss-cn-chengdu.aliyuncs.com//upload/20230215/78c0938ed110230f3907461228e6fb45.jpg");
|
|
|
|
+ byte[] bytes = IOUtils.toByteArray(ossInputStream);
|
|
|
|
|
|
|
|
+ // 这里根据实际需求选择图片类型
|
|
|
|
+ int pictureIdx = workbook.addPicture(bytes,6);
|
|
|
|
|
|
- // String htmlString = IoUtil.readToString(stream);
|
|
|
|
- File writefile = new File(excelUrl);
|
|
|
|
- FileUtil.toFile(stream,writefile);
|
|
|
|
|
|
+ CreationHelper helper = workbook.getCreationHelper();
|
|
|
|
+ ClientAnchor anchor = helper.createClientAnchor();
|
|
|
|
+ anchor.setCol1(0); // param1是列号
|
|
|
|
+ anchor.setCol2(7);
|
|
|
|
+ anchor.setRow1(9); // param2是行号
|
|
|
|
+ anchor.setRow2(30); // param2是行号
|
|
|
|
|
|
|
|
+ Drawing drawing = sheet.createDrawingPatriarch();
|
|
|
|
+ anchor.setAnchorType(ClientAnchor.AnchorType.MOVE_AND_RESIZE);
|
|
|
|
+ // 插入图片
|
|
|
|
+ Picture pict = drawing.createPicture(anchor, pictureIdx); // 调整图片占单元格百分比的大小,1.0就是100%
|
|
|
|
+ pict.resize(1,1);
|
|
|
|
+ FileUtils.imageOrientation(sheet, anchor, new DataVO(0, 9) );
|
|
|
|
+ FileOutputStream outputStream = new FileOutputStream(excelPath);
|
|
|
|
+ //生成一份新的excel
|
|
|
|
|
|
- }*/
|
|
|
|
|
|
+ Cell cell = sheet.getRow(6).getCell(10);
|
|
|
|
+ cell.setCellValue("2023年02-08-2023年02-09");
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ workbook.write(outputStream);
|
|
|
|
+ if (outputStream != null) {
|
|
|
|
+ IoUtil.closeQuietly(outputStream);
|
|
|
|
+ }
|
|
|
|
+ if (exceInp != null) {
|
|
|
|
+ IoUtil.closeQuietly(exceInp);
|
|
|
|
+ }
|
|
|
|
+ if (workbook != null) {
|
|
|
|
+ IoUtil.closeQuietly(workbook);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
}
|
|
}
|