dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #03984
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 1322: Added new method in ExcelUtils - Excel Reporting module:
------------------------------------------------------------
revno: 1322
committer: hieu <hieu.hispvietnam@xxxxxxxxx>
branch nick: trunk
timestamp: Thu 2010-01-21 11:47:18 +0700
message:
Added new method in ExcelUtils - Excel Reporting module:
+ Get only string or numberic value for previewing and importing data into DHIS
modified:
dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/importing/action/ImportDataCategoryExcelGroupAction.java
dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/importing/action/ImportDataExcelOrganizationGroupAction.java
dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/importing/action/ImportDataNormalExcelGroupAction.java
dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/importing/action/ViewDataCategoryAction.java
dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/importing/action/ViewDataNormalAction.java
dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/importing/action/ViewDataOrganizationGroupAction.java
dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/utils/ExcelUtils.java
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription.
=== modified file 'dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/importing/action/ImportDataCategoryExcelGroupAction.java'
--- dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/importing/action/ImportDataCategoryExcelGroupAction.java 2009-11-18 04:14:34 +0000
+++ dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/importing/action/ImportDataCategoryExcelGroupAction.java 2010-01-21 04:47:18 +0000
@@ -148,7 +148,6 @@
public String execute()
throws Exception
{
-
OrganisationUnit organisationUnit = organisationUnitSelectionManager.getSelectedOrganisationUnit();
if ( excelItemIds == null )
@@ -160,19 +159,14 @@
if ( organisationUnit != null )
{
-
FileInputStream upload = new FileInputStream( selectionManager.getUploadFilePath() );
- // WorkbookSettings ws = new WorkbookSettings();
- //ws.setLocale( new Locale( "en", "EN" ) );
- // Workbook templateWorkbook = Workbook.getWorkbook( upload, ws );
-
- HSSFWorkbook wb = new HSSFWorkbook( upload );
+
+ HSSFWorkbook wb = new HSSFWorkbook( upload );
Period period = periodGenericManager.getSelectedPeriod();
for ( int i = 0; i < excelItemIds.length; i++ )
{
-
int excelItemId = Integer.parseInt( excelItemIds[i].split( "-" )[0] );
int rowIndex = Integer.parseInt( excelItemIds[i].split( "-" )[1] );
@@ -183,10 +177,9 @@
HSSFSheet sheet = wb.getSheetAt( excelItem.getSheetNo() - 1 );
- String value = ExcelUtils.readValuePOI( rowIndex, excelItem.getColumn(), sheet );
+ String value = ExcelUtils.readValueImportingByPOI( rowIndex, excelItem.getColumn(), sheet );
addDataValue( expression, value, organisationUnit, period );
-
}
}// end if (organisationUnit ...
@@ -198,7 +191,6 @@
private void addDataValue( String expression, String value, OrganisationUnit organisationUnit, Period period )
{
-
Operand operand = expressionService.getOperandsInExpression( expression ).iterator().next();
DataElement dataElement = dataElementService.getDataElement( operand.getDataElementId() );
@@ -215,7 +207,6 @@
dataValue = new DataValue( dataElement, period, organisationUnit, value + "", storedBy, new Date(), null,
optionCombo );
dataValueService.addDataValue( dataValue );
-
}
else
{
@@ -224,8 +215,6 @@
dataValue.setStoredBy( storedBy );
dataValueService.updateDataValue( dataValue );
-
}
}
-
}
\ No newline at end of file
=== modified file 'dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/importing/action/ImportDataExcelOrganizationGroupAction.java'
--- dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/importing/action/ImportDataExcelOrganizationGroupAction.java 2009-11-21 16:22:30 +0000
+++ dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/importing/action/ImportDataExcelOrganizationGroupAction.java 2010-01-21 04:47:18 +0000
@@ -157,7 +157,6 @@
public String execute()
throws Exception
{
-
OrganisationUnit organisationUnit = organisationUnitSelectionManager.getSelectedOrganisationUnit();
if ( excelItemIds == null )
@@ -169,16 +168,14 @@
if ( organisationUnit != null )
{
-
FileInputStream inputStream = new FileInputStream( selectionManager.getUploadFilePath() );
-
- HSSFWorkbook wb = new HSSFWorkbook( inputStream );
+
+ HSSFWorkbook wb = new HSSFWorkbook( inputStream );
Period period = periodGenericManager.getSelectedPeriod();
for ( int i = 0; i < excelItemIds.length; i++ )
{
-
int orgunitId = Integer.parseInt( excelItemIds[i].split( "-" )[0] );
OrganisationUnit o = organisationUnitService.getOrganisationUnit( orgunitId );
@@ -205,17 +202,14 @@
return SUCCESS;
}
- private void writeDataValue( ExcelItem exelItem, HSSFWorkbook wb, int row, OrganisationUnit o,
- Period period )
+ private void writeDataValue( ExcelItem exelItem, HSSFWorkbook wb, int row, OrganisationUnit o, Period period )
{
-
HSSFSheet sheet = wb.getSheetAt( exelItem.getSheetNo() - 1 );
- String value = ExcelUtils.readValuePOI( exelItem.getRow() + row, exelItem.getColumn(), sheet );
+ String value = ExcelUtils.readValueImportingByPOI( exelItem.getRow() + row, exelItem.getColumn(), sheet );
if ( value.length() > 0 )
{
-
Operand operand = expressionService.getOperandsInExpression( exelItem.getExpression() ).iterator().next();
DataElement dataElement = dataElementService.getDataElement( operand.getDataElementId() );
@@ -239,7 +233,6 @@
dataValue.setStoredBy( storedBy );
dataValueService.updateDataValue( dataValue );
-
}
}
}
=== modified file 'dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/importing/action/ImportDataNormalExcelGroupAction.java'
--- dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/importing/action/ImportDataNormalExcelGroupAction.java 2009-11-21 16:22:30 +0000
+++ dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/importing/action/ImportDataNormalExcelGroupAction.java 2010-01-21 04:47:18 +0000
@@ -159,7 +159,6 @@
public String execute()
throws Exception
{
-
ExcelItemGroup excelItemGroup = excelItemService.getExcelItemGroup( excelItemGroupId.intValue() );
OrganisationUnit organisationUnit = organisationUnitSelectionManager.getSelectedOrganisationUnit();
@@ -173,10 +172,9 @@
if ( organisationUnit != null )
{
-
FileInputStream upload = new FileInputStream( selectionManager.getUploadFilePath() );
-
- HSSFWorkbook wb = new HSSFWorkbook( upload );
+
+ HSSFWorkbook wb = new HSSFWorkbook( upload );
Collection<ExcelItem> excelItems = new ArrayList<ExcelItem>();
if ( excelItemIds != null )
@@ -195,15 +193,12 @@
for ( ExcelItem excelItem : excelItems )
{
-
-
HSSFSheet sheet = wb.getSheetAt( excelItem.getSheetNo() - 1 );
- String value = ExcelUtils.readValuePOI( excelItem.getRow(), excelItem.getColumn(), sheet );
+ String value = ExcelUtils.readValueImportingByPOI( excelItem.getRow(), excelItem.getColumn(), sheet );
if ( value.length() > 0 )
{
-
Operand operand = expressionService.getOperandsInExpression( excelItem.getExpression() ).iterator()
.next();
=== modified file 'dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/importing/action/ViewDataCategoryAction.java'
--- dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/importing/action/ViewDataCategoryAction.java 2009-11-21 16:22:30 +0000
+++ dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/importing/action/ViewDataCategoryAction.java 2010-01-21 04:47:18 +0000
@@ -97,7 +97,6 @@
{
try
{
-
FileInputStream inputStream = new FileInputStream( upload );
HSSFWorkbook wb = new HSSFWorkbook( inputStream );
@@ -121,7 +120,7 @@
for ( DataElement dataElement : dataElementGroup.getDataElements() )
{
- String value = ExcelUtils.readValuePOI( rowBegin, excelItem.getColumn(), sheet );
+ String value = ExcelUtils.readValueImportingByPOI( rowBegin, excelItem.getColumn(), sheet );
ExcelItem item = new ExcelItem();
=== modified file 'dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/importing/action/ViewDataNormalAction.java'
--- dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/importing/action/ViewDataNormalAction.java 2009-11-18 04:14:34 +0000
+++ dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/importing/action/ViewDataNormalAction.java 2010-01-21 04:47:18 +0000
@@ -86,19 +86,17 @@
{
try
{
-
FileInputStream inputStream = new FileInputStream( upload );
-
- HSSFWorkbook wb = new HSSFWorkbook( inputStream );
+
+ HSSFWorkbook wb = new HSSFWorkbook( inputStream );
excelItemValues = new ArrayList<ExcelItemValue>();
for ( ExcelItem excelItem : excelItems )
{
-
HSSFSheet sheet = wb.getSheetAt( excelItem.getSheetNo() - 1 );
- String value = ExcelUtils.readValuePOI( excelItem.getRow(), excelItem.getColumn(), sheet );
+ String value = ExcelUtils.readValueImportingByPOI( excelItem.getRow(), excelItem.getColumn(), sheet );
ExcelItemValue excelItemvalue = new ExcelItemValue( excelItem, value );
=== modified file 'dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/importing/action/ViewDataOrganizationGroupAction.java'
--- dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/importing/action/ViewDataOrganizationGroupAction.java 2009-11-25 03:18:57 +0000
+++ dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/importing/action/ViewDataOrganizationGroupAction.java 2010-01-21 04:47:18 +0000
@@ -112,23 +112,20 @@
{
try
{
-
OrganisationUnit organisationUnit = organisationUnitSelectionManager.getSelectedOrganisationUnit();
FileInputStream inputStream = new FileInputStream( upload );
-
- HSSFWorkbook wb = new HSSFWorkbook( inputStream );
+
+ HSSFWorkbook wb = new HSSFWorkbook( inputStream );
excelItemValueByOrgUnits = new ArrayList<ExcelItemValueByOrganisationUnit>();
if ( organisationUnit != null )
{
-
for ( OrganisationUnitGroup organisationUnitGroup : excelItemGroup.getOrganisationUnitGroups() )
{
-
- List<OrganisationUnit> organisationUnits = new ArrayList<OrganisationUnit>( getOrganisationUnits( organisationUnitGroup,
- organisationUnit ));
+ List<OrganisationUnit> organisationUnits = new ArrayList<OrganisationUnit>( getOrganisationUnits(
+ organisationUnitGroup, organisationUnit ) );
Collections.sort( organisationUnits, new OrganisationUnitNameComparator() );
@@ -136,18 +133,16 @@
for ( OrganisationUnit o : organisationUnits )
{
-
ExcelItemValueByOrganisationUnit excelItemValueByOrgUnit = new ExcelItemValueByOrganisationUnit(
o );
ArrayList<ExcelItemValue> excelItemValues = new ArrayList<ExcelItemValue>();
for ( ExcelItem excelItem : excelItems )
{
-
HSSFSheet sheet = wb.getSheetAt( excelItem.getSheetNo() - 1 );
- String value = ExcelUtils
- .readValuePOI( excelItem.getRow() + row, excelItem.getColumn(), sheet );
+ String value = ExcelUtils.readValueImportingByPOI( excelItem.getRow() + row, excelItem
+ .getColumn(), sheet );
ExcelItemValue excelItemvalue = new ExcelItemValue( excelItem, value );
=== modified file 'dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/utils/ExcelUtils.java'
--- dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/utils/ExcelUtils.java 2010-01-21 03:59:55 +0000
+++ dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/utils/ExcelUtils.java 2010-01-21 04:47:18 +0000
@@ -136,7 +136,7 @@
}
/* POI - Read the value of specified cell */
- public static String readValuePOI( int row, int column, org.apache.poi.ss.usermodel.Sheet sheetPOI )
+ public static String readValueByPOI( int row, int column, org.apache.poi.ss.usermodel.Sheet sheetPOI )
{
org.apache.poi.ss.usermodel.Cell cellPOI = getCellByPOI( row, column, sheetPOI );
@@ -176,6 +176,31 @@
}
+ public static String readValueImportingByPOI( int row, int column, org.apache.poi.ss.usermodel.Sheet sheetPOI )
+ {
+ org.apache.poi.ss.usermodel.Cell cellPOI = getCellByPOI( row, column, sheetPOI );
+
+ String value = "";
+
+ if ( cellPOI != null )
+ {
+ switch ( cellPOI.getCellType() )
+ {
+ case org.apache.poi.ss.usermodel.Cell.CELL_TYPE_STRING:
+ case org.apache.poi.ss.usermodel.Cell.CELL_TYPE_BLANK:
+ value = cellPOI.getRichStringCellValue().toString();
+ break;
+
+ case org.apache.poi.ss.usermodel.Cell.CELL_TYPE_NUMERIC:
+ value = String.valueOf( cellPOI.getNumericCellValue() );
+ break;
+ }
+ }
+
+ return value;
+
+ }
+
/**
* USING FOR XLS-XLSX EXTENSION
*/