Skip to content

Commit 1db61a9

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

File tree

5 files changed

+30
-41
lines changed

5 files changed

+30
-41
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,10 @@ private Boolean saveAsImpl(String newFileName, String password) {
105105
return ok;
106106
}
107107

108-
public ExcelCells getCell(int rowIdx, int colIdx) {
108+
public ExcelCellsGXWrapper getCell(int rowIdx, int colIdx) {
109109
if (initialize()) {
110110
try {
111-
return (ExcelCells) _document.getCell(_currentWorksheet, rowIdx, colIdx);
111+
return _document.getCell(_currentWorksheet, rowIdx, colIdx);
112112
} catch (ExcelException e) {
113113
this.setError(e);
114114
}
@@ -137,10 +137,10 @@ public void setError(String errorMsg, ExcelException e) {
137137
logger.error(errorMsg);
138138
}
139139

140-
public ExcelCells getCells(int rowIdx, int colIdx, int rowCount, int colCount) {
140+
public ExcelCellsGXWrapper getCells(int rowIdx, int colIdx, int rowCount, int colCount) {
141141
if (initialize()) {
142142
try {
143-
return (ExcelCells) _document.getCells(_currentWorksheet, rowIdx, colIdx, rowCount, colCount);
143+
return _document.getCells(_currentWorksheet, rowIdx, colIdx, rowCount, colCount);
144144
} catch (ExcelException e) {
145145
this.setError(e);
146146
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ public interface IExcelSpreadsheet
1414
Boolean close() throws ExcelException;
1515

1616
// CellMethods
17-
IExcelCellRange getCells(IExcelWorksheet worksheet, int startRow, int startCol, int rowCount, int colCount) throws ExcelException;
17+
ExcelCellsGXWrapper getCells(IExcelWorksheet worksheet, int startRow, int startCol, int rowCount, int colCount) throws ExcelException;
1818

19-
IExcelCellRange getCell(IExcelWorksheet worksheet, int startRow, int startCol) throws ExcelException;
19+
ExcelCellsGXWrapper getCell(IExcelWorksheet worksheet, int startRow, int startCol) throws ExcelException;
2020

2121
Boolean insertRow(IExcelWorksheet worksheet, int rowIdx, int rowCount);
2222

gxoffice/src/main/java/com/genexus/msoffice/excel/poi/hssf/ExcelSpreadsheet.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@
77
import java.util.ArrayList;
88
import java.util.List;
99

10-
import com.genexus.msoffice.excel.Constants;
10+
import com.genexus.msoffice.excel.*;
1111
import com.genexus.msoffice.excel.exception.ExcelException;
12-
import com.genexus.msoffice.excel.IExcelSpreadsheet;
13-
import com.genexus.msoffice.excel.IGXError;
1412
import com.genexus.msoffice.excel.exception.ExcelTemplateNotFoundException;
1513
import org.apache.poi.ss.usermodel.Cell;
1614
import org.apache.poi.ss.usermodel.CellStyle;
@@ -24,8 +22,6 @@
2422
import com.genexus.util.GXFile;
2523
import com.genexus.diagnostics.core.ILogger;
2624
import com.genexus.diagnostics.core.LogManager;
27-
import com.genexus.msoffice.excel.IExcelCellRange;
28-
import com.genexus.msoffice.excel.IExcelWorksheet;
2925

3026
public class ExcelSpreadsheet implements IExcelSpreadsheet {
3127
public static final ILogger logger = LogManager.getLogger(ExcelSpreadsheet.class);
@@ -126,11 +122,11 @@ public Boolean close() throws ExcelException {
126122
return save();
127123
}
128124

129-
public IExcelCellRange getCells(IExcelWorksheet worksheet, int startRow, int startCol, int rowCount, int colCount) throws ExcelException {
130-
return new ExcelCells(_errorHandler, this, _workbook, _workbook.getSheet(worksheet.getName()), startRow - 1, startCol - 1, rowCount, colCount, _isReadonly, _stylesCache);
125+
public ExcelCellsGXWrapper getCells(IExcelWorksheet worksheet, int startRow, int startCol, int rowCount, int colCount) throws ExcelException {
126+
return new ExcelCellsGXWrapper(new ExcelCells(_errorHandler, this, _workbook, _workbook.getSheet(worksheet.getName()), startRow - 1, startCol - 1, rowCount, colCount, _isReadonly, _stylesCache));
131127
}
132128

133-
public IExcelCellRange getCell(IExcelWorksheet worksheet, int startRow, int startCol) throws ExcelException {
129+
public ExcelCellsGXWrapper getCell(IExcelWorksheet worksheet, int startRow, int startCol) throws ExcelException {
134130
return getCells(worksheet, startRow, startCol, 1, 1);
135131
}
136132

gxoffice/src/main/java/com/genexus/msoffice/excel/poi/xssf/ExcelSpreadsheet.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@
77
import java.util.ArrayList;
88
import java.util.List;
99

10-
import com.genexus.msoffice.excel.Constants;
10+
import com.genexus.msoffice.excel.*;
1111
import com.genexus.msoffice.excel.exception.ExcelException;
12-
import com.genexus.msoffice.excel.IExcelSpreadsheet;
13-
import com.genexus.msoffice.excel.IGXError;
1412
import com.genexus.msoffice.excel.exception.ExcelTemplateNotFoundException;
1513
import org.apache.poi.ss.usermodel.Cell;
1614
import org.apache.poi.ss.usermodel.CellStyle;
@@ -24,8 +22,6 @@
2422
import com.genexus.util.GXFile;
2523
import com.genexus.diagnostics.core.ILogger;
2624
import com.genexus.diagnostics.core.LogManager;
27-
import com.genexus.msoffice.excel.IExcelCellRange;
28-
import com.genexus.msoffice.excel.IExcelWorksheet;
2925

3026
public class ExcelSpreadsheet implements IExcelSpreadsheet {
3127
public static final ILogger logger = LogManager.getLogger(ExcelSpreadsheet.class);
@@ -127,11 +123,11 @@ public Boolean close() throws ExcelException {
127123
return save();
128124
}
129125

130-
public IExcelCellRange getCells(IExcelWorksheet worksheet, int startRow, int startCol, int rowCount, int colCount) throws ExcelException {
131-
return new ExcelCells(_errorHandler, this, _workbook, _workbook.getSheet(worksheet.getName()), startRow - 1, startCol - 1, rowCount, colCount, _isReadonly, _stylesCache);
126+
public ExcelCellsGXWrapper getCells(IExcelWorksheet worksheet, int startRow, int startCol, int rowCount, int colCount) throws ExcelException {
127+
return new ExcelCellsGXWrapper(new ExcelCells(_errorHandler, this, _workbook, _workbook.getSheet(worksheet.getName()), startRow - 1, startCol - 1, rowCount, colCount, _isReadonly, _stylesCache));
132128
}
133129

134-
public IExcelCellRange getCell(IExcelWorksheet worksheet, int startRow, int startCol) throws ExcelException {
130+
public ExcelCellsGXWrapper getCell(IExcelWorksheet worksheet, int startRow, int startCol) throws ExcelException {
135131
return getCells(worksheet, startRow, startCol, 1, 1);
136132
}
137133

gxoffice/src/test/java/com/genexus/msoffice/excel/ExcelSpreadsheetTest.java

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,9 @@
1010
import java.util.List;
1111

1212
import com.genexus.msoffice.excel.style.ExcelStyle;
13-
import org.junit.*;
14-
15-
import com.genexus.msoffice.excel.poi.xssf.ExcelCells;
16-
import com.genexus.msoffice.excel.poi.xssf.ExcelWorksheet;
1713
import com.genexus.msoffice.excel.style.ExcelAlignment;
1814

15+
import org.junit.*;
1916
import static org.junit.Assert.*;
2017
/**
2118
* Unit test for simple App.
@@ -140,7 +137,7 @@ public void testActiveWorksheet() {
140137
public void testOpenAndSave() {
141138
ExcelSpreadsheetGXWrapper excel = create("testActive");
142139
try {
143-
excel.getCells(2, 1, 5, 5).setDate(new Date());
140+
excel.getCells(2, 1, 5, 5).setDateValue(new Date());
144141
} catch (Exception e) {
145142
e.printStackTrace();
146143
}
@@ -166,7 +163,7 @@ public void testOpenAndSaveLocked() {
166163
Assert.assertEquals("File is locked", 7, excel.getErrCode());
167164

168165
try {
169-
excel.getCells(2, 1, 5, 5).setDate(new Date());
166+
excel.getCells(2, 1, 5, 5).setDateValue(new Date());
170167
} catch (Exception e) {
171168
e.printStackTrace();
172169
}
@@ -186,7 +183,7 @@ public void testFolderNotExists() {
186183
excel.open(excel1);
187184

188185
try {
189-
excel.getCells(2, 1, 5, 5).setDate(new Date());
186+
excel.getCells(2, 1, 5, 5).setDateValue(new Date());
190187
} catch (Exception e) {
191188
e.printStackTrace();
192189
}
@@ -207,7 +204,7 @@ public void testWithoutExtensions() {
207204
excel.insertSheet("genexus1");
208205
excel.insertSheet("genexus2");
209206

210-
List<ExcelWorksheet> wSheets = excel.getWorksheets();
207+
List<IExcelWorksheet> wSheets = excel.getWorksheets();
211208
Assert.assertTrue(wSheets.size() == 3);
212209
Assert.assertTrue(wSheets.get(0).getName() == "genexus0");
213210
Assert.assertTrue(wSheets.get(1).getName() == "genexus1");
@@ -224,7 +221,7 @@ public void testInsertSheet() {
224221
excel.insertSheet("genexus1");
225222
excel.insertSheet("genexus2");
226223

227-
List<ExcelWorksheet> wSheets = excel.getWorksheets();
224+
List<IExcelWorksheet> wSheets = excel.getWorksheets();
228225
Assert.assertTrue(wSheets.size() == 3);
229226
Assert.assertTrue(wSheets.get(0).getName() == "genexus0");
230227
Assert.assertTrue(wSheets.get(1).getName() == "genexus1");
@@ -243,7 +240,7 @@ public void testDeleteSheet() {
243240
excel.insertSheet("gx3");
244241
excel.insertSheet("gx4");
245242

246-
List<ExcelWorksheet> wSheets = excel.getWorksheets();
243+
List<IExcelWorksheet> wSheets = excel.getWorksheets();
247244
Assert.assertTrue(wSheets.size() == 4);
248245
Assert.assertTrue(wSheets.get(0).getName() == "gx1");
249246
Assert.assertTrue(wSheets.get(1).getName() == "gx2");
@@ -432,7 +429,7 @@ public void testGetWorksheets() {
432429
excel.save();
433430
excel.close();
434431
excel = open("testGetWorksheets");
435-
List<ExcelWorksheet> sheets = excel.getWorksheets();
432+
List<IExcelWorksheet> sheets = excel.getWorksheets();
436433
assertEquals("hoja1", sheets.get(0).getName());
437434
assertEquals("hoja2", sheets.get(1).getName());
438435
assertEquals("hoja3", sheets.get(2).getName());
@@ -454,7 +451,7 @@ public void testHiddenCells() {
454451
excel.getCells(1, 1, 3, 3).setCellStyle(style);
455452

456453

457-
ExcelCells cells = excel.getCells(5, 1, 3, 3);
454+
ExcelCellsGXWrapper cells = excel.getCells(5, 1, 3, 3);
458455
cells.setText("texto SI se puede editar");
459456
style = new ExcelStyle();
460457
style.setLocked(false);
@@ -476,7 +473,7 @@ public void testProtectSheet() {
476473
excel.getCells(1, 1, 3, 3).setCellStyle(style);
477474

478475

479-
ExcelCells cells = excel.getCells(5, 1, 3, 3);
476+
ExcelCellsGXWrapper cells = excel.getCells(5, 1, 3, 3);
480477
cells.setText("texto SI se puede editar");
481478
style = new ExcelStyle();
482479
style.setLocked(false);
@@ -542,7 +539,7 @@ public void testCloneSheet() {
542539
excel.save();
543540
excel.close();
544541
excel = open("testCloneSheet");
545-
List<ExcelWorksheet> sheets = excel.getWorksheets();
542+
List<IExcelWorksheet> sheets = excel.getWorksheets();
546543
Assert.assertEquals(4, sheets.size());
547544
excel.close();
548545
}
@@ -556,7 +553,7 @@ public void testCloneSheet2() {
556553
excel.save();
557554
excel.close();
558555
excel = open("testCloneSheet2");
559-
List<ExcelWorksheet> sheets = excel.getWorksheets();
556+
List<IExcelWorksheet> sheets = excel.getWorksheets();
560557
Assert.assertEquals(2, sheets.size());
561558
excel.close();
562559
}
@@ -579,7 +576,7 @@ public void testCloneSheetError() {
579576
excel.save();
580577
excel.close();
581578
excel = open("testCloneSheetError");
582-
List<ExcelWorksheet> sheets = excel.getWorksheets();
579+
List<IExcelWorksheet> sheets = excel.getWorksheets();
583580
Assert.assertEquals(4, sheets.size());
584581
excel.close();
585582
}
@@ -600,7 +597,7 @@ public void testWorksheetRename() {
600597
excel.save();
601598
excel.close();
602599
excel = open("testWorksheetRename");
603-
List<ExcelWorksheet> sheets = excel.getWorksheets();
600+
List<IExcelWorksheet> sheets = excel.getWorksheets();
604601
assertEquals("hoja1", sheets.get(1).getName());
605602
assertEquals("hoja2", sheets.get(2).getName());
606603
assertEquals("modificada", sheets.get(3).getName());
@@ -1026,7 +1023,7 @@ public void testAutoFit() {
10261023
excel.getCells(1, 3, 1, 1).setText("VERYLONGTEXTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT");
10271024
excel.getCells(2, 4, 1, 1).setText("hola!");
10281025
excel.getCells(6, 6, 1, 1).setText("VERYLONGTEXTINDIFFERENTROWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW");
1029-
ExcelCells cells = excel.getCells(7, 7, 1, 1);
1026+
ExcelCellsGXWrapper cells = excel.getCells(7, 7, 1, 1);
10301027
ExcelStyle style = new ExcelStyle();
10311028
style.setDataFormat("#.##"); //change style, so it shows the full number not scientific notation
10321029
cells.setNumericValue(new BigDecimal("123456789123456789123456789"));
@@ -1041,7 +1038,7 @@ public void testDateFormat() {
10411038
excel.setAutofit(true);
10421039
Date date = new Date();
10431040
//sets date with default format
1044-
ExcelCells cells = excel.getCells(1, 1, 1, 1);
1041+
ExcelCellsGXWrapper cells = excel.getCells(1, 1, 1, 1);
10451042
cells.setDateValue(date);
10461043
//sets date and apply format after
10471044
cells = excel.getCells(2, 1, 1, 1);

0 commit comments

Comments
 (0)