[ mvasicdo @ 19.12.2007. 13:53 ] @
| Da li je moguci iz SWT aplikacije tj. iz Tabele upisati podatke u Excel fajl?
1. interesuje me upis u postojeci fajl, tako da mu ja odredim od koje celije ide koja kolona
2. u novi fajl.
3. otvaranje postojeceg excel fajla u nekoj SWT kontroli, da li postoji ta kontrola |
[ Dejan Lozanovic @ 20.12.2007. 13:19 ] @
Pogledaj
http://poi.apache.org/ ova biblioteka ti omogucava manipulaciju sa excel fajlovima.
[ toroman @ 23.12.2007. 19:19 ] @
Hm, ostalo je nedorečeno kako posle otvoriti Excel fajl unutar SWT aplikacije. Pa, najlakše pomoću OLE frejma.
[ mvasicdo @ 10.01.2008. 09:20 ] @
Probao sam i nije lose, ali desava mi se jedan problem:
Kada hocu da izvrsim formulu u odredjenoj celiji dobijem ovu gresku:
Error: ) Expected
Exception in thread "main" java.lang.RuntimeException: Cannot Parse, sorry : ) Expected @ 18 [Formula String was: 'PRODUCT(A1*(B1/2)%)']
at org.apache.poi.hssf.model.FormulaParser.Abort(FormulaParser.java:114)
at org.apache.poi.hssf.model.FormulaParser.Expected(FormulaParser.java:121)
at org.apache.poi.hssf.model.FormulaParser.Match(FormulaParser.java:181)
at org.apache.poi.hssf.model.FormulaParser.function(FormulaParser.java:342)
at org.apache.poi.hssf.model.FormulaParser.Ident(FormulaParser.java:280)
at org.apache.poi.hssf.model.FormulaParser.Factor(FormulaParser.java:505)
at org.apache.poi.hssf.model.FormulaParser.Term(FormulaParser.java:606)
at org.apache.poi.hssf.model.FormulaParser.Expression(FormulaParser.java:654)
at org.apache.poi.hssf.model.FormulaParser.parse(FormulaParser.java:758)
at org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator.internalEvaluate(HSSFFormulaEvaluator.java:296)
at org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator.evaluateInCell(HSSFFormulaEvaluator.java:223)
at Test.<init>(Test.java:37)
at Test.main(Test.java:74)
Zbog cega se ovo desava.
Evo i dio koda koji koristim:
FileInputStream fis=null;
HSSFWorkbook wb=null;
HSSFSheet sheet=null;
try{
fis = new FileInputStream("C:/test.xls");
wb = new HSSFWorkbook(fis);
sheet = wb.getSheetAt(0);
}catch(Exception e){}
// suppose your formula is in B3
HSSFRow row = sheet.getRow((short)0);
HSSFCell cell1 = row.getCell((short)0);
cell1.setCellValue(2.80f);
HSSFCell cell2 = row.getCell((short)1);
cell2.setCellValue(6.20f);
HSSFCell cell = row.getCell((short)2);
HSSFFormulaEvaluator evaluator = new HSSFFormulaEvaluator(sheet, wb);
evaluator.setCurrentRow(row);
if (cell!=null) {
switch (evaluator.evaluateInCell(cell).getCellType()) {
case HSSFCell.CELL_TYPE_BOOLEAN:
System.out.println(cell.getBooleanCellValue());
break;
case HSSFCell.CELL_TYPE_NUMERIC:
System.out.println(cell.getNumericCellValue());
break;
case HSSFCell.CELL_TYPE_STRING:
System.out.println(cell.getStringCellValue());
break;
case HSSFCell.CELL_TYPE_BLANK:
break;
case HSSFCell.CELL_TYPE_ERROR:
System.out.println(cell.getErrorCellValue());
break;
// CELL_TYPE_FORMULA will never occur
case HSSFCell.CELL_TYPE_FORMULA:
break;
}
}
try{
FileOutputStream fileOut = new FileOutputStream("C:/test.xls");
wb.write(fileOut);
fileOut.close();
}catch(Exception e){
}
Copyright (C) 2001-2025 by www.elitesecurity.org. All rights reserved.