最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Java設(shè)置Excel數(shù)據(jù)驗證的示例代碼

 更新時間:2022年05月31日 15:39:41   作者:E-iceblue  
數(shù)據(jù)驗證是Excel 2013版本中,數(shù)據(jù)功能組下面的一個功能。本文將通過Java程序代碼演示數(shù)據(jù)驗證的設(shè)置方法及結(jié)果,感興趣的可以了解一下

數(shù)據(jù)驗證是Excel 2013版本中,數(shù)據(jù)功能組下面的一個功能,在Excel2013之前的版本,包含Excel2010 Excel2007稱為數(shù)據(jù)有效性。通過在excel表格中設(shè)置數(shù)據(jù)驗證可有效規(guī)范數(shù)據(jù)輸入。設(shè)置數(shù)據(jù)類型時,可設(shè)置如驗證數(shù)字(數(shù)字區(qū)間/數(shù)字類型)、日期、文本長度等。下面通過Java程序代碼演示數(shù)據(jù)驗證的設(shè)置方法及結(jié)果。

工具:Free Spire.XLS for Java (免費版)

注:可通過官網(wǎng)下載,并解壓將lib文件夾下的jar文件導入java程序;或者通過maven下載導入。

參考如下Jar導入效果:

Java示例(供參考)

import com.spire.xls.*;

public class DataValidation {
    public static void main(String[] args) {
        //創(chuàng)建Workbook對象
        Workbook workbook = new Workbook();

        //獲取第一個工作表
        Worksheet sheet = workbook.getWorksheets().get(0);

        //在單元格B3中設(shè)置數(shù)字驗證-僅允許輸入1到100之間的數(shù)
        sheet.getCellRange("B2").setText("請輸入1-100之間的數(shù):");
        CellRange rangeNumber = sheet.getCellRange("B3");
        rangeNumber.getDataValidation().setCompareOperator(ValidationComparisonOperator.Between);
        rangeNumber.getDataValidation().setFormula1("1");
        rangeNumber.getDataValidation().setFormula2("100");
        rangeNumber.getDataValidation().setAllowType(CellDataType.Decimal);
        rangeNumber.getDataValidation().setErrorMessage("Please input correct number!");
        rangeNumber.getDataValidation().setShowError(true);
        rangeNumber.getCellStyle().setKnownColor(ExcelColors.Color21);

        //在單元格B6中設(shè)置日期驗證-僅允許輸入1/1/1970到12/31/1970之間的日期
        sheet.getCellRange("B5").setText("請輸入1/1/1970-12/31/1970之間的日期:");
        CellRange rangeDate = sheet.getCellRange("B6");
        rangeDate.getDataValidation().setAllowType(CellDataType.Date);
        rangeDate.getDataValidation().setCompareOperator(ValidationComparisonOperator.Between);
        rangeDate.getDataValidation().setFormula1("1/1/1970");
        rangeDate.getDataValidation().setFormula2("12/31/1970");
        rangeDate.getDataValidation().setErrorMessage("Please input correct date!");
        rangeDate.getDataValidation().setShowError(true);
        rangeDate.getDataValidation().setAlertStyle(AlertStyleType.Warning);
        rangeDate.getCellStyle().setKnownColor(ExcelColors.Color16);

        //在單元格B9設(shè)置字符長度驗證-僅允許輸入5個字符以內(nèi)的文本
        sheet.getCellRange("B8").setText("請輸入不超過5個字符的文本:");
        CellRange rangeTextLength = sheet.getCellRange("B9");
        rangeTextLength.getDataValidation().setAllowType(CellDataType.TextLength);
        rangeTextLength.getDataValidation().setCompareOperator(ValidationComparisonOperator.LessOrEqual);
        rangeTextLength.getDataValidation().setFormula1("5");
        rangeTextLength.getDataValidation().setErrorMessage("Enter a Valid String!");
        rangeTextLength.getDataValidation().setShowError(true);
        rangeTextLength.getDataValidation().setAlertStyle(AlertStyleType.Stop);
        rangeTextLength.getCellStyle().setKnownColor(ExcelColors.Color14);

        //在單元格B12設(shè)置數(shù)字驗證-僅允許輸入大于等于18的整數(shù)
        sheet.getCellRange("B11").setText("請輸入大于等于18的整數(shù):");
        CellRange rangeinteger = sheet.getCellRange("B12");
        rangeinteger.getDataValidation().setAllowType(CellDataType.Integer);
        rangeinteger.getDataValidation().setCompareOperator(ValidationComparisonOperator.GreaterOrEqual);
        rangeinteger.getDataValidation().setFormula1("18");
        rangeinteger.getDataValidation().setErrorMessage("Enter a Valid String!");
        rangeinteger.getDataValidation().setShowError(true);
        rangeinteger.getDataValidation().setAlertStyle(AlertStyleType.Stop);
        rangeinteger.getCellStyle().setKnownColor(ExcelColors.LightGreen1);

        //第二列自適應(yīng)寬度
        sheet.autoFitColumn(2);

        //保存文檔
        workbook.saveToFile("DataValidation.xlsx", ExcelVersion.Version2016);
    }
}

數(shù)據(jù)驗證設(shè)置效果:

到此這篇關(guān)于Java設(shè)置Excel數(shù)據(jù)驗證的示例代碼的文章就介紹到這了,更多相關(guān)Java Excel數(shù)據(jù)驗證內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Mybatis返回單個實體或者返回List的實現(xiàn)

    Mybatis返回單個實體或者返回List的實現(xiàn)

    這篇文章主要介紹了Mybatis返回單個實體或者返回List的實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2020-07-07
  • SpringBoot中TypeExcludeFilter的作用及使用方式

    SpringBoot中TypeExcludeFilter的作用及使用方式

    在SpringBoot應(yīng)用程序中,TypeExcludeFilter通過過濾特定類型的組件,使它們不被自動掃描和注冊為bean,這在排除不必要的組件或特定實現(xiàn)類時非常有用,通過創(chuàng)建自定義過濾器并注冊到spring.factories文件中,我們可以在應(yīng)用啟動時生效
    2025-01-01
  • PostgreSQL Docker部署+SpringBoot集成方式

    PostgreSQL Docker部署+SpringBoot集成方式

    本文介紹了如何在Docker中部署PostgreSQL和pgadmin,并通過SpringBoot集成PostgreSQL,主要步驟包括安裝PostgreSQL和pgadmin,配置防火墻,創(chuàng)建數(shù)據(jù)庫和表,以及在SpringBoot中配置數(shù)據(jù)源和實體類
    2024-12-12
  • 利用線程實現(xiàn)動態(tài)顯示系統(tǒng)時間

    利用線程實現(xiàn)動態(tài)顯示系統(tǒng)時間

    編寫Applet小程序,通過在HTML文檔中接收參數(shù),顯示當前的系統(tǒng)時間,需要的朋友可以參考下
    2015-10-10
  • Mybatis-Plus saveBatch()批量保存失效的解決

    Mybatis-Plus saveBatch()批量保存失效的解決

    本文主要介紹了Mybatis-Plus saveBatch()批量保存失效的解決,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2023-01-01
  • Spring-基于Spring使用自定義注解及Aspect實現(xiàn)數(shù)據(jù)庫切換操作

    Spring-基于Spring使用自定義注解及Aspect實現(xiàn)數(shù)據(jù)庫切換操作

    這篇文章主要介紹了Spring-基于Spring使用自定義注解及Aspect實現(xiàn)數(shù)據(jù)庫切換操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-09-09
  • Java代碼讀取文件緩存問題解決

    Java代碼讀取文件緩存問題解決

    最近遇到了一個Java文件讀取的緩存問題,打遠程斷點出現(xiàn)的也是原來的老代碼參數(shù),本文就介紹一下解決方法,感興趣的可以了解一下
    2021-05-05
  • Spring Data分頁與排序的實現(xiàn)方法

    Spring Data分頁與排序的實現(xiàn)方法

    這篇文章主要給大家介紹了關(guān)于Spring Data分頁與排序的實現(xiàn)方法,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2018-12-12
  • Java Collection集合遍歷運行代碼實例

    Java Collection集合遍歷運行代碼實例

    這篇文章主要介紹了Java Collection集合遍歷運行代碼實例,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
    2020-04-04
  • Java精確計算BigDecimal類詳解

    Java精確計算BigDecimal類詳解

    這篇文章主要介紹了Java精確計算BigDecimal類的使用方法,文中通過示例代碼介紹的非常詳細。對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2021-12-12

最新評論

武邑县| 普格县| 荥经县| 双辽市| 汶上县| 长乐市| 东台市| 乌拉特前旗| 谢通门县| 喀喇沁旗| 东明县| 陆良县| 津南区| 青铜峡市| 五家渠市| 长治市| 伊通| 进贤县| 正安县| 同德县| 平罗县| 重庆市| 绥宁县| 绥中县| 府谷县| 荣成市| 阜新市| 理塘县| 宜兴市| 阳山县| 涿鹿县| 温州市| 九寨沟县| 桓台县| 田林县| 黄大仙区| 漾濞| 邹平县| 同德县| 侯马市| 东阿县|