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

EasyExcel設(shè)置表格樣式

這篇具有很好參考價(jià)值的文章主要介紹了EasyExcel設(shè)置表格樣式。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問(wèn)。

工具類(lèi)

package com.alibaba.excel.write.style;

import java.util.List;

import com.alibaba.excel.metadata.data.WriteCellData;
import com.alibaba.excel.util.ListUtils;
import com.alibaba.excel.write.handler.context.CellWriteHandlerContext;
import com.alibaba.excel.write.metadata.style.WriteCellStyle;

import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.collections4.CollectionUtils;

/**
 * Use the same style for the row
 *
 * @author Jiaju Zhuang
 */
@Getter
@Setter
@EqualsAndHashCode
public class HorizontalCellStyleStrategy extends AbstractCellStyleStrategy {

    private WriteCellStyle headWriteCellStyle;
    private List<WriteCellStyle> contentWriteCellStyleList;

    public HorizontalCellStyleStrategy() {
    }

    public HorizontalCellStyleStrategy(WriteCellStyle headWriteCellStyle,
        List<WriteCellStyle> contentWriteCellStyleList) {
        this.headWriteCellStyle = headWriteCellStyle;
        this.contentWriteCellStyleList = contentWriteCellStyleList;
    }

    public HorizontalCellStyleStrategy(WriteCellStyle headWriteCellStyle, WriteCellStyle contentWriteCellStyle) {
        this.headWriteCellStyle = headWriteCellStyle;
        if (contentWriteCellStyle != null) {
            this.contentWriteCellStyleList = ListUtils.newArrayList(contentWriteCellStyle);
        }
    }

    @Override
    protected void setHeadCellStyle(CellWriteHandlerContext context) {
        if (stopProcessing(context) || headWriteCellStyle == null) {
            return;
        }
        WriteCellData<?> cellData = context.getFirstCellData();
        WriteCellStyle.merge(headWriteCellStyle, cellData.getOrCreateStyle());
    }

    @Override
    protected void setContentCellStyle(CellWriteHandlerContext context) {
        if (stopProcessing(context) || CollectionUtils.isEmpty(contentWriteCellStyleList)) {
            return;
        }
        WriteCellData<?> cellData = context.getFirstCellData();
        if (context.getRelativeRowIndex() == null || context.getRelativeRowIndex() <= 0) {
            WriteCellStyle.merge(contentWriteCellStyleList.get(0), cellData.getOrCreateStyle());
        } else {
            WriteCellStyle.merge(
                contentWriteCellStyleList.get(context.getRelativeRowIndex() % contentWriteCellStyleList.size()),
                cellData.getOrCreateStyle());
        }
    }

    protected boolean stopProcessing(CellWriteHandlerContext context) {
        return context.getFirstCellData() == null;
    }

}
package com.bytz.modules.cms.statistics.excel;

import com.alibaba.excel.write.metadata.style.WriteCellStyle;
import com.alibaba.excel.write.metadata.style.WriteFont;
import org.apache.poi.ss.usermodel.*;

public class StyleUtils {

    /**
     * 標(biāo)題樣式
     * @return
     */
    public static WriteCellStyle getHeadStyle(){
        // 頭的策略
        WriteCellStyle headWriteCellStyle = new WriteCellStyle();
        // 背景顏色
//        headWriteCellStyle.setFillForegroundColor(IndexedColors.LIGHT_TURQUOISE1.getIndex());
//        headWriteCellStyle.setFillPatternType(FillPatternType.SOLID_FOREGROUND);

        // 字體
        WriteFont headWriteFont = new WriteFont();
        headWriteFont.setFontName("宋體");//設(shè)置字體名字
        headWriteFont.setFontHeightInPoints((short)14);//設(shè)置字體大小
        headWriteFont.setBold(true);//字體加粗
        headWriteCellStyle.setWriteFont(headWriteFont); //在樣式用應(yīng)用設(shè)置的字體;

        // 樣式
        headWriteCellStyle.setBorderBottom(BorderStyle.THIN);//設(shè)置底邊框;
        headWriteCellStyle.setBottomBorderColor((short) 0);//設(shè)置底邊框顏色;
        headWriteCellStyle.setBorderLeft(BorderStyle.THIN);  //設(shè)置左邊框;
        headWriteCellStyle.setLeftBorderColor((short) 0);//設(shè)置左邊框顏色;
        headWriteCellStyle.setBorderRight(BorderStyle.THIN);//設(shè)置右邊框;
        headWriteCellStyle.setRightBorderColor((short) 0);//設(shè)置右邊框顏色;
        headWriteCellStyle.setBorderTop(BorderStyle.THIN);//設(shè)置頂邊框;
        headWriteCellStyle.setTopBorderColor((short) 0); //設(shè)置頂邊框顏色;

        headWriteCellStyle.setWrapped(true);  //設(shè)置自動(dòng)換行;

        headWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);//設(shè)置水平對(duì)齊的樣式為居中對(duì)齊;
        headWriteCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);  //設(shè)置垂直對(duì)齊的樣式為居中對(duì)齊;
        headWriteCellStyle.setShrinkToFit(true);//設(shè)置文本收縮至合適

        return headWriteCellStyle;
    }


    /**
     * 內(nèi)容樣式
     * @return
     */
    public static WriteCellStyle getContentStyle(){
        // 內(nèi)容的策略
        WriteCellStyle contentWriteCellStyle = new WriteCellStyle();

        // 背景綠色
        // 這里需要指定 FillPatternType 為FillPatternType.SOLID_FOREGROUND 不然無(wú)法顯示背景顏色.頭默認(rèn)了 FillPatternType所以可以不指定
//        contentWriteCellStyle.setFillForegroundColor(IndexedColors.PALE_BLUE.getIndex());
//        contentWriteCellStyle.setFillPatternType(FillPatternType.SOLID_FOREGROUND);

        // 設(shè)置字體
        WriteFont contentWriteFont = new WriteFont();
        contentWriteFont.setFontHeightInPoints((short) 12);//設(shè)置字體大小
        contentWriteFont.setFontName("宋體"); //設(shè)置字體名字
        contentWriteCellStyle.setWriteFont(contentWriteFont);//在樣式用應(yīng)用設(shè)置的字體;

        //設(shè)置樣式;
        contentWriteCellStyle.setBorderBottom(BorderStyle.THIN);//設(shè)置底邊框;
        contentWriteCellStyle.setBottomBorderColor((short) 0);//設(shè)置底邊框顏色;
        contentWriteCellStyle.setBorderLeft(BorderStyle.THIN);  //設(shè)置左邊框;
        contentWriteCellStyle.setLeftBorderColor((short) 0);//設(shè)置左邊框顏色;
        contentWriteCellStyle.setBorderRight(BorderStyle.THIN);//設(shè)置右邊框;
        contentWriteCellStyle.setRightBorderColor((short) 0);//設(shè)置右邊框顏色;
        contentWriteCellStyle.setBorderTop(BorderStyle.THIN);//設(shè)置頂邊框;
        contentWriteCellStyle.setTopBorderColor((short) 0); ///設(shè)置頂邊框顏色;

        contentWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);// 水平居中
        contentWriteCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);// 垂直居中
        contentWriteCellStyle.setWrapped(true); //設(shè)置自動(dòng)換行;

//        contentWriteCellStyle.setShrinkToFit(true);//設(shè)置文本收縮至合適

        return contentWriteCellStyle;
    }

}

使用

        // 設(shè)置單元格樣式
        HorizontalCellStyleStrategy horizontalCellStyleStrategy =
                new HorizontalCellStyleStrategy(StyleUtils.getHeadStyle(), StyleUtils.getContentStyle());

        //寫(xiě)入表頭
        EasyExcel.write(outputStream)
                .head(header)
                .needHead(true)
                .autoCloseStream(true)
                .sheet()
                .registerWriteHandler(horizontalCellStyleStrategy)
                .doWrite(dataList)
                ;

主要是文字居中文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-511999.html

到了這里,關(guān)于EasyExcel設(shè)置表格樣式的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

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

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • Python自動(dòng)化小技巧18——自動(dòng)化資產(chǎn)月報(bào)(word設(shè)置字體表格樣式,查找替換文字)

    Python自動(dòng)化小技巧18——自動(dòng)化資產(chǎn)月報(bào)(word設(shè)置字體表格樣式,查找替換文字)

    案例背景 每月都要寫(xiě)各種月報(bào),經(jīng)營(yíng)管理月報(bào),資產(chǎn)月報(bào).....這些報(bào)告文字目標(biāo)都是高度相似的,只是需要替換為每個(gè)月的實(shí)際數(shù)據(jù)就行,如下: ? (打碼是怕信息泄露.....) 可以看到,這個(gè)報(bào)告的都是高度模板化,我們只需要對(duì)里面的某些文字進(jìn)行替換,例如2023年7月?lián)Q成2

    2024年02月12日
    瀏覽(23)
  • Ext JS 如何設(shè)置工具欄按鈕和一般按鈕保持統(tǒng)一樣式

    Ext JS 如何設(shè)置工具欄按鈕和一般按鈕保持統(tǒng)一樣式

    在Ext JS 中, Button的背景色保持和系統(tǒng)的主色調(diào)一致, 樣式如下: 但是使用工具欄(toolbar) 添加按鈕的時(shí)候, 按鈕的背景色確實(shí)灰色,如下圖所示: 為什么會(huì)有這個(gè)差別呢? 如何讓它們保持一致呢? 看一下Toolbar里面的按鈕最終產(chǎn)生的按鈕的樣式: Toolbar 通過(guò)樣式類(lèi)x-bt

    2024年02月12日
    瀏覽(23)
  • 使用EasyExcel讀取和寫(xiě)入表格

    使用EasyExcel讀取和寫(xiě)入表格

    首先我創(chuàng)建了一個(gè)Excel的文件,數(shù)據(jù)如下 讀取excel在EasyExcel中是很簡(jiǎn)單的一件事情,首先,我們需要有對(duì)象去存儲(chǔ)一條條數(shù)據(jù),所以這里我建立了一個(gè)Student對(duì)象,有如下四個(gè)字段,并分別賦予了get和set方法 @ExcelProperty該注解就是映射表頭的,value的值就是Excel中實(shí)際的表頭數(shù)據(jù)

    2024年02月02日
    瀏覽(15)
  • easyexcel導(dǎo)入導(dǎo)出+動(dòng)態(tài)列+自定義樣式

    easyexcel導(dǎo)入導(dǎo)出+動(dòng)態(tài)列+自定義樣式

    目錄 1、引用maven依賴(lài) 2、模板文件template1.xlsx 3、導(dǎo)出效果 4、導(dǎo)入效果 5、導(dǎo)出用EasyWriteHandler 6、測(cè)試工具類(lèi)?ExcelTest

    2024年02月15日
    瀏覽(21)
  • java處理Excel表格(EasyExcel)

    1.EasyExcel特點(diǎn) Java領(lǐng)域解析、生成Excel比較有名的框架有Apache poi、jxl等。但他們都存在一個(gè)嚴(yán)重的問(wèn)題就是非常的耗內(nèi)存。如果你的系統(tǒng)并發(fā)量不大的話(huà)可能還行,但是一旦并發(fā)上來(lái)后一定會(huì)OOM或者JVM頻繁的full gc。 EasyExcel是阿里巴巴開(kāi)源的一個(gè)excel處理框架,以使用簡(jiǎn)單、節(jié)

    2024年02月15日
    瀏覽(22)
  • 使用EasyExcel導(dǎo)出表格時(shí)合并單元格

    使用EasyExcel導(dǎo)出表格時(shí)合并單元格

    現(xiàn)在需要將一個(gè)導(dǎo)出列表數(shù)據(jù)到Excel表格的功能進(jìn)行改造,將指定列相同數(shù)據(jù)自動(dòng)合并單元格。 如上圖所示,指定A、B兩列自動(dòng)合并,如圖所示(6、7),(8、9),(13、14、15)要自動(dòng)合并單元格。 EasyExcel是一個(gè)基于Java的、快速、簡(jiǎn)潔、解決大文件內(nèi)存溢出的Excel處理工具。

    2024年02月09日
    瀏覽(24)
  • EasyExcel格式化映射注解和樣式注解詳解

    使用注解很簡(jiǎn)單,只要在對(duì)應(yīng)的實(shí)體類(lèi)上面加上注解即可。 也就是說(shuō)使用實(shí)體類(lèi)模型來(lái)讀寫(xiě) Excel 文件時(shí),可以通過(guò)注解來(lái)控制實(shí)體類(lèi)字段和 Excel 列之間的對(duì)應(yīng)關(guān)系。 2.1 作用 ExcelProperty 注解用于匹配 excel 和實(shí)體類(lèi)字段之間的關(guān)系。 可以作用于字段上。 2.1 注解參數(shù) 名稱(chēng) 默

    2024年01月20日
    瀏覽(18)
  • 使用EasyExcel實(shí)現(xiàn)Excel表格的導(dǎo)入導(dǎo)出

    使用EasyExcel實(shí)現(xiàn)Excel表格的導(dǎo)入導(dǎo)出

    Java解析、生成Excel比較有名的框架有Apache poi、jxl。但他們都存在一個(gè)嚴(yán)重的問(wèn)題就是非常的耗內(nèi)存,poi有一套SAX模式的API可以一定程度的解決一些內(nèi)存溢出的問(wèn)題,但POI還是有一些缺陷,比如07版Excel解壓縮以及解壓后存儲(chǔ)都是在內(nèi)存中完成的,內(nèi)存消耗依然很大。 easyexcel重

    2024年02月12日
    瀏覽(18)
  • 工具類(lèi)——Java導(dǎo)出EXCEL2(設(shè)置樣式、加載并填充圖片、加載指定模板、大數(shù)據(jù)量設(shè)置窗口大小與刷新頻率)

    工具類(lèi)——Java導(dǎo)出EXCEL2(設(shè)置樣式、加載并填充圖片、加載指定模板、大數(shù)據(jù)量設(shè)置窗口大小與刷新頻率)

    書(shū)接上篇:工具類(lèi)——Java 瀏覽器導(dǎo)入、導(dǎo)出Excel(Java import、export)demo POI的導(dǎo)出方式:創(chuàng)建/加載Workbook,設(shè)置樣式,填充數(shù)據(jù),然后生成本地臨時(shí)文件,最終以瀏覽器的形式打開(kāi),完成整個(gè)導(dǎo)出動(dòng)作。 demo如下, demo如下, XSSFClientAnchor anchor = new XSSFClientAnchor(int dx1, int dy1,

    2024年02月01日
    瀏覽(19)
  • Java 導(dǎo)出Excel表格生成下拉框-EasyExcel

覺(jué)得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

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

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包