蓗乐 2022-01-30 18:37 采纳率: 66.7%
浏览 39
已结题

用spire.xls复制EXCEL表格时,里边的函数为何无法运行?

IF function中的 currentFormula = "IF(A1=H1,I1,J1)";及currentFormula = "=IF(A2=H2,I2,J2))";没有运行,考虑过应该是加载文档的问题。
回复修改后的代码,一经测试成功必采。

直接上问题代码:


import com.spire.xls.*;

public class Test {
    public static void main(String args[]){
        //加载文档
        Workbook wb = new Workbook();
        wb.loadFromFile("原始数据.xlsx");

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

        //Declare two variables: currentRow、currentFormula
        int currentRow = 1;
        String currentFormula = null;

        //Set the column width
        sheet.setColumnWidth(1, 32);
        sheet.setColumnWidth(2, 16);

        //Write test data into cells
        sheet.getCellRange(currentRow,1).setValue("AI.data");
        sheet.getCellRange(currentRow,2).setNumberValue(1);
        sheet.getCellRange(currentRow,3).setNumberValue(2);


        //Write text in cells
        currentRow += 2;
        sheet.getCellRange(currentRow,1).setValue("Formulas or functions:") ; ;
        sheet.getCellRange(currentRow,2).setValue("result:");

        //Format cells
        CellRange range = sheet.getCellRange(currentRow,1,currentRow,2);
        range.getStyle().getFont().isBold(true);
        range.getStyle().setKnownColor(ExcelColors.BlueGray);
        range.getStyle().setFillPattern(ExcelPatternType.Solid);
        range.getStyle().getBorders().getByBordersLineType(BordersLineType.EdgeBottom).setLineStyle(LineStyleType.Medium);

        //IF function
        currentFormula = "IF(A1=H1,I1,J1)";
        sheet.getCellRange(++currentRow,1).setText(currentFormula);
        sheet.getCellRange(currentRow,2).setFormula(currentFormula);

        //IF function
        currentFormula = "=IF(A2=H2,I2,J2))";
        sheet.getCellRange(++currentRow,1).setText(currentFormula);
        sheet.getCellRange(currentRow,2).setFormula(currentFormula);


        //保存文档
        wb.saveToFile("system.xlsx",ExcelVersion.Version2013);
    }
}

img

img

  • 写回答

2条回答 默认 最新

  • 「已注销」 2022-01-30 19:58
    关注

    数据文件发一下

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 2月8日
  • 已采纳回答 1月31日
  • 创建了问题 1月30日

悬赏问题

  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办