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

如何通過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://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| 亚洲精品熟女av影院| 人人澡人人看人人妻| 国产午夜男人天堂手机| 91久久国产综合精品| 国产精品大片一区二区三区四区| 国产高清av免费在线播放| 最近最新免费成人在线视频| 91麻豆精品国产91久5久久| 欧美日韩亚洲精品内裤| 日韩欧美亚洲国产另类| 日韩成人一级片在线观看| 亚洲欧美精品专区久久| 日韩欧美精品视频一区| 国产熟女系列一区二区三区| 精精国产xxxx视频在线不卡| 成人免费在线视频不卡| 欧美三级精品三级在线| 黄片无毛欧美在线观看| 亚洲精品福利一二三区| 未满十八周岁禁看视频| 日本人妻系列在线播放| 欧美三级特黄在线播放| 免费看欧美黄片在线看| 成人污视频网站在线观看| 亚洲天堂日韩欧美在线一区| 岛国大片一区二区三区| 亚洲人成网站在线免费看| 久久五月精品综网中文字幕| 久久国产精品一品二品| 国产精品一区二区三区激情| 国产精致成人免费视频| 日韩福利小视频在线| 欧美大片免费久久精品| 亚洲视频一区二区精品| 日韩夫妻性生活免费视频| 深夜日本福利在线观看| 日韩在线不卡免费视频一区| 免费观看国产性生活片|