I'm currently making a code that creates an Excel using Java jxl. I've encountered no problem as long as the formula I'm using exists. The problem is, I need to input a formula which excel will not be able to find because we use a special excel to read it. I need my code to retain the invalid formula instead of writing =1 ERROR() on the cell so that when my file is opened using our special excel, it gets the value. How do I go about this?
Here is my code:
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);
/** The value in the bid = "BDP("EURON Curncy","PX_BID","DATA")1"; */
f = new Formula(6,nRow,bid,new WritableCellFormat(dp2));
s.addCell(f);
/** The value in the offer = "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();