Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add method getUnderlyingObject which returns the internal xssf object… #654

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.genexus.msoffice.excel.exception.ExcelTemplateNotFoundException;
import com.genexus.msoffice.excel.poi.xssf.ExcelCells;
import com.genexus.msoffice.excel.poi.xssf.ExcelWorksheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

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

public XSSFWorkbook getUnderlyingObject(){
return _document.getUnderlyingObject();

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import com.genexus.msoffice.excel.exception.ExcelException;
import com.genexus.msoffice.excel.poi.xssf.ExcelWorksheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

public interface IExcelSpreadsheet
{
Expand Down Expand Up @@ -49,4 +50,6 @@ public interface IExcelSpreadsheet

boolean toggleRow(IExcelWorksheet _currentWorksheet, int i, Boolean visible);
boolean cloneSheet(String sheetName, String newSheetName) throws ExcelException;

XSSFWorkbook getUnderlyingObject();
}
Original file line number Diff line number Diff line change
Expand Up @@ -1110,4 +1110,9 @@ private void applyBorderSide(XSSFCellStyle cellStyle, BorderCellSide bSide, Exce
public enum BorderCellSide {
RIGHT, LEFT, TOP, BOTTOM, DIAGONALUP, DIAGONALDOWN
}

public XSSFCell[] getUnderlyingObject(){
return pCells;

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -487,4 +487,8 @@ public boolean toggleRow(IExcelWorksheet worksheet, int i, Boolean visible) {
return false;
}

public XSSFWorkbook getUnderlyingObject(){
return _workbook;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
import java.util.List;

import com.genexus.msoffice.excel.style.ExcelStyle;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFCellStyle;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.junit.*;

import com.genexus.msoffice.excel.poi.xssf.ExcelCells;
Expand Down Expand Up @@ -1079,6 +1082,32 @@ public void testDateFormat() {
excel.close();
}

@Test
public void testgetUnderlyingObject(){
ExcelSpreadsheetGXWrapper excel = create("testgetUnderlyingObject");
org.apache.poi.xssf.usermodel.XSSFWorkbook workbook2 = excel.getUnderlyingObject();
XSSFSheet testsheet = workbook2.createSheet("test sheet");
workbook2.setActiveSheet(workbook2.getSheetIndex(testsheet));
ExcelCells cells = excel.getCells(1,1,1,1);
XSSFCell underlyingCells = cells.getUnderlyingObject()[1];
underlyingCells.setCellValue("test cell value");

//test using the same excel instance
Assert.assertEquals(excel.getCurrentWorksheet().getName().trim(),"test sheet");
cells = excel.getCell(1,1);
Assert.assertEquals(cells.getText(),"test cell value");

excel.save();
excel.close();

//test after saving and opening the file again
excel = open("testgetUnderlyingObject");
Assert.assertEquals(excel.getCurrentWorksheet().getName().trim(),"test sheet");
cells = excel.getCell(1,1);
Assert.assertEquals(cells.getText(),"test cell value");

}

private void logErrorCodes(ExcelSpreadsheetGXWrapper excel) {
// System.out.println(String.format("%s - %s", excel.getErrCode(), excel.getErrDescription()));
}
Expand All @@ -1096,4 +1125,6 @@ private void ensureFileDoesNotExists(String path){
}
}



}