]>
git.argeo.org Git - gpl/argeo-suite.git/blob - org.argeo.suite.workbench.rap/src/org/argeo/suite/workbench/commands/JxlUtils.java
1 package org
.argeo
.suite
.workbench
.commands
;
3 import java
.io
.IOException
;
4 import java
.io
.InputStream
;
6 import org
.argeo
.connect
.ConnectException
;
7 import org
.argeo
.eclipse
.ui
.EclipseUiUtils
;
11 import jxl
.JXLException
;
14 import jxl
.WorkbookSettings
;
16 /** Centralise useful methods to simplify development with JXL library */
19 public static boolean isEmptyCell(Sheet sheet
, int x
, int y
) {
20 Cell cell
= sheet
.getCell(x
, y
);
21 CellType type
= cell
.getType();
22 return type
== CellType
.EMPTY
;
25 public static String
getStringValue(Sheet sheet
, int x
, int y
) {
26 Cell cell
= sheet
.getCell(x
, y
);
27 CellType type
= cell
.getType();
28 String stringValue
= null;
29 if (type
== CellType
.LABEL
|| type
== CellType
.NUMBER
)
30 stringValue
= cell
.getContents();
34 public static String
getCompulsoryStringValue(Sheet sheet
, int x
, int y
) {
35 Cell cell
= sheet
.getCell(x
, y
);
36 CellType type
= cell
.getType();
37 String stringValue
= null;
38 if (type
== CellType
.LABEL
)
39 stringValue
= cell
.getContents();
40 else if (type
== CellType
.NUMBER
)
41 stringValue
= cell
.getContents();
42 if (EclipseUiUtils
.isEmpty(stringValue
))
43 throw new ConnectException("No name defined at [" + x
+ "," + y
+ "], cannot parse indicator file");
47 public static Double
getNumberValue(Sheet sheet
, int x
, int y
) {
48 Cell cell
= sheet
.getCell(x
, y
);
49 CellType type
= cell
.getType();
50 if (type
== CellType
.NUMBER
)
51 return new Double(cell
.getContents());
52 else if (type
== CellType
.EMPTY
)
55 throw new ConnectException("Not a number at [" + x
+ "," + y
+ "]: " + type
.toString());
58 public static Sheet
getOnlySheet(InputStream in
, String encoding
) throws IOException
{
59 Workbook wkb
= toWorkbook(in
, encoding
);
60 Sheet sheet
= wkb
.getSheet(0);
64 public static Sheet
getSheet(InputStream in
, String encoding
, int index
) throws IOException
{
65 Workbook wkb
= toWorkbook(in
, encoding
);
66 return wkb
.getSheet(index
);
69 public static Workbook
toWorkbook(InputStream in
, String encoding
) throws IOException
{
71 WorkbookSettings ws
= new WorkbookSettings();
72 ws
.setEncoding(encoding
);
73 return Workbook
.getWorkbook(in
, ws
);
74 } catch (JXLException e
) {
75 throw new ConnectException("Unable to open XLS file", e
);
79 // Prevents instantiation