欧美一级特黄大片做受成人-亚洲成人一区二区电影-激情熟女一区二区三区-日韩专区欧美专区国产专区

如何通過Java代碼實(shí)現(xiàn)創(chuàng)建和讀取Excel公式

如何通過Java代碼實(shí)現(xiàn)創(chuàng)建和讀取Excel公式?相信大部分人都還沒學(xué)會這個技能,為了讓大家學(xué)會,給大家總結(jié)了以下內(nèi)容,話不多說,一起往下看吧。

為鐵鋒等地區(qū)用戶提供了全套網(wǎng)頁設(shè)計(jì)制作服務(wù),及鐵鋒網(wǎng)站建設(shè)行業(yè)解決方案。主營業(yè)務(wù)為成都網(wǎng)站制作、成都網(wǎng)站設(shè)計(jì)、鐵鋒網(wǎng)站設(shè)計(jì),以傳統(tǒng)方式定制建設(shè)網(wǎng)站,并提供域名空間備案等一條龍服務(wù),秉承以專業(yè)、用心的態(tài)度為用戶提供真誠的服務(wù)。我們深信只要達(dá)到每一位用戶的要求,就會得到認(rèn)可,從而選擇與我們長期合作。這樣,我們也可以走得更遠(yuǎn)!

這里使用了Excel Java類庫(Free Spire.XLS for Java 免費(fèi)版),在官網(wǎng)下載獲取文件包后,解壓,將lib文件夾下的jar文件導(dǎo)入Java程序;或者通過maven倉庫下載并導(dǎo)入。導(dǎo)入結(jié)果如下:
如何通過Java代碼實(shí)現(xiàn)創(chuàng)建和讀取Excel公式

1. 創(chuàng)建公式

import com.spire.xls.*;

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

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

        //聲明兩個變量
        int currentRow = 1;
        String currentFormula = null;

        //設(shè)置列寬
        sheet.setColumnWidth(1, 32);
        sheet.setColumnWidth(2, 16);

        //寫入用于測試的數(shù)據(jù)到單元格
        sheet.getCellRange(currentRow,1).setValue("測試數(shù)據(jù):");
        sheet.getCellRange(currentRow,2).setNumberValue(1);
        sheet.getCellRange(currentRow,3).setNumberValue(2);
        sheet.getCellRange(currentRow,4).setNumberValue(3);
        sheet.getCellRange(currentRow,5).setNumberValue(4);
        sheet.getCellRange(currentRow,6).setNumberValue(5);

        //寫入文本
        currentRow += 2;
        sheet.getCellRange(currentRow,1).setValue("公式:") ; ;
        sheet.getCellRange(currentRow,2).setValue("結(jié)果:");

        //設(shè)置單元格格式
        CellRange range = sheet.getCellRange(currentRow,1,currentRow,2);
        range.getStyle().getFont().isBold(true);
        range.getStyle().setKnownColor(ExcelColors.LightGreen1);
        range.getStyle().setFillPattern(ExcelPatternType.Solid);
        range.getStyle().getBorders().getByBordersLineType(BordersLineType.EdgeBottom).setLineStyle(LineStyleType.Medium);

        //算數(shù)運(yùn)算
        currentFormula = "=1/2+3*4";
        sheet.getCellRange(++currentRow,1).setText(currentFormula);
        sheet.getCellRange(currentRow,2).setFormula(currentFormula);

        //日期函數(shù)
        currentFormula = "=TODAY()";
        sheet.getCellRange(++currentRow,1).setText(currentFormula);
        sheet.getCellRange(currentRow,2).setFormula(currentFormula);
        sheet.getCellRange(currentRow,2).getStyle().setNumberFormat("YYYY/MM/DD");

        //時間函數(shù)
        currentFormula = "=NOW()";
        sheet.getCellRange(++currentRow,1).setText(currentFormula);
        sheet.getCellRange(currentRow,2).setFormula(currentFormula);
        sheet.getCellRange(currentRow,2).getStyle().setNumberFormat("H:MM AM/PM");

        //IF函數(shù)
        currentFormula = "=IF(B1=5,\"Yes\",\"No\")";
        sheet.getCellRange(++currentRow,1).setText(currentFormula);
        sheet.getCellRange(currentRow,2).setFormula(currentFormula);

        //PI函數(shù)
        currentFormula = "=PI()";
        sheet.getCellRange(++currentRow,1).setText(currentFormula);
        sheet.getCellRange(currentRow,2).setFormula(currentFormula);

        //三角函數(shù)
        currentFormula = "=SIN(PI()/6)";
        sheet.getCellRange(++currentRow,1).setText(currentFormula);
        sheet.getCellRange(currentRow,2).setFormula(currentFormula);

        //計(jì)數(shù)函數(shù)
        currentFormula = "=Count(B1:F1)";
        sheet.getCellRange(++currentRow,1).setText(currentFormula);
        sheet.getCellRange(currentRow,2).setFormula(currentFormula);

        //最大值函數(shù)
        currentFormula = "=MAX(B1:F1)";
        sheet.getCellRange(++currentRow,1).setText(currentFormula);
        sheet.getCellRange(currentRow,2).setFormula(currentFormula);

        //平均值函數(shù)
        currentFormula = "=AVERAGE(B1:F1)";
        sheet.getCellRange(++currentRow,1).setText(currentFormula);
        sheet.getCellRange(currentRow,2).setFormula(currentFormula);

        //求和函數(shù)
        currentFormula = "=SUM(B1:F1)";
        sheet.getCellRange(++currentRow,1).setText(currentFormula);
        sheet.getCellRange(currentRow,2).setFormula(currentFormula);

        //保存文檔
        wb.saveToFile("AddFormulas.xlsx",FileFormat.Version2013);
        wb.dispose();
    }
}

公式創(chuàng)建結(jié)果:
如何通過Java代碼實(shí)現(xiàn)創(chuàng)建和讀取Excel公式

2.讀取公式

import com.spire.xls.*;

public class ReadFormula {
    public static void main(String[] args) {
        //加載Excel文檔
        Workbook wb = new Workbook();
        wb.loadFromFile("AddFormulas.xlsx");

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

        //遍歷B1到B13的單元格
        for (Object cell: sheet.getCellRange("B1:B13"))
        {
            CellRange cellRange = (CellRange)cell;

            //判斷單元格是否含有公式
            if (cellRange.hasFormula())
            {
                //打印單元格及公式
                String certainCell = String.format("單元格[%d, %d]含有公式:", cellRange.getRow(), cellRange.getColumn());
                System.out.println(certainCell + cellRange.getFormula());
            }
        }
    }
}

公式讀取結(jié)果:
如何通過Java代碼實(shí)現(xiàn)創(chuàng)建和讀取Excel公式

看完上述內(nèi)容,你們掌握通過Java代碼實(shí)現(xiàn)創(chuàng)建和讀取Excel公式的方法了嗎?如果還想學(xué)到更多技能或想了解更多相關(guān)內(nèi)容,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝各位的閱讀!

文章標(biāo)題:如何通過Java代碼實(shí)現(xiàn)創(chuàng)建和讀取Excel公式
標(biāo)題路徑:http://www.aaarwkj.com/article24/igjhce.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站維護(hù)、動態(tài)網(wǎng)站、定制網(wǎng)站、品牌網(wǎng)站制作、微信小程序

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

成都網(wǎng)站建設(shè)公司
中文字幕一区二区不卡顿| 成年网站在线91九色| 91精品免费播放在线观看| 亚洲成年人黄色在线观看| 国产一边打电话一边操| 亚洲国产免费一区二区| 尤物视频在线观看羞羞| 亚洲成av人亚洲av| 国产在线不卡中文字幕| 小黄片视频免费在线播放| 中文字幕日韩手机在线| 精品人妻一区二区三区蜜桃电| 久久精品国产亚洲av不丁香| 中文字幕乱码视频日本| 亚洲熟女少妇淫语高潮| 天天操天天射夜夜爽| 91香蕉国产在线观看| 岛国少妇av之中文字幕| 91在线国产精品视频| 丰满少妇一级淫片在线播放| 亚洲福利一区福利三区| 国产精品亚洲欧美日韩在线播放| 青青草视频在线针对华人| 久久精品色妇熟妇丰满人妻| 中文字幕人妻熟女人妻| 国产在线精品91系列| 欧美日韩国产另类在线视频| 亚洲精品视频久久偷拍| 国产视频成人免费观看| 欧美性色黄大片人与善| 免费在线观看污污污网站| 欧美在线免费黄片视频| 中文字幕一区精品日韩| 国产精品三级久久久| 97在线观看免费播放| 国产三级三级精品久久| 国产一区二区三区午夜视频| 国产精品国产三级国产av野外| 日韩无码一区二区视频| 午夜福利视频欧美成人| 亚洲综合美女极品啪啪啪|