Skip to content
Merged
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
@@ -0,0 +1,96 @@
package com.genexus.msoffice.excel;

import com.genexus.msoffice.excel.style.ExcelStyle;

import java.util.Date;

public class ExcelCellsGXWrapper implements IExcelCellRange {
private IExcelCellRange _cellRange;

public ExcelCellsGXWrapper() {
}

public ExcelCellsGXWrapper(IExcelCellRange cellRange) {
_cellRange = cellRange;
}

@Override
public int getRowStart() {
return _cellRange.getRowStart();
}

@Override
public int getColumnStart() {
return _cellRange.getColumnStart();
}

@Override
public int getRowEnd() {
return _cellRange.getRowEnd();
}

@Override
public int getColumnEnd() {
return _cellRange.getColumnEnd();
}

@Override
public String getValueType() {
return _cellRange.getValueType();
}

@Override
public String getText() {
return _cellRange.getText();
}

@Override
public Boolean setText(String value) {
return _cellRange.setText(value);
}

@Override
public java.math.BigDecimal getNumericValue() {
return _cellRange.getNumericValue();
}

@Override
public Boolean setNumericValue(java.math.BigDecimal d) {
return _cellRange.setNumericValue(d);
}

@Override
public Date getDateValue() {
return _cellRange.getDateValue();
}

@Override
public Boolean setDateValue(Date value) {
return _cellRange.setDateValue(value);
}

@Override
public String getHyperlinkValue() {
return _cellRange.getHyperlinkValue();
}

@Override
public Boolean setHyperlinkValue(String value) {
return _cellRange.setHyperlinkValue(value);
}

@Override
public Boolean empty() {
return _cellRange.empty();
}

@Override
public Boolean mergeCells() {
return _cellRange.mergeCells();
}

@Override
public Boolean setCellStyle(ExcelStyle newCellStyle) {
return _cellRange.setCellStyle(newCellStyle);
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package com.genexus.msoffice.excel;

import com.genexus.Application;
import com.genexus.msoffice.excel.poi.xssf.ExcelSpreadsheet;
import com.genexus.msoffice.excel.exception.ExcelDocumentNotSupported;
import com.genexus.msoffice.excel.exception.ExcelTemplateNotFoundException;
import com.genexus.util.GXServices;

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

if (filePath.endsWith(".xlsx") || !filePath.contains("."))
{
return new ExcelSpreadsheet(handler, filePath, template);
if (filePath.toLowerCase().endsWith(".xls")) {
return new com.genexus.msoffice.excel.poi.hssf.ExcelSpreadsheet(handler, filePath, template);
}
else {
if (filePath.toLowerCase().endsWith(".xlsx") || !filePath.contains(".")) {
return new com.genexus.msoffice.excel.poi.xssf.ExcelSpreadsheet(handler, filePath, template);
}
throw new ExcelDocumentNotSupported();
}
throw new ExcelDocumentNotSupported();
}

private static String resolvePath(String filePath) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,26 @@ public class ExcelSpreadsheetGXWrapper implements IGXError {
private int _errCode;
private String _errDescription = "";
private IExcelWorksheet _currentWorksheet;
private List<IExcelWorksheet> _worksheets;
private IExcelSpreadsheet _document;
private Boolean _isReadonly = false;
private Boolean _autofit = false;
private final String DEFAULT_SHEET_NAME = "Sheet";

public Boolean getAutofit() {
return _autofit;
}
private Boolean initialize() {
return initialize(DEFAULT_SHEET_NAME);
}

private Boolean initialize(String defaultSheetName) {
boolean ok = selectFirstDefaultSheet(defaultSheetName);
if (!ok) {
setErrCod((short) 1);
setErrDes("Could not get/set first Sheet on Document");
} else {
setErrCod((short) 0);
setErrDes("");
}
return ok;
}

public void setAutofit(Boolean _autofit) {
this._autofit = _autofit;
Expand All @@ -34,23 +45,6 @@ public void setAutofit(Boolean _autofit) {
}
}

private Boolean initialize() {

return initialize(DEFAULT_SHEET_NAME);
}

private Boolean initialize(String defaultSheetName) {
boolean ok = selectFirstDefaultSheet(defaultSheetName);
if (!ok) {
setErrCod((short) 1);
setErrDes("Could not get/set first Sheet on Document");
} else {
setErrCod((short) 0);
setErrDes("");
}
return ok;
}

public boolean open(String filePath) {
return open(filePath, "");
}
Expand Down Expand Up @@ -111,10 +105,21 @@ private Boolean saveAsImpl(String newFileName, String password) {
return ok;
}

public ExcelCells getCell(int rowIdx, int colIdx) {
public ExcelCells getCell(int rowIdx, int colIdx) {
if (initialize()) {
try {
return (ExcelCells) _document.getCell(_currentWorksheet, rowIdx, colIdx);
} catch (ExcelException e) {
this.setError(e);
}
}
return null;
}

public ExcelCellsGXWrapper getCellv2(int rowIdx, int colIdx) {
if (initialize()) {
try {
return (ExcelCells) _document.getCell(_currentWorksheet, rowIdx, colIdx);
return new ExcelCellsGXWrapper(_document.getCell(_currentWorksheet, rowIdx, colIdx));
} catch (ExcelException e) {
this.setError(e);
}
Expand All @@ -132,10 +137,21 @@ public void setError(String errorMsg, ExcelException e) {
logger.error(errorMsg);
}

public ExcelCells getCells(int rowIdx, int colIdx, int rowCount, int colCount) {
public ExcelCells getCells(int rowIdx, int colIdx, int rowCount, int colCount) {
if (initialize()) {
try {
return (ExcelCells) _document.getCells(_currentWorksheet, rowIdx, colIdx, rowCount, colCount);
} catch (ExcelException e) {
this.setError(e);
}
}
return null;
}

public ExcelCellsGXWrapper getCellsv2(int rowIdx, int colIdx, int rowCount, int colCount) {
if (initialize()) {
try {
return (ExcelCells) _document.getCells(_currentWorksheet, rowIdx, colIdx, rowCount, colCount);
return new ExcelCellsGXWrapper(_document.getCells(_currentWorksheet, rowIdx, colIdx, rowCount, colCount));
} catch (ExcelException e) {
this.setError(e);
}
Expand All @@ -157,7 +173,7 @@ public Boolean setCurrentWorksheet(int sheetIdx) {

public Boolean setCurrentWorksheetByName(String sheetName) {
if (initialize()) {
ExcelWorksheet ws = _document.getWorkSheet(sheetName);
IExcelWorksheet ws = _document.getWorkSheet(sheetName);
if (ws != null) {
_currentWorksheet = ws;
_document.setActiveWorkSheet(sheetName);
Expand All @@ -174,15 +190,6 @@ public Boolean insertRow(int rowIdx, int rowCount) {
return false;
}

public Boolean insertColumn(int colIdx, int colCount) {
//throw new Exception("NotImplemented");
return false;
/*
* if (isOK()) { //return _document.(_currentWorksheet, colIdx, colCount); }
* return false;
*/
}

public Boolean deleteRow(int rowIdx) {
if (initialize()) {
return _document.deleteRow(_currentWorksheet, rowIdx - 1);
Expand Down Expand Up @@ -234,7 +241,7 @@ public Boolean toggleRow(int rowIdx, Boolean visible) {

public Boolean deleteSheet(String sheetName) {
if (initialize()) {
ExcelWorksheet ws = _document.getWorkSheet(sheetName);
IExcelWorksheet ws = _document.getWorkSheet(sheetName);
if (ws != null)
return _document.deleteSheet(sheetName);
}
Expand Down Expand Up @@ -279,18 +286,25 @@ public String getErrDescription() {
return _errDescription;
}

public ExcelWorksheet getCurrentWorksheet() {
public ExcelWorksheet getCurrentWorksheet() {
if (initialize()) {
return (ExcelWorksheet) _currentWorksheet;
}
return null;
}

public ExcelWorksheetGXWrapper getCurrentWorksheetv2() {
if (initialize()) {
return (ExcelWorksheet) _currentWorksheet;
return new ExcelWorksheetGXWrapper(_currentWorksheet);
}
return null;
}

public List<ExcelWorksheet> getWorksheets() {
public List<IExcelWorksheet> getWorksheets() {
if (initialize())
return _document.getWorksheets();
else
return new ArrayList<ExcelWorksheet>();
return new ArrayList<IExcelWorksheet>();
}

private boolean selectFirstDefaultSheet(String sheetName) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.genexus.msoffice.excel;

import com.genexus.msoffice.excel.exception.ExcelException;

public class ExcelWorksheetGXWrapper implements IExcelWorksheet {
private IExcelWorksheet _workSheet;

public ExcelWorksheetGXWrapper() {
}

public ExcelWorksheetGXWrapper(IExcelWorksheet sheet) {
_workSheet = sheet;
}

public String getName() {
return _workSheet.getName();
}

public Boolean setHidden(boolean hidden) {
return _workSheet.setHidden(hidden);
}

public Boolean isHidden() {
return _workSheet.isHidden();
}

public Boolean rename(String newName) {
return _workSheet.rename(newName);
}

public Boolean copy(String newName) {
try {
return _workSheet.copy(newName);
}
catch (ExcelException e) {
return false;
}
}

public void setProtected(String password) {
_workSheet.setProtected(password);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ public interface IExcelCellRange

int getColumnEnd();

String getCellAdress();

String getValueType();

/*
Expand All @@ -44,8 +42,4 @@ public interface IExcelCellRange
Boolean mergeCells();

Boolean setCellStyle(ExcelStyle style);

ExcelStyle getCellStyle();


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

import com.genexus.msoffice.excel.exception.ExcelException;
import com.genexus.msoffice.excel.poi.xssf.ExcelWorksheet;

public interface IExcelSpreadsheet
{
Expand All @@ -29,8 +28,8 @@ public interface IExcelSpreadsheet
Boolean deleteColumn(IExcelWorksheet worksheet, int colIdx);

// Worksheets
List<ExcelWorksheet> getWorksheets();
ExcelWorksheet getWorkSheet(String name);
List<IExcelWorksheet> getWorksheets();
IExcelWorksheet getWorkSheet(String name);

Boolean insertWorksheet(String newSheetName, int idx) throws ExcelException;
Boolean getAutofit();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ public interface IExcelWorksheet

public Boolean isHidden();

public Boolean setHidden(boolean hidden);

public Boolean rename(String newName);

public Boolean copy(String newName) throws ExcelException;
Expand Down
Loading
Loading