Skip to content

Commit 970f61e

Browse files
iroquetaBeta Bot
authored andcommitted
Cherry pick branch 'genexuslabs:fix/implements_xls_support' into beta
1 parent 5897ddd commit 970f61e

13 files changed

+1838
-70
lines changed
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
package com.genexus.msoffice.excel;
2+
3+
import com.genexus.msoffice.excel.style.ExcelStyle;
4+
5+
import java.util.Date;
6+
7+
public class ExcelCellsGXWrapper implements IExcelCellRange {
8+
private IExcelCellRange _cellRange;
9+
10+
public ExcelCellsGXWrapper() {
11+
}
12+
13+
public ExcelCellsGXWrapper(IExcelCellRange cellRange) {
14+
_cellRange = cellRange;
15+
}
16+
17+
@Override
18+
public int getRowStart() {
19+
return _cellRange.getRowStart();
20+
}
21+
22+
@Override
23+
public int getColumnStart() {
24+
return _cellRange.getColumnStart();
25+
}
26+
27+
@Override
28+
public int getRowEnd() {
29+
return _cellRange.getRowEnd();
30+
}
31+
32+
@Override
33+
public int getColumnEnd() {
34+
return _cellRange.getColumnEnd();
35+
}
36+
37+
@Override
38+
public String getValueType() {
39+
return _cellRange.getValueType();
40+
}
41+
42+
@Override
43+
public String getText() {
44+
return _cellRange.getText();
45+
}
46+
47+
@Override
48+
public Boolean setText(String value) {
49+
return _cellRange.setText(value);
50+
}
51+
52+
@Override
53+
public java.math.BigDecimal getNumericValue() {
54+
return _cellRange.getNumericValue();
55+
}
56+
57+
@Override
58+
public Boolean setNumericValue(java.math.BigDecimal d) {
59+
return _cellRange.setNumericValue(d);
60+
}
61+
62+
@Override
63+
public Date getDateValue() {
64+
return _cellRange.getDateValue();
65+
}
66+
67+
@Override
68+
public Boolean setDateValue(Date value) {
69+
return _cellRange.setDateValue(value);
70+
}
71+
72+
@Override
73+
public String getHyperlinkValue() {
74+
return _cellRange.getHyperlinkValue();
75+
}
76+
77+
@Override
78+
public Boolean setHyperlinkValue(String value) {
79+
return _cellRange.setHyperlinkValue(value);
80+
}
81+
82+
@Override
83+
public Boolean empty() {
84+
return _cellRange.empty();
85+
}
86+
87+
@Override
88+
public Boolean mergeCells() {
89+
return _cellRange.mergeCells();
90+
}
91+
92+
@Override
93+
public Boolean setCellStyle(ExcelStyle newCellStyle) {
94+
return _cellRange.setCellStyle(newCellStyle);
95+
}
96+
}

gxoffice/src/main/java/com/genexus/msoffice/excel/ExcelFactory.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
package com.genexus.msoffice.excel;
22

33
import com.genexus.Application;
4-
import com.genexus.msoffice.excel.poi.xssf.ExcelSpreadsheet;
54
import com.genexus.msoffice.excel.exception.ExcelDocumentNotSupported;
65
import com.genexus.msoffice.excel.exception.ExcelTemplateNotFoundException;
7-
import com.genexus.util.GXServices;
86

97
import java.io.File;
108
import java.io.IOException;
@@ -19,11 +17,15 @@ public static IExcelSpreadsheet create(IGXError handler, String filePath, String
1917
filePath = resolvePath(filePath);
2018
template = resolvePath(template);
2119

22-
if (filePath.endsWith(".xlsx") || !filePath.contains("."))
23-
{
24-
return new ExcelSpreadsheet(handler, filePath, template);
20+
if (filePath.toLowerCase().endsWith(".xls")) {
21+
return new com.genexus.msoffice.excel.poi.hssf.ExcelSpreadsheet(handler, filePath, template);
22+
}
23+
else {
24+
if (filePath.toLowerCase().endsWith(".xlsx") || !filePath.contains(".")) {
25+
return new com.genexus.msoffice.excel.poi.xssf.ExcelSpreadsheet(handler, filePath, template);
26+
}
27+
throw new ExcelDocumentNotSupported();
2528
}
26-
throw new ExcelDocumentNotSupported();
2729
}
2830

2931
private static String resolvePath(String filePath) {

gxoffice/src/main/java/com/genexus/msoffice/excel/ExcelSpreadsheetGXWrapper.java

Lines changed: 54 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,26 @@ public class ExcelSpreadsheetGXWrapper implements IGXError {
1717
private int _errCode;
1818
private String _errDescription = "";
1919
private IExcelWorksheet _currentWorksheet;
20-
private List<IExcelWorksheet> _worksheets;
2120
private IExcelSpreadsheet _document;
2221
private Boolean _isReadonly = false;
2322
private Boolean _autofit = false;
2423
private final String DEFAULT_SHEET_NAME = "Sheet";
2524

26-
public Boolean getAutofit() {
27-
return _autofit;
28-
}
25+
private Boolean initialize() {
26+
return initialize(DEFAULT_SHEET_NAME);
27+
}
28+
29+
private Boolean initialize(String defaultSheetName) {
30+
boolean ok = selectFirstDefaultSheet(defaultSheetName);
31+
if (!ok) {
32+
setErrCod((short) 1);
33+
setErrDes("Could not get/set first Sheet on Document");
34+
} else {
35+
setErrCod((short) 0);
36+
setErrDes("");
37+
}
38+
return ok;
39+
}
2940

3041
public void setAutofit(Boolean _autofit) {
3142
this._autofit = _autofit;
@@ -34,23 +45,6 @@ public void setAutofit(Boolean _autofit) {
3445
}
3546
}
3647

37-
private Boolean initialize() {
38-
39-
return initialize(DEFAULT_SHEET_NAME);
40-
}
41-
42-
private Boolean initialize(String defaultSheetName) {
43-
boolean ok = selectFirstDefaultSheet(defaultSheetName);
44-
if (!ok) {
45-
setErrCod((short) 1);
46-
setErrDes("Could not get/set first Sheet on Document");
47-
} else {
48-
setErrCod((short) 0);
49-
setErrDes("");
50-
}
51-
return ok;
52-
}
53-
5448
public boolean open(String filePath) {
5549
return open(filePath, "");
5650
}
@@ -111,10 +105,21 @@ private Boolean saveAsImpl(String newFileName, String password) {
111105
return ok;
112106
}
113107

114-
public ExcelCells getCell(int rowIdx, int colIdx) {
108+
public ExcelCells getCell(int rowIdx, int colIdx) {
109+
if (initialize()) {
110+
try {
111+
return (ExcelCells) _document.getCell(_currentWorksheet, rowIdx, colIdx);
112+
} catch (ExcelException e) {
113+
this.setError(e);
114+
}
115+
}
116+
return null;
117+
}
118+
119+
public ExcelCellsGXWrapper getCellv2(int rowIdx, int colIdx) {
115120
if (initialize()) {
116121
try {
117-
return (ExcelCells) _document.getCell(_currentWorksheet, rowIdx, colIdx);
122+
return new ExcelCellsGXWrapper(_document.getCell(_currentWorksheet, rowIdx, colIdx));
118123
} catch (ExcelException e) {
119124
this.setError(e);
120125
}
@@ -132,10 +137,21 @@ public void setError(String errorMsg, ExcelException e) {
132137
logger.error(errorMsg);
133138
}
134139

135-
public ExcelCells getCells(int rowIdx, int colIdx, int rowCount, int colCount) {
140+
public ExcelCells getCells(int rowIdx, int colIdx, int rowCount, int colCount) {
141+
if (initialize()) {
142+
try {
143+
return (ExcelCells) _document.getCells(_currentWorksheet, rowIdx, colIdx, rowCount, colCount);
144+
} catch (ExcelException e) {
145+
this.setError(e);
146+
}
147+
}
148+
return null;
149+
}
150+
151+
public ExcelCellsGXWrapper getCellsv2(int rowIdx, int colIdx, int rowCount, int colCount) {
136152
if (initialize()) {
137153
try {
138-
return (ExcelCells) _document.getCells(_currentWorksheet, rowIdx, colIdx, rowCount, colCount);
154+
return new ExcelCellsGXWrapper(_document.getCells(_currentWorksheet, rowIdx, colIdx, rowCount, colCount));
139155
} catch (ExcelException e) {
140156
this.setError(e);
141157
}
@@ -157,7 +173,7 @@ public Boolean setCurrentWorksheet(int sheetIdx) {
157173

158174
public Boolean setCurrentWorksheetByName(String sheetName) {
159175
if (initialize()) {
160-
ExcelWorksheet ws = _document.getWorkSheet(sheetName);
176+
IExcelWorksheet ws = _document.getWorkSheet(sheetName);
161177
if (ws != null) {
162178
_currentWorksheet = ws;
163179
_document.setActiveWorkSheet(sheetName);
@@ -174,15 +190,6 @@ public Boolean insertRow(int rowIdx, int rowCount) {
174190
return false;
175191
}
176192

177-
public Boolean insertColumn(int colIdx, int colCount) {
178-
//throw new Exception("NotImplemented");
179-
return false;
180-
/*
181-
* if (isOK()) { //return _document.(_currentWorksheet, colIdx, colCount); }
182-
* return false;
183-
*/
184-
}
185-
186193
public Boolean deleteRow(int rowIdx) {
187194
if (initialize()) {
188195
return _document.deleteRow(_currentWorksheet, rowIdx - 1);
@@ -234,7 +241,7 @@ public Boolean toggleRow(int rowIdx, Boolean visible) {
234241

235242
public Boolean deleteSheet(String sheetName) {
236243
if (initialize()) {
237-
ExcelWorksheet ws = _document.getWorkSheet(sheetName);
244+
IExcelWorksheet ws = _document.getWorkSheet(sheetName);
238245
if (ws != null)
239246
return _document.deleteSheet(sheetName);
240247
}
@@ -279,18 +286,25 @@ public String getErrDescription() {
279286
return _errDescription;
280287
}
281288

282-
public ExcelWorksheet getCurrentWorksheet() {
289+
public ExcelWorksheet getCurrentWorksheet() {
290+
if (initialize()) {
291+
return (ExcelWorksheet) _currentWorksheet;
292+
}
293+
return null;
294+
}
295+
296+
public ExcelWorksheetGXWrapper getCurrentWorksheetv2() {
283297
if (initialize()) {
284-
return (ExcelWorksheet) _currentWorksheet;
298+
return new ExcelWorksheetGXWrapper(_currentWorksheet);
285299
}
286300
return null;
287301
}
288302

289-
public List<ExcelWorksheet> getWorksheets() {
303+
public List<IExcelWorksheet> getWorksheets() {
290304
if (initialize())
291305
return _document.getWorksheets();
292306
else
293-
return new ArrayList<ExcelWorksheet>();
307+
return new ArrayList<IExcelWorksheet>();
294308
}
295309

296310
private boolean selectFirstDefaultSheet(String sheetName) {
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package com.genexus.msoffice.excel;
2+
3+
import com.genexus.msoffice.excel.exception.ExcelException;
4+
5+
public class ExcelWorksheetGXWrapper implements IExcelWorksheet {
6+
private IExcelWorksheet _workSheet;
7+
8+
public ExcelWorksheetGXWrapper() {
9+
}
10+
11+
public ExcelWorksheetGXWrapper(IExcelWorksheet sheet) {
12+
_workSheet = sheet;
13+
}
14+
15+
public String getName() {
16+
return _workSheet.getName();
17+
}
18+
19+
public Boolean setHidden(boolean hidden) {
20+
return _workSheet.setHidden(hidden);
21+
}
22+
23+
public Boolean isHidden() {
24+
return _workSheet.isHidden();
25+
}
26+
27+
public Boolean rename(String newName) {
28+
return _workSheet.rename(newName);
29+
}
30+
31+
public Boolean copy(String newName) {
32+
try {
33+
return _workSheet.copy(newName);
34+
}
35+
catch (ExcelException e) {
36+
return false;
37+
}
38+
}
39+
40+
public void setProtected(String password) {
41+
_workSheet.setProtected(password);
42+
}
43+
}

gxoffice/src/main/java/com/genexus/msoffice/excel/IExcelCellRange.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ public interface IExcelCellRange
1818

1919
int getColumnEnd();
2020

21-
String getCellAdress();
22-
2321
String getValueType();
2422

2523
/*
@@ -44,8 +42,4 @@ public interface IExcelCellRange
4442
Boolean mergeCells();
4543

4644
Boolean setCellStyle(ExcelStyle style);
47-
48-
ExcelStyle getCellStyle();
49-
50-
5145
}

gxoffice/src/main/java/com/genexus/msoffice/excel/IExcelSpreadsheet.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import java.util.List;
44

55
import com.genexus.msoffice.excel.exception.ExcelException;
6-
import com.genexus.msoffice.excel.poi.xssf.ExcelWorksheet;
76

87
public interface IExcelSpreadsheet
98
{
@@ -29,8 +28,8 @@ public interface IExcelSpreadsheet
2928
Boolean deleteColumn(IExcelWorksheet worksheet, int colIdx);
3029

3130
// Worksheets
32-
List<ExcelWorksheet> getWorksheets();
33-
ExcelWorksheet getWorkSheet(String name);
31+
List<IExcelWorksheet> getWorksheets();
32+
IExcelWorksheet getWorkSheet(String name);
3433

3534
Boolean insertWorksheet(String newSheetName, int idx) throws ExcelException;
3635
Boolean getAutofit();

gxoffice/src/main/java/com/genexus/msoffice/excel/IExcelWorksheet.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ public interface IExcelWorksheet
88

99
public Boolean isHidden();
1010

11+
public Boolean setHidden(boolean hidden);
12+
1113
public Boolean rename(String newName);
1214

1315
public Boolean copy(String newName) throws ExcelException;

0 commit comments

Comments
 (0)