Skip to content

Commit 0ef1ee7

Browse files
Add method getUnderlyingObject which returns the internal xssf object for the workbook and the cells in excel spreadsheet
1 parent c363b38 commit 0ef1ee7

File tree

5 files changed

+48
-0
lines changed

5 files changed

+48
-0
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import com.genexus.msoffice.excel.exception.ExcelTemplateNotFoundException;
1212
import com.genexus.msoffice.excel.poi.xssf.ExcelCells;
1313
import com.genexus.msoffice.excel.poi.xssf.ExcelWorksheet;
14+
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
1415

1516
public class ExcelSpreadsheetGXWrapper implements IGXError {
1617
private static final ILogger logger = LogManager.getLogger(ExcelSpreadsheetGXWrapper.class);
@@ -333,4 +334,8 @@ public void setErrDes(String arg0) {
333334
_errDescription = arg0;
334335
}
335336

337+
public XSSFWorkbook getUnderlyingObject(){
338+
return _document.getUnderlyingObject();
339+
340+
}
336341
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import com.genexus.msoffice.excel.exception.ExcelException;
66
import com.genexus.msoffice.excel.poi.xssf.ExcelWorksheet;
7+
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
78

89
public interface IExcelSpreadsheet
910
{
@@ -49,4 +50,6 @@ public interface IExcelSpreadsheet
4950

5051
boolean toggleRow(IExcelWorksheet _currentWorksheet, int i, Boolean visible);
5152
boolean cloneSheet(String sheetName, String newSheetName) throws ExcelException;
53+
54+
XSSFWorkbook getUnderlyingObject();
5255
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,4 +1110,9 @@ private void applyBorderSide(XSSFCellStyle cellStyle, BorderCellSide bSide, Exce
11101110
public enum BorderCellSide {
11111111
RIGHT, LEFT, TOP, BOTTOM, DIAGONALUP, DIAGONALDOWN
11121112
}
1113+
1114+
public XSSFCell[] getUnderlyingObject(){
1115+
return pCells;
1116+
1117+
}
11131118
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,4 +487,8 @@ public boolean toggleRow(IExcelWorksheet worksheet, int i, Boolean visible) {
487487
return false;
488488
}
489489

490+
public XSSFWorkbook getUnderlyingObject(){
491+
return _workbook;
492+
}
493+
490494
}

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

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

1212
import com.genexus.msoffice.excel.style.ExcelStyle;
13+
import org.apache.poi.xssf.usermodel.XSSFCell;
14+
import org.apache.poi.xssf.usermodel.XSSFCellStyle;
15+
import org.apache.poi.xssf.usermodel.XSSFSheet;
1316
import org.junit.*;
1417

1518
import com.genexus.msoffice.excel.poi.xssf.ExcelCells;
@@ -1079,6 +1082,32 @@ public void testDateFormat() {
10791082
excel.close();
10801083
}
10811084

1085+
@Test
1086+
public void testgetUnderlyingObject(){
1087+
ExcelSpreadsheetGXWrapper excel = create("testgetUnderlyingObject");
1088+
org.apache.poi.xssf.usermodel.XSSFWorkbook workbook2 = excel.getUnderlyingObject();
1089+
XSSFSheet testsheet = workbook2.createSheet("test sheet");
1090+
workbook2.setActiveSheet(workbook2.getSheetIndex(testsheet));
1091+
ExcelCells cells = excel.getCells(1,1,1,1);
1092+
XSSFCell underlyingCells = cells.getUnderlyingObject()[1];
1093+
underlyingCells.setCellValue("test cell value");
1094+
1095+
//test using the same excel instance
1096+
Assert.assertEquals(excel.getCurrentWorksheet().getName().trim(),"test sheet");
1097+
cells = excel.getCell(1,1);
1098+
Assert.assertEquals(cells.getText(),"test cell value");
1099+
1100+
excel.save();
1101+
excel.close();
1102+
1103+
//test after saving and opening the file again
1104+
excel = open("testgetUnderlyingObject");
1105+
Assert.assertEquals(excel.getCurrentWorksheet().getName().trim(),"test sheet");
1106+
cells = excel.getCell(1,1);
1107+
Assert.assertEquals(cells.getText(),"test cell value");
1108+
1109+
}
1110+
10821111
private void logErrorCodes(ExcelSpreadsheetGXWrapper excel) {
10831112
// System.out.println(String.format("%s - %s", excel.getErrCode(), excel.getErrDescription()));
10841113
}
@@ -1096,4 +1125,6 @@ private void ensureFileDoesNotExists(String path){
10961125
}
10971126
}
10981127

1128+
1129+
10991130
}

0 commit comments

Comments
 (0)