国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

Java Excel轉(zhuǎn)PDF,支持xlsx和xls兩種格式, itextpdf【即取即用】

這篇具有很好參考價值的文章主要介紹了Java Excel轉(zhuǎn)PDF,支持xlsx和xls兩種格式, itextpdf【即取即用】。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

本篇主要為工具方法整理,參考學習其他博主文章做了整理,方便使用。

工具方法

一、使用方式

1、本地轉(zhuǎn)換

  • 導入依賴
  • 創(chuàng)建工具方法
  • 傳入輸入輸出流或文檔地址即可。

2、網(wǎng)絡下載

通過POI或者easyExcel生成或填充,再由后端轉(zhuǎn)換PDF響應前端
思路:將網(wǎng)絡下載拆分為本地轉(zhuǎn)換,再響應前端即可。文章來源地址http://www.zghlxwxcb.cn/news/detail-759044.html

  • 現(xiàn)在服務器創(chuàng)建臨時文件目錄(臨時目錄可在每次下載請求開始先進行清空);
  • 將生成的Excel寫入本地臨時文件;
  • 獲取Excel文件輸入流,獲取響應的輸出流(response.getOutputStream(););
  • 調(diào)取公共方法傳入輸入輸出流即可。

二、pom依賴引入

	<!-- pom相關(guān)依賴 -->
    <poi.version>4.1.1</poi.version>
    <itextpdf.version>5.5.13.2</itextpdf.version>
    <!-- POI Excel-->
    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi</artifactId>
        <version>${poi.version}</version>
    </dependency>
    <!-- iText PDF -->
    <dependency>
        <groupId>com.itextpdf</groupId>
        <artifactId>itextpdf</artifactId>
        <version>${itextpdf.version}</version>
    </dependency>

三、工具方法

package com.xxx.tool.util;

import cn.hutool.core.collection.CollUtil;
import com.itextpdf.text.*;
import com.itextpdf.text.pdf.BaseFont;
import com.itextpdf.text.pdf.PdfPCell;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfWriter;
import lombok.experimental.UtilityClass;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.ooxml.POIXMLDocumentPart;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.usermodel.*;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Objects;

@UtilityClass
public class ExcelToPdfUtil {

    public static void excelToPdf(String excelPath, String pdfPath, String excelSuffix) {
        try (InputStream in = Files.newInputStream(Paths.get(excelPath));
             OutputStream out = Files.newOutputStream(Paths.get(pdfPath))) {
            ExcelToPdfUtil.excelToPdf(in, out, excelSuffix);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * Excel轉(zhuǎn)PDF并寫入輸出流
     *
     * @param inStream    Excel輸入流
     * @param outStream   PDF輸出流
     * @param excelSuffix Excel類型 .xls 和 .xlsx
     * @throws Exception 異常信息
     */
    public static void excelToPdf(InputStream inStream, OutputStream outStream, String excelSuffix) throws Exception {
        // 輸入流轉(zhuǎn)workbook,獲取sheet
        Sheet sheet = getPoiSheetByFileStream(inStream, 0, excelSuffix);
        // 獲取列寬度占比
        float[] widths = getColWidth(sheet);
        PdfPTable table = new PdfPTable(widths);
        table.setWidthPercentage(100);
        int colCount = widths.length;
        //設置基本字體
        BaseFont baseFont = BaseFont.createFont("C:\\Windows\\Fonts\\simsun.ttc,0", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
        // 遍歷行
        for (int rowIndex = sheet.getFirstRowNum(); rowIndex <= sheet.getLastRowNum(); rowIndex++) {
            Row row = sheet.getRow(rowIndex);
            if (Objects.isNull(row)) {
                // 插入空對象
                for (int i = 0; i < colCount; i++) {
                    table.addCell(createPdfPCell(null, 0, 13f, null));
                }
            } else {
                // 遍歷單元格
                for (int columnIndex = 0; (columnIndex < row.getLastCellNum() || columnIndex < colCount) && columnIndex > -1; columnIndex++) {
                    PdfPCell pCell = excelCellToPdfCell(sheet, row.getCell(columnIndex), baseFont);
                    // 是否合并單元格
                    if (isMergedRegion(sheet, rowIndex, columnIndex)) {
                        int[] span = getMergedSpan(sheet, rowIndex, columnIndex);
                        //忽略合并過的單元格
                        boolean mergedCell = span[0] == 1 && span[1] == 1;
                        if (mergedCell) {
                            continue;
                        }
                        pCell.setRowspan(span[0]);
                        pCell.setColspan(span[1]);
                    }
                    table.addCell(pCell);
                }
            }
        }
        // 初始化PDF文檔對象
        createPdfTableAndWriteDocument(outStream, table);
    }

    /**
     * 單元格轉(zhuǎn)換,poi cell 轉(zhuǎn)換為 itext cell
     *
     * @param sheet     poi sheet頁
     * @param excelCell poi 單元格
     * @param baseFont  基礎字體
     * @return com.itextpdf.text.pdf.PdfPCell
     */
    private static PdfPCell excelCellToPdfCell(Sheet sheet, Cell excelCell, BaseFont baseFont) throws Exception {
        if (Objects.isNull(excelCell)) {
            return createPdfPCell(null, 0, 13f, null);
        }
        int rowIndex = excelCell.getRowIndex();
        int columnIndex = excelCell.getColumnIndex();
        // 圖片信息
        List<PicturesInfo> infos = getAllPictureInfos(sheet, rowIndex, rowIndex, columnIndex, columnIndex, false);
        PdfPCell pCell;
        if (CollUtil.isNotEmpty(infos)) {
            pCell = new PdfPCell(Image.getInstance(infos.get(0).getPictureData()));
        } else {
            Font excelFont = getExcelFont(sheet, excelCell);
            //設置單元格字體
            com.itextpdf.text.Font pdFont = new com.itextpdf.text.Font(baseFont, excelFont.getFontHeightInPoints(), excelFont.getBold() ? 1 : 0, BaseColor.BLACK);
            Integer border = hasBorder(excelCell) ? null : 0;
            String excelCellValue = getExcelCellValue(excelCell);
            pCell = createPdfPCell(excelCellValue, border, excelCell.getRow().getHeightInPoints(), pdFont);
        }
        // 水平居中
        pCell.setHorizontalAlignment(getHorAlign(excelCell.getCellStyle().getAlignment().getCode()));
        // 垂直對齊
        pCell.setVerticalAlignment(getVerAlign(excelCell.getCellStyle().getVerticalAlignment().getCode()));
        return pCell;
    }

    /**
     * 創(chuàng)建pdf文檔,并添加表格
     *
     * @param outStream 輸出流,目標文檔
     * @param table     表格
     * @throws DocumentException 異常信息
     */
    private static void createPdfTableAndWriteDocument(OutputStream outStream, PdfPTable table) throws DocumentException {
        //設置pdf紙張大小 PageSize.A4 A4橫向
        Document document = new Document(new RectangleReadOnly(842.0F, 595.0F));
        PdfWriter.getInstance(document, outStream);
        //設置頁邊距 寬
        document.setMargins(10, 10, 10, 10);
        document.open();
        document.add(table);
        document.close();
    }

    /**
     * Excel文檔輸入流轉(zhuǎn)換為對應的workbook及獲取對應的sheet
     *
     * @param inputStream Excel文檔輸入流
     * @param sheetNo     sheet編號,默認0 第一個sheet
     * @param excelSuffix 文件類型 .xls和.xlsx
     * @return poi sheet
     * @throws IOException 異常
     */
    public static Sheet getPoiSheetByFileStream(InputStream inputStream, int sheetNo, String excelSuffix) throws IOException {
        Workbook workbook;
        if (excelSuffix.endsWith(".xlsx")) {
            workbook = new XSSFWorkbook(inputStream);
        } else {
            workbook = new HSSFWorkbook(inputStream);
        }
        return workbook.getSheetAt(sheetNo);
    }

    /**
     * 創(chuàng)建itext pdf 單元格
     *
     * @param content       單元格內(nèi)容
     * @param border        邊框
     * @param minimumHeight 高度
     * @param pdFont        字體
     * @return pdf cell
     */
    private static PdfPCell createPdfPCell(String content, Integer border, Float minimumHeight, com.itextpdf.text.Font pdFont) {
        String contentValue = content == null ? "" : content;
        com.itextpdf.text.Font pdFontNew = pdFont == null ? new com.itextpdf.text.Font() : pdFont;
        PdfPCell pCell = new PdfPCell(new Phrase(contentValue, pdFontNew));
        if (Objects.nonNull(border)) {
            pCell.setBorder(border);
        }
        if (Objects.nonNull(minimumHeight)) {
            pCell.setMinimumHeight(minimumHeight);
        }

        return pCell;
    }

    /**
     * excel垂直對齊方式映射到pdf對齊方式
     */
    private static int getVerAlign(int align) {
        switch (align) {
            case 2:
                return com.itextpdf.text.Element.ALIGN_BOTTOM;
            case 3:
                return com.itextpdf.text.Element.ALIGN_TOP;
            default:
                return com.itextpdf.text.Element.ALIGN_MIDDLE;
        }
    }

    /**
     * excel水平對齊方式映射到pdf水平對齊方式
     */
    private static int getHorAlign(int align) {
        switch (align) {
            case 1:
                return com.itextpdf.text.Element.ALIGN_LEFT;
            case 3:
                return com.itextpdf.text.Element.ALIGN_RIGHT;
            default:
                return com.itextpdf.text.Element.ALIGN_CENTER;
        }
    }

    /*============================================== POI獲取圖片及文本內(nèi)容工具方法 ==============================================*/

    /**
     * 獲取字體
     *
     * @param sheet excel 轉(zhuǎn)換的sheet頁
     * @param cell  單元格
     * @return 字體
     */
    private static Font getExcelFont(Sheet sheet, Cell cell) {
        // xls
        if (sheet instanceof HSSFSheet) {
            Workbook workbook = sheet.getWorkbook();
            return ((HSSFCell) cell).getCellStyle().getFont(workbook);
        }
        // xlsx
        return ((XSSFCell) cell).getCellStyle().getFont();
    }

    /**
     * 判斷excel單元格是否有邊框
     */
    private static boolean hasBorder(Cell excelCell) {
        short top = excelCell.getCellStyle().getBorderTop().getCode();
        short bottom = excelCell.getCellStyle().getBorderBottom().getCode();
        short left = excelCell.getCellStyle().getBorderLeft().getCode();
        short right = excelCell.getCellStyle().getBorderRight().getCode();
        return top + bottom + left + right > 2;
    }

    /**
     * 判斷單元格是否是合并單元格
     */
    private static boolean isMergedRegion(Sheet sheet, int row, int column) {
        int sheetMergeCount = sheet.getNumMergedRegions();
        for (int i = 0; i < sheetMergeCount; i++) {
            CellRangeAddress range = sheet.getMergedRegion(i);
            int firstColumn = range.getFirstColumn();
            int lastColumn = range.getLastColumn();
            int firstRow = range.getFirstRow();
            int lastRow = range.getLastRow();
            if (row >= firstRow && row <= lastRow) {
                if (column >= firstColumn && column <= lastColumn) {
                    return true;
                }
            }
        }
        return false;
    }

    /**
     * 計算合并單元格合并的跨行跨列數(shù)
     */
    private static int[] getMergedSpan(Sheet sheet, int row, int column) {
        int sheetMergeCount = sheet.getNumMergedRegions();
        int[] span = {1, 1};
        for (int i = 0; i < sheetMergeCount; i++) {
            CellRangeAddress range = sheet.getMergedRegion(i);
            int firstColumn = range.getFirstColumn();
            int lastColumn = range.getLastColumn();
            int firstRow = range.getFirstRow();
            int lastRow = range.getLastRow();
            if (firstColumn == column && firstRow == row) {
                span[0] = lastRow - firstRow + 1;
                span[1] = lastColumn - firstColumn + 1;
                break;
            }
        }
        return span;
    }

    /**
     * 獲取excel中每列寬度的占比
     */
    private static float[] getColWidth(Sheet sheet) {
        int rowNum = getMaxColRowNum(sheet);
        Row row = sheet.getRow(rowNum);
        int cellCount = row.getPhysicalNumberOfCells();
        int[] colWidths = new int[cellCount];
        int sum = 0;

        for (int i = row.getFirstCellNum(); i < cellCount; i++) {
            Cell cell = row.getCell(i);
            if (cell != null) {
                colWidths[i] = sheet.getColumnWidth(i);
                sum += sheet.getColumnWidth(i);
            }
        }

        float[] colWidthPer = new float[cellCount];
        for (int i = row.getFirstCellNum(); i < cellCount; i++) {
            colWidthPer[i] = (float) colWidths[i] / sum * 100;
        }
        return colWidthPer;
    }

    /**
     * 獲取excel中列數(shù)最多的行號
     */
    private static int getMaxColRowNum(Sheet sheet) {
        int rowNum = 0;
        int maxCol = 0;
        for (int r = sheet.getFirstRowNum(); r < sheet.getPhysicalNumberOfRows(); r++) {
            Row row = sheet.getRow(r);
            if (row != null && maxCol < row.getPhysicalNumberOfCells()) {
                maxCol = row.getPhysicalNumberOfCells();
                rowNum = r;
            }
        }
        return rowNum;
    }

    /**
     * poi 根據(jù)單元格類型獲取單元格內(nèi)容
     *
     * @param excelCell poi單元格
     * @return 單元格內(nèi)容文本
     */
    public static String getExcelCellValue(Cell excelCell) {
        if (excelCell == null) {
            return "";
        }
        // 判斷數(shù)據(jù)的類型
        CellType cellType = excelCell.getCellType();

        if (cellType == CellType.STRING) {
            return excelCell.getStringCellValue();
        }
        if (cellType == CellType.BOOLEAN) {
            return String.valueOf(excelCell.getBooleanCellValue());
        }
        if (cellType == CellType.FORMULA) {
            return excelCell.getCellFormula();
        }
        if (cellType == CellType.NUMERIC) {
            //short s = excelCell.getCellStyle().getDataFormat();
            if (DateUtil.isCellDateFormatted(excelCell)) {// 處理日期格式、時間格式
                SimpleDateFormat sdf;
                // 驗證short值
                if (excelCell.getCellStyle().getDataFormat() == 14) {
                    sdf = new SimpleDateFormat("yyyy/MM/dd");
                } else if (excelCell.getCellStyle().getDataFormat() == 21) {
                    sdf = new SimpleDateFormat("HH:mm:ss");
                } else if (excelCell.getCellStyle().getDataFormat() == 22) {
                    sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
                } else {
                    throw new RuntimeException("日期格式錯誤!!!");
                }
                Date date = excelCell.getDateCellValue();
                return sdf.format(date);
            } else if (excelCell.getCellStyle().getDataFormat() == 0) {
                //處理數(shù)值格式
                DataFormatter formatter = new DataFormatter();
                return formatter.formatCellValue(excelCell);
            }
        }
        if (cellType == CellType.ERROR) {
            return "非法字符";
        }
        return "";
    }

    /**
     * 獲取sheet內(nèi)的所有圖片信息
     *
     * @param sheet        sheet表
     * @param onlyInternal 單元格內(nèi)部
     * @return 照片集合
     * @throws Exception 異常
     */
    public static List<PicturesInfo> getAllPictureInfos(Sheet sheet, boolean onlyInternal) throws Exception {
        return getAllPictureInfos(sheet, null, null, null, null, onlyInternal);
    }

    /**
     * 根據(jù)sheet和單元格信息獲取圖片
     *
     * @param sheet        sheet表
     * @param minRow       最小行
     * @param maxRow       最大行
     * @param minCol       最小列
     * @param maxCol       最大列
     * @param onlyInternal 是否內(nèi)部
     * @return 圖片集合
     * @throws Exception 異常
     */
    public static List<PicturesInfo> getAllPictureInfos(Sheet sheet, Integer minRow, Integer maxRow, Integer minCol,
                                                        Integer maxCol, boolean onlyInternal) throws Exception {
        if (sheet instanceof HSSFSheet) {
            return getXLSAllPictureInfos((HSSFSheet) sheet, minRow, maxRow, minCol, maxCol, onlyInternal);
        } else if (sheet instanceof XSSFSheet) {
            return getXLSXAllPictureInfos((XSSFSheet) sheet, minRow, maxRow, minCol, maxCol, onlyInternal);
        } else {
            throw new Exception("未處理類型,沒有為該類型添加:GetAllPicturesInfos()擴展方法!");
        }
    }

    private static List<PicturesInfo> getXLSAllPictureInfos(HSSFSheet sheet, Integer minRow, Integer maxRow,
                                                            Integer minCol, Integer maxCol, Boolean onlyInternal) {
        List<PicturesInfo> picturesInfoList = new ArrayList<>();
        HSSFShapeContainer shapeContainer = sheet.getDrawingPatriarch();
        if (shapeContainer == null) {
            return picturesInfoList;
        }
        List<HSSFShape> shapeList = shapeContainer.getChildren();
        for (HSSFShape shape : shapeList) {
            if (shape instanceof HSSFPicture && shape.getAnchor() instanceof HSSFClientAnchor) {
                HSSFPicture picture = (HSSFPicture) shape;
                HSSFClientAnchor anchor = (HSSFClientAnchor) shape.getAnchor();

                if (isInternalOrIntersect(minRow, maxRow, minCol, maxCol, anchor.getRow1(), anchor.getRow2(),
                        anchor.getCol1(), anchor.getCol2(), onlyInternal)) {
                    HSSFPictureData pictureData = picture.getPictureData();
                    picturesInfoList.add(new PicturesInfo()
                            .setMinRow(anchor.getRow1())
                            .setMaxRow(anchor.getRow2())
                            .setMinCol(anchor.getCol1())
                            .setMaxCol(anchor.getCol2())
                            .setPictureData(pictureData.getData())
                            .setExt(pictureData.getMimeType()));
                }
            }
        }
        return picturesInfoList;
    }

    private static List<PicturesInfo> getXLSXAllPictureInfos(XSSFSheet sheet, Integer minRow, Integer maxRow,
                                                             Integer minCol, Integer maxCol, Boolean onlyInternal) {
        List<PicturesInfo> picturesInfoList = new ArrayList<>();

        List<POIXMLDocumentPart> documentPartList = sheet.getRelations();
        for (POIXMLDocumentPart documentPart : documentPartList) {
            if (documentPart instanceof XSSFDrawing) {
                XSSFDrawing drawing = (XSSFDrawing) documentPart;
                List<XSSFShape> shapes = drawing.getShapes();
                for (XSSFShape shape : shapes) {
                    if (shape instanceof XSSFPicture) {
                        XSSFPicture picture = (XSSFPicture) shape;
                        XSSFClientAnchor anchor = picture.getPreferredSize();

                        if (isInternalOrIntersect(minRow, maxRow, minCol, maxCol, anchor.getRow1(), anchor.getRow2(),
                                anchor.getCol1(), anchor.getCol2(), onlyInternal)) {
                            XSSFPictureData pictureData = picture.getPictureData();
                            picturesInfoList.add(new PicturesInfo()
                                    .setMinRow(anchor.getRow1())
                                    .setMaxRow(anchor.getRow2())
                                    .setMinCol(anchor.getCol1())
                                    .setMaxCol(anchor.getCol2())
                                    .setPictureData(pictureData.getData())
                                    .setExt(pictureData.getMimeType()));
                        }
                    }
                }
            }
        }

        return picturesInfoList;
    }

    private static boolean isInternalOrIntersect(Integer rangeMinRow, Integer rangeMaxRow, Integer rangeMinCol,
                                                 Integer rangeMaxCol, int pictureMinRow, int pictureMaxRow, int pictureMinCol, int pictureMaxCol,
                                                 Boolean onlyInternal) {
        int _rangeMinRow = rangeMinRow == null ? pictureMinRow : rangeMinRow;
        int _rangeMaxRow = rangeMaxRow == null ? pictureMaxRow : rangeMaxRow;
        int _rangeMinCol = rangeMinCol == null ? pictureMinCol : rangeMinCol;
        int _rangeMaxCol = rangeMaxCol == null ? pictureMaxCol : rangeMaxCol;

        if (onlyInternal) {
            return (_rangeMinRow <= pictureMinRow && _rangeMaxRow >= pictureMaxRow && _rangeMinCol <= pictureMinCol
                    && _rangeMaxCol >= pictureMaxCol);
        } else {
            return ((Math.abs(_rangeMaxRow - _rangeMinRow) + Math.abs(pictureMaxRow - pictureMinRow) >= Math
                    .abs(_rangeMaxRow + _rangeMinRow - pictureMaxRow - pictureMinRow))
                    && (Math.abs(_rangeMaxCol - _rangeMinCol) + Math.abs(pictureMaxCol - pictureMinCol) >= Math
                    .abs(_rangeMaxCol + _rangeMinCol - pictureMaxCol - pictureMinCol)));
        }
    }

    /**
     * 圖片基本信息
     */
    private class PicturesInfo {

        private int minRow;
        private int maxRow;
        private int minCol;
        private int maxCol;
        private String ext;
        private byte[] pictureData;

        public PicturesInfo() {
        }
        public byte[] getPictureData() {
            return pictureData;
        }
        public PicturesInfo setPictureData(byte[] pictureData) {
            this.pictureData = pictureData;
            return this;
        }
        public int getMinRow() {
            return minRow;
        }
        public PicturesInfo setMinRow(int minRow) {
            this.minRow = minRow;
            return this;
        }
        public int getMaxRow() {
            return maxRow;
        }
        public PicturesInfo setMaxRow(int maxRow) {
            this.maxRow = maxRow;
            return this;
        }
        public int getMinCol() {
            return minCol;
        }
        public PicturesInfo setMinCol(int minCol) {
            this.minCol = minCol;
            return this;
        }
        public int getMaxCol() {
            return maxCol;
        }
        public PicturesInfo setMaxCol(int maxCol) {
            this.maxCol = maxCol;
            return this;
        }
        public String getExt() {
            return ext;
        }
        public PicturesInfo setExt(String ext) {
            this.ext = ext;
            return this;
        }
    }
}

三、引文

  1. java高效實現(xiàn)excel轉(zhuǎn)pdf,支持excel中帶有圖片的轉(zhuǎn)換(支持.xls和.xlsx兩種格式)
  2. Java Poi 讀取excel 對所有類型進行處理

到了這里,關(guān)于Java Excel轉(zhuǎn)PDF,支持xlsx和xls兩種格式, itextpdf【即取即用】的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權(quán),不承擔相關(guān)法律責任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實不符,請點擊違法舉報進行投訴反饋,一經(jīng)查實,立即刪除!

領(lǐng)支付寶紅包贊助服務器費用

相關(guān)文章

  • vue - - - - - 在線預覽常見文件格式 .doc, .docx, .xls, .xlsx,.pdf

    vue - - - - - 在線預覽常見文件格式 .doc, .docx, .xls, .xlsx,.pdf

    關(guān)于一些文件的在線預覽,最簡易的實現(xiàn)方式是什么呢? 寫在前面 .png, .jpg, .jpeg 等圖片格式 直接預覽http/https地址 即可 .pdf 文件 直接預覽http/https地址 即可 .doc, .docx, .xls, .xlsx 等類型文件,需要在預覽地址之前拼接上 https://view.officeapps.live.com/op/view.aspx?src= .ofd 等類型文件,需

    2024年02月09日
    瀏覽(62)
  • 文件格式xls和xlsx有什么區(qū)別?xlsx和xls選擇哪個

    文件格式xls和xlsx有什么區(qū)別?xlsx和xls選擇哪個

    在數(shù)字時代,我們經(jīng)常需要處理各種電子文件,其中xls和xlsx是兩種常見的電子表格文件格式。盡管它們只有一字之差,但它們在功能、兼容性和性能等方面有著顯著的區(qū)別。本文將詳細解析這兩種文件格式的區(qū)別,并指導您如何根據(jù)需求選擇合適的格式。 XLS是Microsoft Excel的

    2024年01月24日
    瀏覽(23)
  • (Java)word轉(zhuǎn)pdf(aspose),pdf加水印(itextpdf),并支持POI模板(包括checkbox)導出

    (Java)word轉(zhuǎn)pdf(aspose),pdf加水印(itextpdf),并支持POI模板(包括checkbox)導出

    目錄 1、引入jar包 2、pdf處理工具類 3、poi模板導出工具類 4、測試類 5、模板 6、最終效果? 1、引入jar包 ? 2、pdf處理工具類 ?3、poi模板導出工具類 ?4、測試類 5、模板 6、最終效果?

    2024年02月06日
    瀏覽(33)
  • 用poi把xls格式轉(zhuǎn)換成xlsx格式

    java中要實現(xiàn)excel新老格式的轉(zhuǎn)換比較麻煩,開源庫也沒幾個好用的。用ChatGpt查詢也是推薦直接用POI,下面是借助ChatGPT寫出來的代碼,經(jīng)過小小修改,格式轉(zhuǎn)換良好,基本能用,就是效率比較低下。將就著用吧,哎! ? ?

    2024年02月10日
    瀏覽(19)
  • 【Unity】用Excel庫讀取Excel表格(.xlsx或者.xls)

    【Unity】用Excel庫讀取Excel表格(.xlsx或者.xls)

    首先需要下載解析的庫??EPPlus,? Excel,? ICSharpCode.SharpZipLib? ? 下載鏈接: https://download.csdn.net/download/weixin_46472622/87238048 使用方法 我的Excel 表格是這樣的,每一列有一個 我用一個結(jié)構(gòu)體對象來表示 讀取的方法 ?全部代碼,以及調(diào)用: 如果是打包PC端的exe,需要將編輯

    2024年02月12日
    瀏覽(30)
  • java中用HSSFWorkbook生成xls格式的excel(親測)

    SXSSFWorkbook類是用于生成XLSX格式的Excel文件(基于XML格式),而不是XLS格式的Excel文件(基于二進制格式)。 如果你需要生成XLS格式的Excel文件,可以使用HSSFWorkbook類。以下是一個簡單的示例: javaCopy code import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.ss.usermodel.*; impo

    2024年02月11日
    瀏覽(18)
  • aspose-words、itextpdf完美解決java將word、excel、ppt、圖片轉(zhuǎn)換為pdf文件

    aspose-words、itextpdf完美解決java將word、excel、ppt、圖片轉(zhuǎn)換為pdf文件

    我是 傲驕鹿先生 ,沉淀、學習、分享、成長。 如果你覺得文章內(nèi)容還可以的話,希望不吝您的「一鍵三連」,文章里面有不足的地方希望各位在評論區(qū)補充疑惑、見解以及面試中遇到的奇葩問法 面對日常開發(fā)過程中,將各種文件轉(zhuǎn)換為pdf文件的問題,總是讓人頭疼,這次終

    2024年02月03日
    瀏覽(96)
  • python 將 csv轉(zhuǎn)excel (.xls和.xlsx)的幾種方式

    python 將 csv轉(zhuǎn)excel (.xls和.xlsx)的幾種方式

    excel 后綴有2種格式, .xls 是從 Excel 97 到 Excel 2003 的默認文件格式,而 .xlsx 是 Excel 2007 及更高版本的默認文件格式。 .xlsx和.xls格式的主要區(qū)別在于,.xls格式單個工作表最多支持65536行,256列。 .xlsx格式最多支持1048576行,16384列。 此外就是,存儲同樣多的數(shù)據(jù),.xlsx格式文件更

    2024年02月08日
    瀏覽(18)
  • H5實現(xiàn)附件預覽功能(doc/docx、xls/xlsx、ppt/pptx、pdf)

    一、H5用以下方式即可實現(xiàn): (釘釘小程序官方目前沒有預覽附件的API,也可用這種方法實現(xiàn)) doc/docx、xls/xlsx、ppt/pptx 可直接用以下鏈接打開: 注意:使用此方法,附件鏈接必須是域名。 https://view.officeapps.live.com/op/view.aspx?src= + 文檔url pdf類型附件需要另外處理 ,具體方法

    2024年02月16日
    瀏覽(38)
  • 用python將csv轉(zhuǎn)excel (.xls和.xlsx)的幾種方式

    excel 后綴有2種格式, .xls 是從 Excel 97 到 Excel 2003 的默認文件格式,而 .xlsx 是 Excel 2007 及更高版本的默認文件格式。 .xlsx和.xls格式的主要區(qū)別在于,.xls格式單個工作表最多支持65536行,256列。 .xlsx格式最多支持1048576行,16384列。 此外就是,存儲同樣多的數(shù)據(jù),.xlsx格式文件更

    2024年02月05日
    瀏覽(21)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包