如何使用Java在Excel中input无效的公式

我目前正在创build一个使用Java jxl创buildExcel的代码。 只要我使用的公式存在,我就没有遇到任何问题。 问题是,我需要input一个excel无法find的公式,因为我们使用了一个特殊的excel来读取它。 我需要我的代码来保留无效的公式,而不是在单元格上写入= 1 ERROR(),这样当我的文件用我们特殊的excel打开时,它会得到值。 我如何去做这件事?

这是我的代码:

WorkbookSettings ws = new WorkbookSettings(); ws.setLocale(new Locale("en", "EN")); workbook = Workbook.createWorkbook(file, ws); WritableSheet s = workbook.createSheet("Sheet1", 0); WritableFont wf = new WritableFont(WritableFont.ARIAL, 10, WritableFont.NO_BOLD); DateFormat dateFormat = new DateFormat("M/d/yyyy H:mm"); NumberFormat dp = new NumberFormat("#"); NumberFormat dp2 = new NumberFormat("#.##"); ResultSetMetaData rsmd = rs.getMetaData(); int nRow = 0; Label l = null; Formula f = null; for(int index = 1; index <= rsmd.getColumnCount(); index++) { l = new Label(index-1,nRow,rsmd.getColumnName(index),new WritableCellFormat(wf)); s.addCell(l); } nRow++; while(rs.next()) { String valueDate = VerifyNull.ifNull(rs.getString(1), Constant.BLANK); f = new Formula(0,nRow,valueDate,new WritableCellFormat(dp)); s.addCell(f); String rateDate = VerifyNull.ifNull(rs.getString(2), Constant.BLANK); f = new Formula(1,nRow,rateDate,new WritableCellFormat(dp)); s.addCell(f); String market = VerifyNull.ifNull(rs.getString(3), Constant.BLANK); l = new Label(3,nRow,market,new WritableCellFormat(wf)); s.addCell(l); String ccy = VerifyNull.ifNull(rs.getString(4), Constant.BLANK); l = new Label(4,nRow,ccy,new WritableCellFormat(wf)); s.addCell(l); String label = VerifyNull.ifNull(rs.getString(5), Constant.BLANK); l = new Label(5,nRow,label,new WritableCellFormat(wf)); s.addCell(l); String quoteDate = VerifyNull.ifNull(rs.getString(6), Constant.BLANK); f = new Formula(1,nRow,quoteDate,new WritableCellFormat(dp)); s.addCell(f); String bid = "="+VerifyNull.ifNull(rs.getString(7), Constant.BLANK); 

/ **出价中的值=“BDP(”EURON Curncy“,”PX_BID“,”DATA“) 1”; * /

  f = new Formula(6,nRow,bid,new WritableCellFormat(dp2)); s.addCell(f); 

/ **报价中的值=“BDP(”EURON Curncy“,”PX_ASK“,”DATA“) 1”; * /

  String offer = "="+VerifyNull.ifNull(rs.getString(8), Constant.BLANK); f = new Formula(7,nRow,offer,new WritableCellFormat(dp2)); s.addCell(f); String timeStamp = VerifyNull.ifNull(rs.getString(9), Constant.BLANK); f = new Formula(8,nRow,timeStamp,new WritableCellFormat(dateFormat)); s.addCell(f); nRow++; } workbook.write(); workbook.close(); 

我认为你的“特殊的Excel”是你有一个可视化的基本function插入使用单元格公式

我不知道如果当前版本的JXL支持macros或至less不修改现有的工作簿时删除它,但在您的代码中您不更新现有的工作簿,您正在创build一个新的

你有没有试图用你的代码打开一个现有的工作簿,其中的视觉基本function的作品? (可以是空的)。 如果有效,可以将该文件用作模板,将其复制到所需的位置,重命名该文件,然后使用JXL进行编辑

对不起,我只有时间快速回复,但你有没有看过Apache POI呢? 它的API可能对你有用。

但是,我不是100%确定这是写Excel,因为我认为它的主要用途是读MS Office文件。 不过,也许值得一看。

问题是,我需要input一个excel无法find的公式,因为我们使用了一个特殊的excel来读取它。 我需要我的代码来保留无效的公式,而不是在单元格上写入= 1 ERROR(),这样当我的文件用我们特殊的excel打开时,它会得到值。

你的问题不是JExcel或POI。 没有API将能够帮助你find一个无法find的公式。

什么是这个“特殊的优秀”? 如果是另一个文件,只需读入并使用它。

你的问题很混乱 我很难理解究竟发生了什么。 除非你能澄清,否则我投票结束。