dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #20440
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 9327: local vn - Auto generate form now fixed:
------------------------------------------------------------
revno: 9327
committer: Hieu <hieu.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Sat 2012-12-15 16:52:30 +0700
message:
local vn - Auto generate form now fixed:
- The design form is editable
- Colors which apply from the template file.
- Allow jump next/previous by Tab / Enter / Up (Down) button.
added:
local/vn/dhis-web-spreadsheet-reporting/src/main/java/org/hisp/dhis/reportsheet/preview/action/AbstractXMLStructure.java
local/vn/dhis-web-spreadsheet-reporting/src/main/java/org/hisp/dhis/reportsheet/preview/action/HSSFHtmlHelper.java
local/vn/dhis-web-spreadsheet-reporting/src/main/java/org/hisp/dhis/reportsheet/preview/action/HtmlHelper.java
local/vn/dhis-web-spreadsheet-reporting/src/main/java/org/hisp/dhis/reportsheet/preview/action/XSSFHtmlHelper.java
modified:
local/vn/dhis-web-spreadsheet-reporting/src/main/java/org/hisp/dhis/reportsheet/importing/action/ViewDataCategoryAction.java
local/vn/dhis-web-spreadsheet-reporting/src/main/java/org/hisp/dhis/reportsheet/importing/action/ViewDataNormalAction.java
local/vn/dhis-web-spreadsheet-reporting/src/main/java/org/hisp/dhis/reportsheet/importing/action/ViewDataOrganizationGroupAction.java
local/vn/dhis-web-spreadsheet-reporting/src/main/java/org/hisp/dhis/reportsheet/preview/action/AutoGenerateFormByTemplate.java
local/vn/dhis-web-spreadsheet-reporting/src/main/java/org/hisp/dhis/reportsheet/preview/action/ExportXMLAction.java
local/vn/dhis-web-spreadsheet-reporting/src/main/java/org/hisp/dhis/reportsheet/preview/action/XMLStructureResponse.java
local/vn/dhis-web-spreadsheet-reporting/src/main/java/org/hisp/dhis/reportsheet/preview/action/XMLStructureResponseImport.java
local/vn/dhis-web-spreadsheet-reporting/src/main/webapp/dhis-web-spreadsheet-reporting/javascript/autoGenerateForm.js
--
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 'local/vn/dhis-web-spreadsheet-reporting/src/main/java/org/hisp/dhis/reportsheet/importing/action/ViewDataCategoryAction.java'
--- local/vn/dhis-web-spreadsheet-reporting/src/main/java/org/hisp/dhis/reportsheet/importing/action/ViewDataCategoryAction.java 2011-10-25 08:52:49 +0000
+++ local/vn/dhis-web-spreadsheet-reporting/src/main/java/org/hisp/dhis/reportsheet/importing/action/ViewDataCategoryAction.java 2012-12-15 09:52:30 +0000
@@ -28,6 +28,7 @@
*/
import java.util.ArrayList;
+import java.util.HashSet;
import java.util.List;
import org.hisp.dhis.dataelement.DataElement;
@@ -59,7 +60,7 @@
setUpImportItems( importReport, importItems, categoryImportItems );
xmlStructureResponse = new XMLStructureResponseImport( selectionManager.getUploadFilePath(),
- importReportService.getAllSheet(), categoryImportItems, true ).getXml();
+ new HashSet<Integer>( importReportService.getAllSheet() ), categoryImportItems ).getXml();
}
catch ( Exception ex )
{
@@ -80,17 +81,17 @@
for ( DataElementGroupOrder dataElementGroup : importReport.getDataElementOrders() )
{
- rowBegin ++;
-
+ rowBegin++;
+
for ( DataElement dataElement : dataElementGroup.getDataElements() )
{
ImportItem item = new ImportItem();
-
+
item.setSheetNo( importItem.getSheetNo() );
- item.setRow( rowBegin ++ );
+ item.setRow( rowBegin++ );
item.setColumn( importItem.getColumn() );
item.setExpression( importItem.getExpression().replace( "*", dataElement.getId() + "" ) );
-
+
importItemsDest.add( item );
}
}
=== modified file 'local/vn/dhis-web-spreadsheet-reporting/src/main/java/org/hisp/dhis/reportsheet/importing/action/ViewDataNormalAction.java'
--- local/vn/dhis-web-spreadsheet-reporting/src/main/java/org/hisp/dhis/reportsheet/importing/action/ViewDataNormalAction.java 2011-10-24 05:42:25 +0000
+++ local/vn/dhis-web-spreadsheet-reporting/src/main/java/org/hisp/dhis/reportsheet/importing/action/ViewDataNormalAction.java 2012-12-15 09:52:30 +0000
@@ -27,6 +27,7 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import java.util.HashSet;
import java.util.List;
import org.hisp.dhis.reportsheet.importitem.ImportItem;
@@ -52,7 +53,7 @@
try
{
xmlStructureResponse = new XMLStructureResponseImport( selectionManager.getUploadFilePath(),
- importReportService.getAllSheet(), importItems, true ).getXml();
+ new HashSet<Integer>( importReportService.getAllSheet() ), importItems ).getXml();
}
catch ( Exception ex )
{
=== modified file 'local/vn/dhis-web-spreadsheet-reporting/src/main/java/org/hisp/dhis/reportsheet/importing/action/ViewDataOrganizationGroupAction.java'
--- local/vn/dhis-web-spreadsheet-reporting/src/main/java/org/hisp/dhis/reportsheet/importing/action/ViewDataOrganizationGroupAction.java 2012-11-27 04:26:35 +0000
+++ local/vn/dhis-web-spreadsheet-reporting/src/main/java/org/hisp/dhis/reportsheet/importing/action/ViewDataOrganizationGroupAction.java 2012-12-15 09:52:30 +0000
@@ -30,6 +30,7 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
+import java.util.HashSet;
import java.util.List;
import org.hisp.dhis.common.comparator.IdentifiableObjectNameComparator;
@@ -75,7 +76,7 @@
try
{
xmlStructureResponse = new XMLStructureResponseImport( selectionManager.getUploadFilePath(),
- importReportService.getAllSheet(), orgUnitListingImportItems, true ).getXml();
+ new HashSet<Integer>( importReportService.getAllSheet() ), orgUnitListingImportItems ).getXml();
}
catch ( Exception e )
{
=== added file 'local/vn/dhis-web-spreadsheet-reporting/src/main/java/org/hisp/dhis/reportsheet/preview/action/AbstractXMLStructure.java'
--- local/vn/dhis-web-spreadsheet-reporting/src/main/java/org/hisp/dhis/reportsheet/preview/action/AbstractXMLStructure.java 1970-01-01 00:00:00 +0000
+++ local/vn/dhis-web-spreadsheet-reporting/src/main/java/org/hisp/dhis/reportsheet/preview/action/AbstractXMLStructure.java 2012-12-15 09:52:30 +0000
@@ -0,0 +1,229 @@
+package org.hisp.dhis.reportsheet.preview.action;
+
+/*
+ * Copyright (c) 2004-2012, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import static org.apache.commons.io.FilenameUtils.getExtension;
+import static org.hisp.dhis.reportsheet.preview.action.HtmlHelper.FOREGROUND_COLOR;
+import static org.hisp.dhis.reportsheet.preview.action.HtmlHelper.TEXT_COLOR;
+import static org.hisp.dhis.reportsheet.utils.ExcelUtils.convertAlignmentString;
+
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.Collection;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.CellStyle;
+import org.apache.poi.ss.usermodel.Font;
+import org.apache.poi.ss.usermodel.FormulaEvaluator;
+import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.ss.usermodel.Workbook;
+import org.apache.poi.ss.util.CellRangeAddress;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
+import org.hisp.dhis.reportsheet.importitem.ImportItem;
+
+/**
+ * Simple demo class which uses the api to present the contents of an excel 97
+ * spreadsheet as an XML document, using a workbook and output stream of your
+ * choice
+ *
+ * @author Dang Duy Hieu
+ * @version $Id$
+ */
+
+public abstract class AbstractXMLStructure
+{
+ private static final String WORKBOOK_OPENTAG = "<workbook>";
+
+ private static final String WORKBOOK_CLOSETAG = "</workbook>";
+
+ private static final String MERGEDCELL_OPENTAG = "<MergedCells>";
+
+ private static final String MERGEDCELL_CLOSETAG = "</MergedCells>";
+
+ /**
+ * The workbook we are reading from a given file
+ */
+ protected Workbook WORKBOOK;
+
+ protected FormulaEvaluator evaluatorFormula;
+
+ protected HtmlHelper htmlHelper;
+
+ /**
+ * The encoding to write
+ */
+ protected StringBuffer xml = new StringBuffer();
+
+ /**
+ * Constructor
+ *
+ * @param w The workbook to interrogate
+ * @param enc The encoding used by the output stream. Null or unrecognized
+ * values cause the encoding to default to UTF8
+ * @param f Indicates whether the generated XML document should contain the
+ * cell format information
+ * @exception java.io.IOException
+ */
+
+ protected AbstractXMLStructure( String pathFileName, Set<Integer> collectSheets, List<ImportItem> importItems )
+ throws Exception
+ {
+ cleanUp();
+
+ if ( getExtension( pathFileName ).equals( "xls" ) )
+ {
+ WORKBOOK = new HSSFWorkbook( new FileInputStream( pathFileName ) );
+ htmlHelper = new HSSFHtmlHelper( (HSSFWorkbook) WORKBOOK );
+ }
+ else
+ {
+ WORKBOOK = new XSSFWorkbook( new FileInputStream( pathFileName ) );
+ htmlHelper = new XSSFHtmlHelper();
+ }
+
+ evaluatorFormula = WORKBOOK.getCreationHelper().createFormulaEvaluator();
+
+ setUpDecimalFormat();
+
+ printXML( collectSheets, importItems );
+ }
+
+ /**
+ * Writes out the WORKBOOK data as XML, with formatting information
+ *
+ * @param bDetailed
+ *
+ * @throws Exception
+ */
+
+ protected void printXML( Collection<Integer> collectSheets, List<ImportItem> importItems )
+ throws Exception
+ {
+ printMergedInfo( collectSheets );
+
+ xml.append( WORKBOOK_OPENTAG );
+
+ for ( Integer sheet : collectSheets )
+ {
+ printData( sheet, importItems );
+ }
+
+ xml.append( WORKBOOK_CLOSETAG );
+ }
+
+ protected void printFormatInfo( Sheet sheet, Cell objCell )
+ {
+ // The format information
+ CellStyle format = objCell.getCellStyle();
+
+ if ( format != null )
+ {
+ xml.append( "<format a='" + convertAlignmentString( format.getAlignment() ) + "'" );
+ xml.append( " w='" + sheet.getColumnWidth( objCell.getColumnIndex() ) + "'" );
+ xml.append( " b='"
+ + (format.getBorderBottom() + format.getBorderLeft() + format.getBorderRight() + format.getBorderTop())
+ + "'" );
+
+ Font font = WORKBOOK.getFontAt( format.getFontIndex() );
+
+ if ( font != null )
+ {
+ xml.append( "><font s='" + font.getFontHeightInPoints() + "'" );
+ xml.append( " b='" + (font.getBoldweight() == Font.BOLDWEIGHT_BOLD ? "1" : "0") + "'" );
+ xml.append( " i='" + font.getItalic() + "'" );
+ xml.append( " c='" + htmlHelper.colorStyle( TEXT_COLOR, format ) + "'/>" );
+
+ // The cell background information
+ xml.append( "<bg c='" + htmlHelper.colorStyle( FOREGROUND_COLOR, format ) + "'/>" );
+ xml.append( "</format>" );
+ }
+ else
+ {
+ xml.append( "/>" );
+ }
+ }
+ }
+
+ public String getXml()
+ {
+ return xml.toString();
+ }
+
+ // -------------------------------------------------------------------------
+ // Abstract methods
+ // -------------------------------------------------------------------------
+
+ protected abstract void setUpDecimalFormat();
+
+ protected abstract void printData( int sheetNo, List<ImportItem> importItems );
+
+ // -------------------------------------------------------------------------
+ // Get the merged cell's information
+ // -------------------------------------------------------------------------
+
+ protected void cleanUp()
+ {
+ System.gc();
+ }
+
+ private void printMergedInfo( Collection<Integer> collectSheets )
+ throws IOException
+ {
+ // Open the main Tag //
+ xml.append( MERGEDCELL_OPENTAG );
+
+ for ( Integer sheet : collectSheets )
+ {
+ printMergedInfoBySheetNo( sheet );
+ }
+
+ // Close the main Tag //
+ xml.append( MERGEDCELL_CLOSETAG );
+ }
+
+ private void printMergedInfoBySheetNo( int sheetNo )
+ {
+ Sheet sheet = WORKBOOK.getSheetAt( sheetNo - 1 );
+ CellRangeAddress cellRangeAddress = null;
+
+ for ( int i = 0; i < sheet.getNumMergedRegions(); i++ )
+ {
+ cellRangeAddress = sheet.getMergedRegion( i );
+
+ if ( cellRangeAddress.getFirstColumn() != cellRangeAddress.getLastColumn() )
+ {
+ xml.append( "<cell " + "iKey='" + (sheetNo) + "#" + cellRangeAddress.getFirstRow() + "#"
+ + cellRangeAddress.getFirstColumn() + "'>"
+ + (cellRangeAddress.getLastColumn() - cellRangeAddress.getFirstColumn() + 1) + "</cell>" );
+ }
+ }
+ }
+}
\ No newline at end of file
=== modified file 'local/vn/dhis-web-spreadsheet-reporting/src/main/java/org/hisp/dhis/reportsheet/preview/action/AutoGenerateFormByTemplate.java'
--- local/vn/dhis-web-spreadsheet-reporting/src/main/java/org/hisp/dhis/reportsheet/preview/action/AutoGenerateFormByTemplate.java 2012-12-12 09:34:51 +0000
+++ local/vn/dhis-web-spreadsheet-reporting/src/main/java/org/hisp/dhis/reportsheet/preview/action/AutoGenerateFormByTemplate.java 2012-12-15 09:52:30 +0000
@@ -35,15 +35,17 @@
import static org.hisp.dhis.dataelement.DataElement.VALUE_TYPE_INT;
import static org.hisp.dhis.reportsheet.ExportItem.PERIODTYPE.SELECTED_MONTH;
import static org.hisp.dhis.reportsheet.ExportItem.TYPE.DATAELEMENT;
+import static org.hisp.dhis.reportsheet.preview.action.HtmlHelper.FOREGROUND_COLOR;
+import static org.hisp.dhis.reportsheet.preview.action.HtmlHelper.TEXT_COLOR;
import static org.hisp.dhis.reportsheet.utils.ExcelUtils.convertAlignmentString;
import static org.hisp.dhis.reportsheet.utils.ExcelUtils.readValueByPOI;
import java.io.FileInputStream;
import java.io.IOException;
-import java.io.InputStream;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
+import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -53,7 +55,6 @@
import org.apache.poi.ss.usermodel.Comment;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.FormulaEvaluator;
-import org.apache.poi.ss.usermodel.IndexedColors;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
@@ -73,6 +74,7 @@
import org.hisp.dhis.reportsheet.ExportReport;
import org.hisp.dhis.reportsheet.ExportReportNormal;
import org.hisp.dhis.reportsheet.ExportReportService;
+import org.hisp.dhis.reportsheet.importitem.ImportItem;
import org.hisp.dhis.reportsheet.state.SelectionManager;
import org.springframework.beans.factory.annotation.Autowired;
@@ -93,6 +95,12 @@
{
private static final String REPORT_EXCEL_GROUP = "BAO CAO THONG KE";
+ private static DataElementCategoryOptionCombo optionCombo = null;
+
+ private String excelFileName = "";
+
+ private String commonName = "";
+
private static final String WORKBOOK_OPENTAG = "<workbook>";
private static final String WORKBOOK_CLOSETAG = "</workbook>";
@@ -101,21 +109,19 @@
private static final String MERGEDCELL_CLOSETAG = "</MergedCells>";
- private String excelFileName = "";
-
- private String commonName = "";
-
/**
* The workbook we are reading from a given file
*/
- private Workbook WORKBOOK;
-
- private FormulaEvaluator evaluatorFormula;
+ protected Workbook WORKBOOK;
+
+ protected FormulaEvaluator evaluatorFormula;
+
+ protected HtmlHelper htmlHelper;
/**
* The encoding to write
*/
- private StringBuffer xml = new StringBuffer( 200000 );
+ protected StringBuffer xml = new StringBuffer();
// -------------------------------------------------------------------------
// Dependencies
@@ -156,31 +162,33 @@
public String execute()
{
+ cleanUp();
+
Set<Integer> collectSheets = new HashSet<Integer>();
collectSheets.add( 1 );
try
{
- this.cleanUp();
-
String pathFileName = selectionManager.getUploadFilePath();
- InputStream inputSteam = new FileInputStream( pathFileName );
excelFileName = getName( pathFileName );
commonName = getBaseName( pathFileName );
if ( getExtension( pathFileName ).equals( "xls" ) )
{
- this.WORKBOOK = new HSSFWorkbook( inputSteam );
+ WORKBOOK = new HSSFWorkbook( new FileInputStream( pathFileName ) );
+ htmlHelper = new HSSFHtmlHelper( (HSSFWorkbook) WORKBOOK );
}
else
{
- this.WORKBOOK = new XSSFWorkbook( inputSteam );
+ WORKBOOK = new XSSFWorkbook( new FileInputStream( pathFileName ) );
+ htmlHelper = new XSSFHtmlHelper();
}
- this.evaluatorFormula = WORKBOOK.getCreationHelper().createFormulaEvaluator();
+ optionCombo = categoryService.getDefaultDataElementCategoryOptionCombo();
+ evaluatorFormula = WORKBOOK.getCreationHelper().createFormulaEvaluator();
- writeFormattedXML( collectSheets );
+ printXML( collectSheets, null );
xmlStructureResponse = xml.toString();
@@ -188,42 +196,30 @@
}
catch ( Exception e )
{
- System.out.println( e.getMessage() );
+ e.printStackTrace();
+
+ cleanUp();
}
return SUCCESS;
}
- // -------------------------------------------------------------------------
- // Sub-methods
- // -------------------------------------------------------------------------
-
- private void cleanUp()
- {
- System.gc();
- }
-
- /**
- * Writes out the WORKBOOK data as XML, with formatting information
- *
- * @param bDetailed
- *
- * @throws Exception
- */
-
- private void writeFormattedXML( Collection<Integer> collectSheets )
+ private void printXML( Collection<Integer> collectSheets, List<ImportItem> importItems )
throws Exception
{
- this.writeXMLMergedDescription( collectSheets );
+ printMergedInfo( collectSheets );
xml.append( WORKBOOK_OPENTAG );
- createFormByComment( 1, categoryService.getDefaultDataElementCategoryOptionCombo() );
+ for ( Integer sheet : collectSheets )
+ {
+ printData( sheet, importItems );
+ }
xml.append( WORKBOOK_CLOSETAG );
}
- private void createFormByComment( int sheetNo, DataElementCategoryOptionCombo optionCombo )
+ private void printData( int sheetNo, List<ImportItem> importItems )
{
PeriodType periodType = PeriodType.getPeriodTypeByName( MonthlyPeriodType.NAME );
@@ -268,7 +264,7 @@
// Generate DataElement
DataElement dataElement = new DataElement( name );
/** TAKE CARE OF SHORT_NAME IS TOO LONG */
- dataElement.setShortName( System.currentTimeMillis() + "" );
+ dataElement.setShortName( name );
dataElement.setActive( true );
dataElement.setZeroIsSignificant( false );
dataElement.setDomainType( DOMAIN_TYPE_AGGREGATE );
@@ -303,8 +299,10 @@
{
xml.append( "<col no='" + colIndex + "'>" );
- xml.append( "<data><![CDATA[" + "<input name='entryfield' id='" + idxMap.get( colIndex ) + "-"
- + optionCombo.getId() + "-val']]></data>" );
+ xml.append( "<data><![CDATA[" + "<input id=\"" + idxMap.get( colIndex ) + "-"
+ + optionCombo.getId() + "-val\" style=\"width:7em;text-align:center\" value=\"\" title=\"\" />]]></data>" );
+
+ printFormatInfo( s, cell );
xml.append( "</col>" );
}
@@ -316,7 +314,7 @@
xml.append( "<data><![CDATA["
+ readValueByPOI( row.getRowNum() + 1, colIndex + 1, s, evaluatorFormula ) + "]]></data>" );
- this.readingDetailsFormattedCell( s, cell );
+ printFormatInfo( s, cell );
xml.append( "</col>" );
}
@@ -346,16 +344,22 @@
{
cleanUp();
- // Catch exception if any
e.printStackTrace();
}
}
- // -------------------------------------------------------------------------
- // Get the merged cell's information
- // -------------------------------------------------------------------------
-
- private void readingDetailsFormattedCell( Sheet sheet, Cell objCell )
+ /**
+ * Writes out the WORKBOOK data as XML, with formatting information
+ *
+ * @throws Exception
+ */
+
+ private void cleanUp()
+ {
+ System.gc();
+ }
+
+ private void printFormatInfo( Sheet sheet, Cell objCell )
{
// The format information
CellStyle format = objCell.getCellStyle();
@@ -363,6 +367,7 @@
if ( format != null )
{
xml.append( "<format a='" + convertAlignmentString( format.getAlignment() ) + "'" );
+ xml.append( " w='" + sheet.getColumnWidth( objCell.getColumnIndex() ) + "'" );
xml.append( " b='"
+ (format.getBorderBottom() + format.getBorderLeft() + format.getBorderRight() + format.getBorderTop())
+ "'" );
@@ -374,9 +379,10 @@
xml.append( "><font s='" + font.getFontHeightInPoints() + "'" );
xml.append( " b='" + (font.getBoldweight() == Font.BOLDWEIGHT_BOLD ? "1" : "0") + "'" );
xml.append( " i='" + font.getItalic() + "'" );
- xml.append( " c='" + getSimilarColor( font.getColor() ) + "'" );
- xml.append( "/>" );
+ xml.append( " c='" + htmlHelper.colorStyle( TEXT_COLOR, format ) + "'/>" );
+ // The cell background information
+ xml.append( "<bg c='" + htmlHelper.colorStyle( FOREGROUND_COLOR, format ) + "'/>" );
xml.append( "</format>" );
}
else
@@ -386,7 +392,11 @@
}
}
- private void writeXMLMergedDescription( Collection<Integer> collectSheets )
+ // -------------------------------------------------------------------------
+ // Get the merged cell's information
+ // -------------------------------------------------------------------------
+
+ private void printMergedInfo( Collection<Integer> collectSheets )
throws IOException
{
// Open the main Tag //
@@ -394,14 +404,14 @@
for ( Integer sheet : collectSheets )
{
- writeMergedInfoBySheetNo( sheet );
+ printMergedInfoBySheetNo( sheet );
}
// Close the main Tag //
xml.append( MERGEDCELL_CLOSETAG );
}
- private void writeMergedInfoBySheetNo( int sheetNo )
+ private void printMergedInfoBySheetNo( int sheetNo )
{
Sheet sheet = WORKBOOK.getSheetAt( sheetNo - 1 );
CellRangeAddress cellRangeAddress = null;
@@ -418,24 +428,4 @@
}
}
}
-
- private String getSimilarColor( short index )
- {
- if ( IndexedColors.BLUE.getIndex() == index )
- {
- return "blue";
- }
-
- if ( IndexedColors.DARK_BLUE.getIndex() == index )
- {
- return "darkblue";
- }
-
- if ( IndexedColors.BROWN.getIndex() == index )
- {
- return "brown";
- }
-
- return "";
- }
}
\ No newline at end of file
=== modified file 'local/vn/dhis-web-spreadsheet-reporting/src/main/java/org/hisp/dhis/reportsheet/preview/action/ExportXMLAction.java'
--- local/vn/dhis-web-spreadsheet-reporting/src/main/java/org/hisp/dhis/reportsheet/preview/action/ExportXMLAction.java 2012-11-02 04:42:01 +0000
+++ local/vn/dhis-web-spreadsheet-reporting/src/main/java/org/hisp/dhis/reportsheet/preview/action/ExportXMLAction.java 2012-12-15 09:52:30 +0000
@@ -69,15 +69,11 @@
// Input && Output
// -------------------------------------------------------------------------
- private String xmlStructureResponse;
-
- // -------------------------------------------------------------------------
- // Getter & Setter
- // -------------------------------------------
+ private String xml;
public String getXmlStructureResponse()
{
- return xmlStructureResponse;
+ return xml;
}
// -------------------------------------------------------------------------
@@ -104,7 +100,7 @@
}
}
- xmlStructureResponse = new XMLStructureResponse( selectionManager.getDownloadFilePath(), sheets ).getXml();
+ xml = new XMLStructureResponse( selectionManager.getDownloadFilePath(), sheets, null ).getXml();
return SUCCESS;
}
=== added file 'local/vn/dhis-web-spreadsheet-reporting/src/main/java/org/hisp/dhis/reportsheet/preview/action/HSSFHtmlHelper.java'
--- local/vn/dhis-web-spreadsheet-reporting/src/main/java/org/hisp/dhis/reportsheet/preview/action/HSSFHtmlHelper.java 1970-01-01 00:00:00 +0000
+++ local/vn/dhis-web-spreadsheet-reporting/src/main/java/org/hisp/dhis/reportsheet/preview/action/HSSFHtmlHelper.java 2012-12-15 09:52:30 +0000
@@ -0,0 +1,88 @@
+package org.hisp.dhis.reportsheet.preview.action;
+
+/*
+ * Copyright (c) 2004-2012, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import org.apache.poi.hssf.usermodel.HSSFCellStyle;
+import org.apache.poi.hssf.usermodel.HSSFPalette;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.hssf.util.HSSFColor;
+import org.apache.poi.ss.usermodel.CellStyle;
+
+/**
+ * @author Dang Duy Hieu
+ * @version $Id$
+ */
+
+public class HSSFHtmlHelper
+ implements HtmlHelper
+{
+ private final HSSFWorkbook wb;
+
+ private final HSSFPalette colors;
+
+ private static final HSSFColor HSSF_AUTO_COLOR = new HSSFColor.AUTOMATIC();
+
+ public HSSFHtmlHelper( HSSFWorkbook wb )
+ {
+ this.wb = wb;
+
+ colors = wb.getCustomPalette();
+ }
+
+ public String colorStyle( String type, CellStyle style )
+ {
+ if ( type == null || type.trim().isEmpty() )
+ {
+ return EMPTY;
+ }
+
+ HSSFCellStyle cellStyle = (HSSFCellStyle) style;
+
+ short index = 0;
+
+ if ( type.equals( FOREGROUND_COLOR ) )
+ {
+ index = cellStyle.getFillForegroundColor();
+ }
+ else
+ {
+ index = cellStyle.getFont( wb ).getColor();
+ }
+
+ HSSFColor color = colors.getColor( index );
+
+ if ( index == HSSF_AUTO_COLOR.getIndex() || color == null )
+ {
+ return EMPTY;
+ }
+
+ short[] rgb = color.getTriplet();
+
+ return "rgb(" + rgb[0] + "," + rgb[1] + "," + rgb[2] + ")";
+ }
+}
=== added file 'local/vn/dhis-web-spreadsheet-reporting/src/main/java/org/hisp/dhis/reportsheet/preview/action/HtmlHelper.java'
--- local/vn/dhis-web-spreadsheet-reporting/src/main/java/org/hisp/dhis/reportsheet/preview/action/HtmlHelper.java 1970-01-01 00:00:00 +0000
+++ local/vn/dhis-web-spreadsheet-reporting/src/main/java/org/hisp/dhis/reportsheet/preview/action/HtmlHelper.java 2012-12-15 09:52:30 +0000
@@ -0,0 +1,46 @@
+package org.hisp.dhis.reportsheet.preview.action;
+
+/*
+ * Copyright (c) 2004-2012, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import org.apache.poi.ss.usermodel.CellStyle;
+
+/**
+ * @author Dang Duy Hieu
+ * @version $Id$
+ * */
+
+public interface HtmlHelper
+{
+ final String EMPTY = "";
+
+ final String TEXT_COLOR = "tc";
+
+ final String FOREGROUND_COLOR = "fgc";
+
+ String colorStyle( String type, CellStyle style );
+}
=== modified file 'local/vn/dhis-web-spreadsheet-reporting/src/main/java/org/hisp/dhis/reportsheet/preview/action/XMLStructureResponse.java'
--- local/vn/dhis-web-spreadsheet-reporting/src/main/java/org/hisp/dhis/reportsheet/preview/action/XMLStructureResponse.java 2012-12-11 20:24:41 +0000
+++ local/vn/dhis-web-spreadsheet-reporting/src/main/java/org/hisp/dhis/reportsheet/preview/action/XMLStructureResponse.java 2012-12-15 09:52:30 +0000
@@ -27,30 +27,24 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-import static org.apache.commons.io.FilenameUtils.getExtension;
+import static org.hisp.dhis.reportsheet.preview.action.HtmlHelper.FOREGROUND_COLOR;
+import static org.hisp.dhis.reportsheet.preview.action.HtmlHelper.TEXT_COLOR;
import static org.hisp.dhis.reportsheet.utils.ExcelUtils.convertAlignmentString;
import static org.hisp.dhis.reportsheet.utils.ExcelUtils.readValueByPOI;
import static org.hisp.dhis.reportsheet.utils.NumberUtils.PATTERN_DECIMAL_FORMAT1;
import static org.hisp.dhis.reportsheet.utils.NumberUtils.applyPatternDecimalFormat;
import static org.hisp.dhis.reportsheet.utils.NumberUtils.resetDecimalFormatByLocale;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.util.Collection;
+import java.util.List;
import java.util.Locale;
import java.util.Set;
-import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Font;
-import org.apache.poi.ss.usermodel.FormulaEvaluator;
-import org.apache.poi.ss.usermodel.IndexedColors;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
-import org.apache.poi.ss.usermodel.Workbook;
-import org.apache.poi.ss.util.CellRangeAddress;
-import org.apache.poi.xssf.usermodel.XSSFWorkbook;
+import org.hisp.dhis.reportsheet.importitem.ImportItem;
/**
* Simple demo class which uses the api to present the contents of an excel 97
@@ -62,104 +56,27 @@
*/
public class XMLStructureResponse
+ extends AbstractXMLStructure
{
- /**
- * The encoding to write
- */
- private StringBuffer xml = new StringBuffer( 200000 );
-
- /**
- * The workbook we are reading from a given file
- */
- private Workbook WORKBOOK;
-
- private FormulaEvaluator evaluatorFormula;
-
- private static final String WORKBOOK_OPENTAG = "<workbook>";
-
- private static final String WORKBOOK_CLOSETAG = "</workbook>";
-
- private static final String MERGEDCELL_OPENTAG = "<MergedCells>";
-
- private static final String MERGEDCELL_CLOSETAG = "</MergedCells>";
-
- // -------------------------------------------------------------------------
- // Get & Set methods
- // -------------------------------------------------------------------------
-
- protected String getXml()
- {
- return xml.toString();
- }
-
- private void cleanUpForResponse()
- {
- System.gc();
- }
-
- /**
- * Constructor
- *
- * @param w The workbook to interrogate
- * @param enc The encoding used by the output stream. Null or unrecognized
- * values cause the encoding to default to UTF8
- * @param f Indicates whether the generated XML document should contain the
- * cell format information
- * @exception java.io.IOException
- */
-
- public XMLStructureResponse( String pathFileName, Set<Integer> collectSheets )
+ // -------------------------------------------------------------------------
+ // Sub-methods
+ // -------------------------------------------------------------------------
+
+ protected XMLStructureResponse( String pathFileName, Set<Integer> collectSheets, List<ImportItem> importItems )
throws Exception
{
- this.cleanUpForResponse();
-
- if ( getExtension( pathFileName ).equals( "xls" ) )
- {
- this.WORKBOOK = new HSSFWorkbook( new FileInputStream( pathFileName ) );
- }
- else
- {
- this.WORKBOOK = new XSSFWorkbook( new FileInputStream( pathFileName ) );
- }
-
+ super( pathFileName, collectSheets, importItems );
+ }
+
+ @Override
+ protected void setUpDecimalFormat()
+ {
resetDecimalFormatByLocale( Locale.GERMAN );
applyPatternDecimalFormat( PATTERN_DECIMAL_FORMAT1 );
-
- this.evaluatorFormula = WORKBOOK.getCreationHelper().createFormulaEvaluator();
-
- writeFormattedXML( collectSheets );
-
- }
-
- /**
- * Writes out the WORKBOOK data as XML, with formatting information
- *
- * @param bDetailed
- *
- * @throws Exception
- */
-
- private void writeFormattedXML( Collection<Integer> collectSheets )
- throws Exception
- {
-
- this.writeXMLMergedDescription( collectSheets );
-
- xml.append( WORKBOOK_OPENTAG );
-
- for ( Integer sheet : collectSheets )
- {
- writeBySheetNo( sheet );
- }
-
- xml.append( WORKBOOK_CLOSETAG );
- }
-
- // -------------------------------------------------------------------------
- // Sub-methods
- // -------------------------------------------------------------------------
-
- private void writeBySheetNo( int sheetNo )
+ }
+
+ @Override
+ protected void printData( int sheetNo, List<ImportItem> importItems )
{
Sheet s = WORKBOOK.getSheetAt( sheetNo - 1 );
@@ -181,7 +98,7 @@
+ readValueByPOI( row.getRowNum() + 1, cell.getColumnIndex() + 1, s, evaluatorFormula )
+ "]]></data>" );
- this.readingDetailsFormattedCell( s, cell );
+ readingDetailsFormattedCell( s, cell );
xml.append( "</col>" );
}
@@ -210,9 +127,10 @@
xml.append( "><font s='" + font.getFontHeightInPoints() + "'" );
xml.append( " b='" + (font.getBoldweight() == Font.BOLDWEIGHT_BOLD ? "1" : "0") + "'" );
xml.append( " i='" + font.getItalic() + "'" );
- xml.append( " c='" + getSimilarColor( font.getColor() ) + "'" );
- xml.append( "/>" );
+ xml.append( " c='" + htmlHelper.colorStyle( TEXT_COLOR, format ) + "'/>" );
+ // The cell background information
+ xml.append( "<bg c='" + htmlHelper.colorStyle( FOREGROUND_COLOR, format ) + "'/>" );
xml.append( "</format>" );
}
else
@@ -221,61 +139,4 @@
}
}
}
-
- // -------------------------------------------------------------------------
- // Get the merged cell's information
- // -------------------------------------------------------------------------
-
- private void writeXMLMergedDescription( Collection<Integer> collectSheets )
- throws IOException
- {
- // Open the main Tag //
- xml.append( MERGEDCELL_OPENTAG );
-
- for ( Integer sheet : collectSheets )
- {
- writeMergedInfoBySheetNo( sheet );
- }
-
- // Close the main Tag //
- xml.append( MERGEDCELL_CLOSETAG );
- }
-
- private void writeMergedInfoBySheetNo( int sheetNo )
- {
- Sheet sheet = WORKBOOK.getSheetAt( sheetNo - 1 );
- CellRangeAddress cellRangeAddress = null;
-
- for ( int i = 0; i < sheet.getNumMergedRegions(); i++ )
- {
- cellRangeAddress = sheet.getMergedRegion( i );
-
- if ( cellRangeAddress.getFirstColumn() != cellRangeAddress.getLastColumn() )
- {
- xml.append( "<cell " + "iKey='" + (sheetNo) + "#" + cellRangeAddress.getFirstRow() + "#"
- + cellRangeAddress.getFirstColumn() + "'>"
- + (cellRangeAddress.getLastColumn() - cellRangeAddress.getFirstColumn() + 1) + "</cell>" );
- }
- }
- }
-
- private String getSimilarColor( short index )
- {
- if ( IndexedColors.BLUE.getIndex() == index )
- {
- return "blue";
- }
-
- if ( IndexedColors.DARK_BLUE.getIndex() == index )
- {
- return "darkblue";
- }
-
- if ( IndexedColors.BROWN.getIndex() == index )
- {
- return "brown";
- }
-
- return "";
- }
}
\ No newline at end of file
=== modified file 'local/vn/dhis-web-spreadsheet-reporting/src/main/java/org/hisp/dhis/reportsheet/preview/action/XMLStructureResponseImport.java'
--- local/vn/dhis-web-spreadsheet-reporting/src/main/java/org/hisp/dhis/reportsheet/preview/action/XMLStructureResponseImport.java 2012-11-27 04:26:35 +0000
+++ local/vn/dhis-web-spreadsheet-reporting/src/main/java/org/hisp/dhis/reportsheet/preview/action/XMLStructureResponseImport.java 2012-12-15 09:52:30 +0000
@@ -1,7 +1,7 @@
package org.hisp.dhis.reportsheet.preview.action;
/*
- * Copyright (c) 2004-2011, University of Oslo
+ * Copyright (c) 2004-2012, University of Oslo
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -27,149 +27,39 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-import static org.apache.commons.io.FilenameUtils.getExtension;
-import static org.hisp.dhis.reportsheet.utils.ExcelUtils.convertAlignmentString;
import static org.hisp.dhis.reportsheet.utils.ExcelUtils.readValueByPOI;
-import static org.hisp.dhis.reportsheet.utils.NumberUtils.PATTERN_DECIMAL_FORMAT1;
-import static org.hisp.dhis.reportsheet.utils.NumberUtils.applyPatternDecimalFormat;
-import static org.hisp.dhis.reportsheet.utils.NumberUtils.resetDecimalFormatByLocale;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.util.Collection;
import java.util.List;
-import java.util.Locale;
+import java.util.Set;
-import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
-import org.apache.poi.ss.usermodel.CellStyle;
-import org.apache.poi.ss.usermodel.Font;
-import org.apache.poi.ss.usermodel.FormulaEvaluator;
-import org.apache.poi.ss.usermodel.IndexedColors;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
-import org.apache.poi.ss.usermodel.Workbook;
-import org.apache.poi.ss.util.CellRangeAddress;
-import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.hisp.dhis.reportsheet.importitem.ImportItem;
/**
*
* @author Dang Duy Hieu
- * @version $Id XMLStructureResponse.java 2011-06-28 16:08:00$
+ * @version $Id XMLStructureResponseImport.java 2011-06-28 16:08:00$
*/
public class XMLStructureResponseImport
+ extends AbstractXMLStructure
{
- /**
- * The encoding to write
- */
- private StringBuffer xml = new StringBuffer( 200000 );
-
- /**
- * The workbook we are reading from a given file
- */
- private Workbook WORKBOOK;
-
- private FormulaEvaluator evaluatorFormula;
-
- private static final String WORKBOOK_OPENTAG = "<workbook>";
-
- private static final String WORKBOOK_CLOSETAG = "</workbook>";
-
- private static final String MERGEDCELL_OPENTAG = "<MergedCells>";
-
- private static final String MERGEDCELL_CLOSETAG = "</MergedCells>";
-
- // -------------------------------------------------------------------------
- // Get & Set methods
- // -------------------------------------------------------------------------
-
- public String getXml()
- {
- return xml.toString();
- }
-
- /**
- * Constructor
- *
- * @param importItems
- *
- * @param w The workbook to interrogate
- * @param enc The encoding used by the output stream. Null or unrecognized
- * values cause the encoding to default to UTF8
- * @param f Indicates whether the generated XML document should contain the
- * cell format information
- * @exception java.io.IOException
- */
-
- public XMLStructureResponseImport( String pathFileName, Collection<Integer> collectSheets,
- List<ImportItem> importItems, boolean bWriteDescription )
- throws Exception
- {
- this.cleanUpForResponse();
-
- FileInputStream inputStream = new FileInputStream( pathFileName );
-
- if ( getExtension( pathFileName ).equals( "xls" ) )
- {
- this.WORKBOOK = new HSSFWorkbook( inputStream );
- }
- else
- {
- this.WORKBOOK = new XSSFWorkbook( inputStream );
- }
-
- resetDecimalFormatByLocale( Locale.GERMAN );
- applyPatternDecimalFormat( PATTERN_DECIMAL_FORMAT1 );
-
- this.evaluatorFormula = WORKBOOK.getCreationHelper().createFormulaEvaluator();
-
- this.writeFormattedXML( collectSheets, importItems, bWriteDescription );
- }
-
- // -------------------------------------------------------------------------
- // Private methods
- // -------------------------------------------------------------------------
-
- private void cleanUpForResponse()
- {
- System.gc();
- }
-
- private void writeFormattedXML( Collection<Integer> collectSheets, List<ImportItem> importItems,
- boolean bWriteDescription )
- throws Exception
- {
- if ( bWriteDescription )
- {
- this.writeXMLMergedDescription( collectSheets );
- }
-
- xml.append( WORKBOOK_OPENTAG );
-
- for ( Integer sheet : collectSheets )
- {
- this.writeData( sheet, importItems );
- }
-
- xml.append( WORKBOOK_CLOSETAG );
- }
-
- private void writeXMLMergedDescription( Collection<Integer> collectSheets )
- throws IOException
- {
- xml.append( MERGEDCELL_OPENTAG );
-
- for ( Integer sheet : collectSheets )
- {
- writeBySheetNo( sheet );
- }
-
- xml.append( MERGEDCELL_CLOSETAG );
- }
-
- private void writeData( int sheetNo, List<ImportItem> importItems )
+ public XMLStructureResponseImport( String pathFileName, Set<Integer> collectSheets, List<ImportItem> importItems )
+ throws Exception
+ {
+ super( pathFileName, collectSheets, importItems );
+ }
+
+ @Override
+ protected void setUpDecimalFormat()
+ {
+ // TODO: Nothing
+ }
+
+ @Override
+ protected void printData( int sheetNo, List<ImportItem> importItems )
{
Sheet s = WORKBOOK.getSheetAt( sheetNo - 1 );
@@ -216,7 +106,7 @@
xml.append( "<data><![CDATA[" + readValueByPOI( i + 1, j + 1, s, evaluatorFormula ) + "]]></data>" );
- this.readingDetailsFormattedCell( s, cell );
+ this.printFormatInfo( s, cell );
xml.append( "</col>" );
}
@@ -230,73 +120,4 @@
}
xml.append( "</sheet>" );
}
-
- private void writeBySheetNo( int sheetNo )
- {
- Sheet sheet = WORKBOOK.getSheetAt( sheetNo - 1 );
- CellRangeAddress cellRangeAddress = null;
-
- for ( int i = 0; i < sheet.getNumMergedRegions(); i++ )
- {
- cellRangeAddress = sheet.getMergedRegion( i );
-
- if ( cellRangeAddress.getFirstColumn() != cellRangeAddress.getLastColumn() )
- {
- xml.append( "<cell " + "iKey='" + (sheetNo) + "#" + cellRangeAddress.getFirstRow() + "#"
- + cellRangeAddress.getFirstColumn() + "'>"
- + (cellRangeAddress.getLastColumn() - cellRangeAddress.getFirstColumn() + 1) + "</cell>" );
- }
- }
- }
-
- private void readingDetailsFormattedCell( Sheet sheet, Cell objCell )
- {
- // The format information
- CellStyle format = objCell.getCellStyle();
-
- if ( format != null )
- {
- xml.append( "<format a='" + convertAlignmentString( format.getAlignment() ) + "'" );
- xml.append( " b='"
- + (format.getBorderBottom() + format.getBorderLeft() + format.getBorderRight() + format.getBorderTop())
- + "'" );
-
- Font font = WORKBOOK.getFontAt( format.getFontIndex() );
-
- if ( font != null )
- {
- xml.append( "><font s='" + font.getFontHeightInPoints() + "'" );
- xml.append( " b='" + (font.getBoldweight() == Font.BOLDWEIGHT_BOLD ? "1" : "0") + "'" );
- xml.append( " i='" + font.getItalic() + "'" );
- xml.append( " c='" + getSimilarColor( font.getColor() ) + "'" );
- xml.append( "/>" );
-
- xml.append( "</format>" );
- }
- else
- {
- xml.append( "/>" );
- }
- }
- }
-
- private String getSimilarColor( short index )
- {
- if ( IndexedColors.BLUE.getIndex() == index )
- {
- return "blue";
- }
-
- if ( IndexedColors.DARK_BLUE.getIndex() == index )
- {
- return "darkblue";
- }
-
- if ( IndexedColors.BROWN.getIndex() == index )
- {
- return "brown";
- }
-
- return "";
- }
}
\ No newline at end of file
=== added file 'local/vn/dhis-web-spreadsheet-reporting/src/main/java/org/hisp/dhis/reportsheet/preview/action/XSSFHtmlHelper.java'
--- local/vn/dhis-web-spreadsheet-reporting/src/main/java/org/hisp/dhis/reportsheet/preview/action/XSSFHtmlHelper.java 1970-01-01 00:00:00 +0000
+++ local/vn/dhis-web-spreadsheet-reporting/src/main/java/org/hisp/dhis/reportsheet/preview/action/XSSFHtmlHelper.java 2012-12-15 09:52:30 +0000
@@ -0,0 +1,87 @@
+package org.hisp.dhis.reportsheet.preview.action;
+
+/*
+ * Copyright (c) 2004-2012, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import org.apache.poi.ss.usermodel.CellStyle;
+import org.apache.poi.xssf.usermodel.XSSFCellStyle;
+import org.apache.poi.xssf.usermodel.XSSFColor;
+
+/**
+ * @author Dang Duy Hieu
+ * @version $Id$
+ */
+
+public class XSSFHtmlHelper
+ implements HtmlHelper
+{
+ public String colorStyle( String type, CellStyle style )
+ {
+ if ( type == null || type.trim().isEmpty() )
+ {
+ return EMPTY;
+ }
+
+ XSSFCellStyle cellStyle = (XSSFCellStyle) style;
+
+ XSSFColor color = null;
+
+ if ( type.equals( FOREGROUND_COLOR ) )
+ {
+ color = cellStyle.getFillForegroundXSSFColor();
+ }
+ else
+ {
+ color = cellStyle.getFont().getXSSFColor();
+ }
+
+ if ( color == null || color.isAuto() )
+ {
+ return EMPTY;
+ }
+
+ byte[] rgb = color.getRgb();
+
+ if ( rgb == null )
+ {
+ return EMPTY;
+ }
+
+ // This is done twice -- rgba is new with CSS 3, and browser that don't
+ // support it will ignore the rgba specification and stick with the
+ // solid color, which is declared first
+
+ byte[] argb = color.getARgb();
+
+ if ( argb == null )
+ {
+ return EMPTY;
+ }
+
+ return "rgb(" + argb[3] + "," + argb[0] + "," + argb[1] + "," + argb[2] + ")";
+ }
+}
=== modified file 'local/vn/dhis-web-spreadsheet-reporting/src/main/webapp/dhis-web-spreadsheet-reporting/javascript/autoGenerateForm.js'
--- local/vn/dhis-web-spreadsheet-reporting/src/main/webapp/dhis-web-spreadsheet-reporting/javascript/autoGenerateForm.js 2012-12-12 09:34:51 +0000
+++ local/vn/dhis-web-spreadsheet-reporting/src/main/webapp/dhis-web-spreadsheet-reporting/javascript/autoGenerateForm.js 2012-12-15 09:52:30 +0000
@@ -92,7 +92,7 @@
_rows = _sheets[s].getElementsByTagName( 'row' );
_orderSheet = getRootElementAttribute( _sheets[s], "id" );
- _sHTML.push( "<table>" );
+ _sHTML.push( "<table cellspacing='1'><tbody>" );
for (var i = 0 ; i < _rows.length ; i ++)
{
@@ -109,7 +109,7 @@
// Printing out the unformatted cells
for (; _index < _number ; _index ++)
{
- _sHTML.push( "<td/>" );
+ _sHTML.push( "<td> </td>" );
}
if ( _index == _number )
@@ -117,10 +117,12 @@
var _sData = getElementValue( _cols[j], 'data' );
var _align = getElementAttribute( _cols[j], 'format', 'a' );
var _border = getElementAttribute( _cols[j], 'format', 'b' );
+ var _width = getElementAttribute( _cols[j], 'format', 'w' );
var _size = getElementAttribute( _cols[j], 'font', 's' );
var _bold = getElementAttribute( _cols[j], 'font', 'b' );
var _italic = getElementAttribute( _cols[j], 'font', 'i' );
- var _color = getElementAttribute( _cols[j], 'font', 'c' );
+ var _fcolor = getElementAttribute( _cols[j], 'font', 'c' );
+ var _bgcolor = getElementAttribute( _cols[j], 'bg', 'c' );
// If this cell is merged - Key's form: Sheet#Row#Col
_sPattern = _orderSheet + "#" + i + "#" + _number;
@@ -131,26 +133,36 @@
_index = Number(_index) + Number(_colspan);
_size = Number(_size) + 2;
- _sHTML.push( "<td align='", _align, "' colspan='", _colspan, "'" );
- _sHTML.push( " style='font-size:", _size, "px" );
- _sHTML.push( _color == "" ? "'" : ";color:" + _color + "'" );
- _sHTML.push( _border > 0 ? " ui-widget-content" : "" );
-
+ // style for <td>
+ _sHTML.push( "<td colspan='", _colspan, "'" );
+ _sHTML.push( " style='text-align: ", _align, ";" );
+ _sHTML.push( _bgcolor == "" ? "" : " background-color: " + _bgcolor + ";" );
+ _sHTML.push( _width > 0 ? " width: " + _width + ";" : "" );
+ _sHTML.push( "'>" );
+
if ( _bold == "1" )
{
- _sData = "<b>" + _sData + "</b>";
+ _sData = "<strong>" + _sData + "<strong>";
}
if ( _italic == "true" )
{
_sData = "<i>" + _sData + "</i>";
}
+ if ( _size > 0 )
+ {
+ _sData = "<span style='font-size: " + _size + "px;'>" + _sData + "</span>";
+ }
+ if ( _fcolor != "" )
+ {
+ _sData = "<span style='color:" + _fcolor + ";'>" + _sData + "</span>";
+ }
- _sHTML.push( "'>", _sData, "</td>" );
+ _sHTML.push( _sData, "</td>" );
}
}
_sHTML.push( "</tr>" );
}
- _sHTML.push( "</table>" );
+ _sHTML.push( "</tbody></table>" );
}
//jQuery( '#previewDiv' ).html( _sHTML.join('') );