- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
这是我的第一篇文章,请多多包涵。我正在尝试做一些简单的事情:查看包含公式的电子表格单元格的值。似乎什么都不起作用,我得到的不是正确答案(579),而是“4”。 (输出如下)。该程序创建一个简单的电子表格,其中 A1 和 A2 中包含数字,A3 中包含总和。
import java.io.*;
import jxl.*;
import jxl.Workbook;
import jxl.biff.FormulaData;
import jxl.biff.formula.FormulaException;
import jxl.write.Number;
import jxl.write.*;
import jxl.write.Formula;
import jxl.read.biff.CellValue;
public class ReadCell {
public static void main(String[] args) throws IOException,
jxl.read.biff.BiffException,
WriteException, FormulaException
{
String filename = "readcell.xls";
WritableWorkbook workbook = Workbook.createWorkbook(new File(filename));
WritableSheet ws = workbook.createSheet("Sheet1", 0);
Number n = new Number(0,0,123); // 123 in A1
ws.addCell(n);
n = new Number(0,1,456); // 456 in A2
ws.addCell(n);
Formula f = new Formula(0,2, "A1+A2"); // formula in A3, yields 579
ws.addCell(f);
workbook.write();
workbook.close();
//now try to retrieve the sum of A1 + A2, which is in A3 (value should be 579)
Workbook wb = Workbook.getWorkbook( new File (filename));
Sheet sheet = wb.getSheet(0);
Cell cell = sheet.getCell("A3");
System.out.println("\n\nCell A3 contents = " + cell.getContents());
//that didn't work, maybe try it by casting to a NumberCell?
NumberCell numbercell = (NumberCell)cell;
System.out.println("NumberCell value = " + numbercell.getValue());
System.out.println("NumberCell contents = " + numbercell.getContents());
//that didn't work, maybe try it by casting to a FormulaCell?
FormulaCell fc = (FormulaCell)cell;
System.out.println("FormulaCell contents = " + fc.getContents());
System.out.println("FormulaCell formula = " + fc.getFormula());
//that didn't work, maybe try to get contents by casting to FormulaData?
FormulaData fd = (FormulaData)cell;
System.out.println("FormulaData contents = " + fd.getContents());
System.out.println("FormulaData type = " + fd.getType());
//that didn't work, maybe try to get contents by casting to NumberFormulaCell?
NumberFormulaCell nfc = (NumberFormulaCell)cell;
System.out.println("NumberFormulaCell value = " + nfc.getValue());
System.out.println("NumberFormulaCell contents = " + nfc.getContents());
System.out.println("NumberFormulaCell formula = " + nfc.getFormula());
//that didn't work, try to get contents by casting to CellValue?
CellValue cv = (CellValue)cell;
System.out.println("cellValue contents = " + cv.getContents());
//Nothing works and these casts won't compile:
//Number nnn = (Number)cell;
//NumberFormulaRecord nfr = (NumberFormulaRecord)cell;
wb.close();
}
}
这是输出,“4”应该是“579”
单元格 A3 内容 = 4
NumberCell 值 = 4.0
单元格编号内容 = 4
公式单元格内容 = 4
FormulaCell公式=A1+A2
公式数据内容 = 4
FormulaData 类型 = 数值公式
NumberFormulaCell 值 = 4.0
NumberFormulaCell 内容 = 4
NumberFormulaCell 公式 = A1+A2
单元格值内容 = 4
感谢您提供的任何帮助!
最佳答案
我运行了编写工作簿的代码。然后我在 Excel 中打开工作簿。当我告诉它关闭时,系统提示我一条消息:“当打开由早期版本的 Excel 上次保存的文件时,Microsoft Excel 会重新计算公式”。选择保存后,然后运行读取的代码(但不是写入工作簿的代码),我得到了正确的单元格值 579。当我删除文件并运行您发布的所有代码时,我得到了 4。看起来公式需要先计算才能读取。这篇文章似乎说无法修复它,并假设了原因:Updated excel file still returns old values
关于java - 无法使用 JExcelAPI 检索计算单元格的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36613309/
在 Excel 中,我可以在一个单元格中拥有多种文本样式。有没有办法使用 JExcelApi 创建这样的文件?到目前为止我没有看到任何东西:setCellFormat 是 WritableCell 上
我一直在使用 JExcelAPI 在 Java 中编写和读取 Excel 文件。当我读取由 JExcelAPI 编写的文件时,它工作正常,但如果我使用 OpenOffice 等其他程序修改 .xls
如何使用第三方库? 我已经下载了它,但不确定如何处理它,我是否将它放在我的 Eclipse 项目文件夹等中? 我确实在网站上查看过,但没有结果 谢谢 最佳答案 您需要在项目类路径中设置 jar。导入后
我想知道是否可以使用 Java JExcepAPI 创建一个包含文本“Red Rose Blue Sky”的 Excel 文件单元格(标签),其中“Rose”显示为红色,“Blue”显示为 - 你猜怎
我可以使用以下命令找到 Excel 文档中的行数sheet.getRows();但是我的 Excel 文件中的行长度不同,我怎样才能只获取 1 列中的行数。我发现了 getting rows in f
我为 jExcelApi 类创建了一个包装器,以便轻松地将对象列表导出到 Excel。为了最大限度地减少对象创建,单元格格式被创建为静态字段,并在连续的导出调用中重复使用。但我对日期格式有问题 - 第
我正在使用 JExcelApi 生成 XLS 文件。来自 jxl.format.Colour ,我了解了如何获取“标准 Excel 调色板”中的任何颜色,但没有了解如何创建新颜色(例如,给定其 RGB
首先我要说的是,我对 Java 和这个网站都很陌生。我现在已经读了一两本书,从那时起我就一直在寻找小项目来让自己开心。我尝试对此进行研究,但无法找到我需要的信息。话虽如此,这是我的第一个问题,所以如果
我需要检测单元格内的文本是否被删除。我正在使用这个: Cell cc = sheet.getCell("B1"); CellFormat format = cc.getCellFormat(); Sy
我有一个 Excel 工作表,其中包含一些非英语字符,当我尝试通过 获取内容时 sheet.getColumn(column)[row].getContents() 它返回带有替换字符\uFFFD 的
我使用 jexcelapi for android . 我写字符串“Hello jExcelAPI!”,但是当我读的时候我看到了中文符号。 我该如何解决? 提前致谢。 附言也许有帮助:我不知道需要在
这是我的第一篇文章,请多多包涵。我正在尝试做一些简单的事情:查看包含公式的电子表格单元格的值。似乎什么都不起作用,我得到的不是正确答案(579),而是“4”。 (输出如下)。该程序创建一个简单的电子表
当我添加 JExcelAPI 时 http://jexcelapi.sourceforge.net/到类路径并运行我的应用程序,我得到:编写输出时遇到问题:不应该发生[2009-07-16 14:32
我有一个成功导出到 Excel 的 Jasper 报告,但是所有数字列(当前为 java.math.BigDecimal 类型)在 Excel 中显示为“常规”类型。这使得无法对列进行数字运算(例如添
我正在用 JExcelApi 编写电子表格. 我有两个要应用货币格式的单元格。通过阅读 API,我发现了 jxl.write.NumberFormat,它似乎可以满足我的要求。在我的应用程序中,我写了
我安装了java并设置了路径,运行成功。现在我需要的是如何使用 jexcelapi。我下载了 jexcel api 并将其解压缩。我不知道在哪里放置提取的文件,也不知道如何为 jexcel 文件设置
我正在使用 JExcelApi 生成 xls 文件。现在我需要的是锁定标题,因为我有超过 300 行。 每当我滚动时,我都需要显示标题。谁能帮我解决这个问题。我浏览了很多网站,但没有找到解决方案。 O
在尝试使用 jExcelAPI 读取 xls 文件时,我发现该库在 stderr 中转储了大量信息,有时这些信息不相关。例如,此代码片段会导致大量“警告”转储到 stderr 流上: Work
我尝试使用 JExcelAPI (v. 2.6.3) 在 Java 应用程序中生成一些 Excel 工作表,但无法正确生成日期单元格。例如,对于代码: WritableWorkbook workboo
我正在使用 Java 编写 MS Excel 文件,以及如何设置“跟踪更改”标志,以便我可以看到人们稍后进行修改的位置。如何在 jexcelapi 或 Apache HSSF 中设置此标志? 最佳答案
我是一名优秀的程序员,十分优秀!