日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > java >内容正文

java

java excel添加公式_Java 添加、读取 Excel 公式

發(fā)布時間:2023/12/20 java 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java excel添加公式_Java 添加、读取 Excel 公式 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

import com.spire.xls.*;public classInsertFormulas {public static voidmain(String[] args) {//創(chuàng)建Workbook對象

Workbook workbook = newWorkbook();//獲取第一個工作表

Worksheet sheet = workbook.getWorksheets().get(0);//聲明兩個變量

int currentRow = 1;

String currentFormula= null;//設(shè)置列寬

sheet.setColumnWidth(1, 26);

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ù)運算

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);//計數(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);//保存文檔

workbook.saveToFile("InsertFormulas.xlsx",FileFormat.Version2013);

}

}

總結(jié)

以上是生活随笔為你收集整理的java excel添加公式_Java 添加、读取 Excel 公式的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。