java EasyExcelを使ってエクスポートエクセルを導入します。


一、準備工作
1、コンダクタンス

<!-- poi   -->
<dependency>
	<groupId>org.apache.poi</groupId>
	<artifactId>poi</artifactId>
	<version>3.17</version>
</dependency>
<dependency>
	<groupId>org.apache.poi</groupId>
	<artifactId>poi-ooxml-schemas</artifactId>
	<version>3.17</version>
</dependency>
<dependency>
	<groupId>org.apache.poi</groupId>
	<artifactId>poi-ooxml</artifactId>
	<version>3.17</version>
</dependency>
<!-- esayexcel 2.1.7  -->
<dependency>
	<groupId>com.alibaba</groupId>
	<artifactId>easyexcel</artifactId>
	<version>2.1.7</version>
</dependency>
二、注釈を理解する
1、常用注釈
フィールドのコメント
クラスのコメント
@ColumnWith(列幅)
@ColumnWidth(全体列幅)
@Excel Property(フィールド設定)
@ヘッドフォートスタイル
@HeadRowHeight(タイトルの高さ)
@ConttentFontStyle(内容フォントスタイル)
@ContentRowHeight(内容の高さ)
2、@Excel Propertyコメント
必要な注釈は、注釈の中に三つのパラメータvalueがあり、indexはそれぞれ列明を表し、列番号を数える。
valueとindexは二者択一しかできません。通常はconverterを設置しません。
1.valueはタイトルテキストで対応します。
2.indexはテキスト行番号で対応します。

@ExcelProperty(value = "  ", index = 0)
private Long id;
3、@ColumnWithコメント
列の幅を設定します。パラメータは一つだけです。valueの単位は文字長で、最大255文字を設定できます。excelのセルの最大書き込み可能文字数は255文字です。

public class ImeiEncrypt {
    @ColumnWidth(value = 255) //excel         255
    private String message;
}
4、@ContentFontStyleコメント
セルの内容のフォントフォーマットを設定するためのコメント
パラメータ
意味
font Name
フォント名
fontHeight InPoints
フォントの高さ
italic
斜体かどうか
ストリップアウト
水平線の削除を設定しますか?
カラー
フォントの色
typeOffset
オフセット
アンダーライン
下線を引く
bold
太めの有無
charset
コーディングフォーマット
5、@ContentStyleコメント
コンテンツフォーマットのコメントを設定します。
パラメータ
意味
data Format
日付の書式
hidden
このスタイルでセルを非表示にする
ロックド
このスタイルでセルをロックする
「tePrefix」
セルの前に記号を追加すると、数字または数式が文字列として表示されます。
ホリプゾントAlign ment
水平方向に中央揃えするかどうかを設定します。
wrapped
テキストを改行するかどうかを設定します。このフラグをtrueに設定します。複数の行に表示することで、セルのすべての内容が表示されます。
vertical Align ment
垂直方向に中央揃えするかどうかを設定します。
ロテート
セル内のテキストの回転角度を設定します。03バージョンのExcel回転角度区間は-90°で、07バージョンのExcel回転角度区間は0°180°です。
indent
セル内のテキストをインデントするスペースの数を設定します。
border Left
左枠線のスタイルを設定します。
border Right
右辺のスタイルを設定
border Top
上辺のスタイルを設定
leftBorder Color
左枠線の色を設定
ライトBorder Color
右枠線の色を設定
topBorder Color
上辺の色を設定
bottomborder Color
下辺の色を設定
fillPattern Type
塗りつぶしの種類を設定
fillBackground Color
背景色を設定
shrink ToFit
自動セルの自動サイズを設定します。
6、@HeadFontStyleコメント
タイトルのフォントフォーマットをカスタマイズする
パラメータ
意味
font Name
フォント名を設定
fontHeight InPoints
フォントの高さを設定
italic
フォントの斜体を設定します。
ストリップアウト
削除線を設定しますか?
カラー
フォントの色を設定
typeOffset
オフセットの設定
アンダーライン
下線を引く
charset
フォントコードの設定
bold
フォントの太さを設定します。
7、Excel Ignoreコメント
このフィールドをExcelに変換しない
三、コード化
1、マッピングエンティティクラス----例

package com.pingou.admin.bean.param;

import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.format.DateTimeFormat;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import com.alibaba.excel.annotation.write.style.ContentRowHeight;
import com.alibaba.excel.annotation.write.style.HeadRowHeight;
import lombok.Data;

import java.math.BigDecimal;
import java.util.Date;

@Data
@ContentRowHeight(35) //     
@HeadRowHeight(40)    //    
@ColumnWidth(40)
public class OrderExcel {
    //  excel    
    @ExcelProperty(value = "  ", index = 0)
    private Long id;
    @DateTimeFormat("yyyy MM dd HH mm ss ")
    @ExcelProperty(value = "    ", index = 1)
    private Date createTime;
}
以上は簡単な例です。もっと多くの属性があれば、自分で一つずつ書いてください。そして、この実体類に押し込めばいいです。
2、エクセルを生成する

public void excel() {
        //   excel      
        List<OrderExcel> excel = new ArrayList<>();
        //               

        //UUID    name
        String name = UUID.randomUUID().toString().replaceAll("-", "") + ".xlsx";
        //  excel    

        //1           excel    
        String filename = "/  " + name;
        JSONObject json = new JSONObject();
        try {
            // 2   easyexcel          
            // write      :           ,        class
            EasyExcel.write(filename, OrderExcel.class).sheet("  ").doWrite(excel);
            //   fastdfs               ,        excel  
            File file = new File(filename);
            String path = fastDFSClient.upload(new FileInputStream(file), name, null);
            path = (this.fastdfsDomain + path);
            json.put("url", path);
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            new File(filename).delete();
        }
    }
以上、生成済みです。
四、結果

以上はjavaを使ってEasyExcelを導入してexcelの詳しい内容を導きます。javaについてEasyExcelを導入してexcelの資料をエクスポートします。他の関連記事に注目してください。