Skip to content

Commit fdb72cc

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

File tree

5 files changed

+41
-30
lines changed

5 files changed

+41
-30
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 ExcelCellsGXWrapper getCell(int rowIdx, int colIdx) {
108+
public ExcelCells getCell(int rowIdx, int colIdx) {
109109
if (initialize()) {
110110
try {
111-
return _document.getCell(_currentWorksheet, rowIdx, colIdx);
111+
return (ExcelCells) _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 ExcelCellsGXWrapper getCells(int rowIdx, int colIdx, int rowCount, int colCount) {
140+
public ExcelCells getCells(int rowIdx, int colIdx, int rowCount, int colCount) {
141141
if (initialize()) {
142142
try {
143-
return _document.getCells(_currentWorksheet, rowIdx, colIdx, rowCount, colCount);
143+
return (ExcelCells) _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-
ExcelCellsGXWrapper getCells(IExcelWorksheet worksheet, int startRow, int startCol, int rowCount, int colCount) throws ExcelException;
17+
IExcelCellRange getCells(IExcelWorksheet worksheet, int startRow, int startCol, int rowCount, int colCount) throws ExcelException;
1818

19-
ExcelCellsGXWrapper getCell(IExcelWorksheet worksheet, int startRow, int startCol) throws ExcelException;
19+
IExcelCellRange 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: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
import java.util.ArrayList;
88
import java.util.List;
99

10-
import com.genexus.msoffice.excel.*;
10+
import com.genexus.msoffice.excel.Constants;
1111
import com.genexus.msoffice.excel.exception.ExcelException;
12+
import com.genexus.msoffice.excel.IExcelSpreadsheet;
13+
import com.genexus.msoffice.excel.IGXError;
1214
import com.genexus.msoffice.excel.exception.ExcelTemplateNotFoundException;
1315
import org.apache.poi.ss.usermodel.Cell;
1416
import org.apache.poi.ss.usermodel.CellStyle;
@@ -22,6 +24,8 @@
2224
import com.genexus.util.GXFile;
2325
import com.genexus.diagnostics.core.ILogger;
2426
import com.genexus.diagnostics.core.LogManager;
27+
import com.genexus.msoffice.excel.IExcelCellRange;
28+
import com.genexus.msoffice.excel.IExcelWorksheet;
2529

2630
public class ExcelSpreadsheet implements IExcelSpreadsheet {
2731
public static final ILogger logger = LogManager.getLogger(ExcelSpreadsheet.class);
@@ -122,11 +126,11 @@ public Boolean close() throws ExcelException {
122126
return save();
123127
}
124128

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));
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);
127131
}
128132

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

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

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

10-
import com.genexus.msoffice.excel.*;
10+
import com.genexus.msoffice.excel.Constants;
1111
import com.genexus.msoffice.excel.exception.ExcelException;
12+
import com.genexus.msoffice.excel.IExcelSpreadsheet;
13+
import com.genexus.msoffice.excel.IGXError;
1214
import com.genexus.msoffice.excel.exception.ExcelTemplateNotFoundException;
1315
import org.apache.poi.ss.usermodel.Cell;
1416
import org.apache.poi.ss.usermodel.CellStyle;
@@ -22,6 +24,8 @@
2224
import com.genexus.util.GXFile;
2325
import com.genexus.diagnostics.core.ILogger;
2426
import com.genexus.diagnostics.core.LogManager;
27+
import com.genexus.msoffice.excel.IExcelCellRange;
28+
import com.genexus.msoffice.excel.IExcelWorksheet;
2529

2630
public class ExcelSpreadsheet implements IExcelSpreadsheet {
2731
public static final ILogger logger = LogManager.getLogger(ExcelSpreadsheet.class);
@@ -123,11 +127,11 @@ public Boolean close() throws ExcelException {
123127
return save();
124128
}
125129

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));
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);
128132
}
129133

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

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

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@
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;
1317
import com.genexus.msoffice.excel.style.ExcelAlignment;
1418

15-
import org.junit.*;
1619
import static org.junit.Assert.*;
1720
/**
1821
* Unit test for simple App.
@@ -137,7 +140,7 @@ public void testActiveWorksheet() {
137140
public void testOpenAndSave() {
138141
ExcelSpreadsheetGXWrapper excel = create("testActive");
139142
try {
140-
excel.getCells(2, 1, 5, 5).setDateValue(new Date());
143+
excel.getCells(2, 1, 5, 5).setDate(new Date());
141144
} catch (Exception e) {
142145
e.printStackTrace();
143146
}
@@ -163,7 +166,7 @@ public void testOpenAndSaveLocked() {
163166
Assert.assertEquals("File is locked", 7, excel.getErrCode());
164167

165168
try {
166-
excel.getCells(2, 1, 5, 5).setDateValue(new Date());
169+
excel.getCells(2, 1, 5, 5).setDate(new Date());
167170
} catch (Exception e) {
168171
e.printStackTrace();
169172
}
@@ -183,7 +186,7 @@ public void testFolderNotExists() {
183186
excel.open(excel1);
184187

185188
try {
186-
excel.getCells(2, 1, 5, 5).setDateValue(new Date());
189+
excel.getCells(2, 1, 5, 5).setDate(new Date());
187190
} catch (Exception e) {
188191
e.printStackTrace();
189192
}
@@ -204,7 +207,7 @@ public void testWithoutExtensions() {
204207
excel.insertSheet("genexus1");
205208
excel.insertSheet("genexus2");
206209

207-
List<IExcelWorksheet> wSheets = excel.getWorksheets();
210+
List<ExcelWorksheet> wSheets = excel.getWorksheets();
208211
Assert.assertTrue(wSheets.size() == 3);
209212
Assert.assertTrue(wSheets.get(0).getName() == "genexus0");
210213
Assert.assertTrue(wSheets.get(1).getName() == "genexus1");
@@ -221,7 +224,7 @@ public void testInsertSheet() {
221224
excel.insertSheet("genexus1");
222225
excel.insertSheet("genexus2");
223226

224-
List<IExcelWorksheet> wSheets = excel.getWorksheets();
227+
List<ExcelWorksheet> wSheets = excel.getWorksheets();
225228
Assert.assertTrue(wSheets.size() == 3);
226229
Assert.assertTrue(wSheets.get(0).getName() == "genexus0");
227230
Assert.assertTrue(wSheets.get(1).getName() == "genexus1");
@@ -240,7 +243,7 @@ public void testDeleteSheet() {
240243
excel.insertSheet("gx3");
241244
excel.insertSheet("gx4");
242245

243-
List<IExcelWorksheet> wSheets = excel.getWorksheets();
246+
List<ExcelWorksheet> wSheets = excel.getWorksheets();
244247
Assert.assertTrue(wSheets.size() == 4);
245248
Assert.assertTrue(wSheets.get(0).getName() == "gx1");
246249
Assert.assertTrue(wSheets.get(1).getName() == "gx2");
@@ -429,7 +432,7 @@ public void testGetWorksheets() {
429432
excel.save();
430433
excel.close();
431434
excel = open("testGetWorksheets");
432-
List<IExcelWorksheet> sheets = excel.getWorksheets();
435+
List<ExcelWorksheet> sheets = excel.getWorksheets();
433436
assertEquals("hoja1", sheets.get(0).getName());
434437
assertEquals("hoja2", sheets.get(1).getName());
435438
assertEquals("hoja3", sheets.get(2).getName());
@@ -451,7 +454,7 @@ public void testHiddenCells() {
451454
excel.getCells(1, 1, 3, 3).setCellStyle(style);
452455

453456

454-
ExcelCellsGXWrapper cells = excel.getCells(5, 1, 3, 3);
457+
ExcelCells cells = excel.getCells(5, 1, 3, 3);
455458
cells.setText("texto SI se puede editar");
456459
style = new ExcelStyle();
457460
style.setLocked(false);
@@ -473,7 +476,7 @@ public void testProtectSheet() {
473476
excel.getCells(1, 1, 3, 3).setCellStyle(style);
474477

475478

476-
ExcelCellsGXWrapper cells = excel.getCells(5, 1, 3, 3);
479+
ExcelCells cells = excel.getCells(5, 1, 3, 3);
477480
cells.setText("texto SI se puede editar");
478481
style = new ExcelStyle();
479482
style.setLocked(false);
@@ -539,7 +542,7 @@ public void testCloneSheet() {
539542
excel.save();
540543
excel.close();
541544
excel = open("testCloneSheet");
542-
List<IExcelWorksheet> sheets = excel.getWorksheets();
545+
List<ExcelWorksheet> sheets = excel.getWorksheets();
543546
Assert.assertEquals(4, sheets.size());
544547
excel.close();
545548
}
@@ -553,7 +556,7 @@ public void testCloneSheet2() {
553556
excel.save();
554557
excel.close();
555558
excel = open("testCloneSheet2");
556-
List<IExcelWorksheet> sheets = excel.getWorksheets();
559+
List<ExcelWorksheet> sheets = excel.getWorksheets();
557560
Assert.assertEquals(2, sheets.size());
558561
excel.close();
559562
}
@@ -576,7 +579,7 @@ public void testCloneSheetError() {
576579
excel.save();
577580
excel.close();
578581
excel = open("testCloneSheetError");
579-
List<IExcelWorksheet> sheets = excel.getWorksheets();
582+
List<ExcelWorksheet> sheets = excel.getWorksheets();
580583
Assert.assertEquals(4, sheets.size());
581584
excel.close();
582585
}
@@ -597,7 +600,7 @@ public void testWorksheetRename() {
597600
excel.save();
598601
excel.close();
599602
excel = open("testWorksheetRename");
600-
List<IExcelWorksheet> sheets = excel.getWorksheets();
603+
List<ExcelWorksheet> sheets = excel.getWorksheets();
601604
assertEquals("hoja1", sheets.get(1).getName());
602605
assertEquals("hoja2", sheets.get(2).getName());
603606
assertEquals("modificada", sheets.get(3).getName());
@@ -1023,7 +1026,7 @@ public void testAutoFit() {
10231026
excel.getCells(1, 3, 1, 1).setText("VERYLONGTEXTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT");
10241027
excel.getCells(2, 4, 1, 1).setText("hola!");
10251028
excel.getCells(6, 6, 1, 1).setText("VERYLONGTEXTINDIFFERENTROWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW");
1026-
ExcelCellsGXWrapper cells = excel.getCells(7, 7, 1, 1);
1029+
ExcelCells cells = excel.getCells(7, 7, 1, 1);
10271030
ExcelStyle style = new ExcelStyle();
10281031
style.setDataFormat("#.##"); //change style, so it shows the full number not scientific notation
10291032
cells.setNumericValue(new BigDecimal("123456789123456789123456789"));
@@ -1038,7 +1041,7 @@ public void testDateFormat() {
10381041
excel.setAutofit(true);
10391042
Date date = new Date();
10401043
//sets date with default format
1041-
ExcelCellsGXWrapper cells = excel.getCells(1, 1, 1, 1);
1044+
ExcelCells cells = excel.getCells(1, 1, 1, 1);
10421045
cells.setDateValue(date);
10431046
//sets date and apply format after
10441047
cells = excel.getCells(2, 1, 1, 1);

0 commit comments

Comments
 (0)