=== modified file 'dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/preview/action/ExportXMLAction.java' --- dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/preview/action/ExportXMLAction.java 2009-09-30 07:03:26 +0000 +++ dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/preview/action/ExportXMLAction.java 2009-09-30 10:08:05 +0000 @@ -48,6 +48,8 @@ { private static final String SEPARATE = "/"; + private static final String ENCODING = "UTF8"; + // ------------------------------------------- // Dependency // ------------------------------------------- @@ -64,8 +66,6 @@ private String xmlStructureResponse; - private String ENCODING; - private File FILE_XLS; // ------------------------------------------- @@ -106,7 +106,7 @@ { try { - init(); + this.init(); xmlStructureResponse = new XMLStructureResponse( this.FILE_XLS.getPath(), ENCODING, true, false, true, false, false ).getSTRUCTURE_DATA_RESPONSE(); === removed file 'dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/preview/action/XMLDescriptionResponse.java' --- dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/preview/action/XMLDescriptionResponse.java 2009-09-30 07:03:26 +0000 +++ dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/preview/action/XMLDescriptionResponse.java 1970-01-01 00:00:00 +0000 @@ -1,183 +0,0 @@ -package org.hisp.dhis.reportexcel.preview.action; - -/* - * Copyright (c) 2004-2007, 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 java.io.File; -import java.io.IOException; - -import jxl.Range; -import jxl.Sheet; -import jxl.Workbook; - -/** - * 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 class XMLDescriptionResponse -{ - /** - * The encoding to write - */ - private String DESCRIPTION_DATA_RESPONSE; - - /** - * The encoding to write - */ - private String ENCODING; - - /** - * The workbook we are reading from - */ - private Workbook WORKBOOK; - - private boolean bWRITE_VERSION; - - private static final String PREFIX_VERSION_XML = ""; - - private static final String MERGEDCELL_OPENTAG = ""; - - private static final String MERGEDCELL_CLOSETAG = ""; - - private static final String PRINT_END_LINE = "\n"; - - public String getDESCRIPTION_DATA_RESPONSE() - { - return DESCRIPTION_DATA_RESPONSE; - } - - public void setDESCRIPTION_DATA_RESPONSE( String description_data_response ) - { - DESCRIPTION_DATA_RESPONSE = description_data_response; - } - - /** - * Constructor - * - * @param w The workbook to interrogate - * @param out The output stream to which the XML values are written - * @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 XMLDescriptionResponse( Workbook w, String encoding, boolean bWriteVersion ) - throws IOException - { - this.ENCODING = encoding; - this.WORKBOOK = w; - this.bWRITE_VERSION = bWriteVersion; - this.DESCRIPTION_DATA_RESPONSE = "\n\n"; - - if ( this.ENCODING == null || !this.ENCODING.equals( "UnicodeBig" ) ) - { - - this.ENCODING = "UTF8"; - } - - writeXMLDescription(); - } - - /** - * Writes out the WORKBOOK data as XML, without formatting information - */ - - private void writeXMLDescription() - throws IOException - { - Sheet sheet = null; - Range[] aMergedCell = null; - - // Get the Range of the Merged Cells // - int no_of_sheets = WORKBOOK.getNumberOfSheets(); - int lens_of_range = 0; - int iColTopLeft = 0; - int iRowTopLeft = 0; - int iColBottomRight = 0; - - /* - * Write XML Description Contents - */ - if ( this.bWRITE_VERSION ) - { - DESCRIPTION_DATA_RESPONSE += PREFIX_VERSION_XML; - DESCRIPTION_DATA_RESPONSE += PRINT_END_LINE + PRINT_END_LINE; - } - - // Open the main Tag // - DESCRIPTION_DATA_RESPONSE += MERGEDCELL_OPENTAG; - DESCRIPTION_DATA_RESPONSE += PRINT_END_LINE + PRINT_END_LINE; - - for ( int i = 0; i < no_of_sheets; i++ ) - { - sheet = WORKBOOK.getSheet( i ); - aMergedCell = sheet.getMergedCells(); - lens_of_range = aMergedCell.length; - - for ( int j = 0; j < lens_of_range; j++ ) - { - iColTopLeft = aMergedCell[j].getTopLeft().getColumn(); - iRowTopLeft = aMergedCell[j].getTopLeft().getRow(); - iColBottomRight = aMergedCell[j].getBottomRight().getColumn(); - - if ( iColTopLeft != iColBottomRight ) - { - // DESCRIPTION_DATA_RESPONSE += " " + "" + (iColBottomRight - - // iColTopLeft + 1) + ""; - // DESCRIPTION_DATA_RESPONSE += PRINT_END_LINE; - - DESCRIPTION_DATA_RESPONSE += " " + (iColBottomRight - iColTopLeft + 1) + ""; - DESCRIPTION_DATA_RESPONSE += PRINT_END_LINE; - } - } - DESCRIPTION_DATA_RESPONSE += PRINT_END_LINE; - } - - // Close the main Tag // - DESCRIPTION_DATA_RESPONSE += PRINT_END_LINE; - DESCRIPTION_DATA_RESPONSE += MERGEDCELL_CLOSETAG; - DESCRIPTION_DATA_RESPONSE += PRINT_END_LINE; - } - - public static void main( String[] args ) - throws Exception - { - System.out.println( new XMLDescriptionResponse( Workbook.getWorkbook( new File( - "c:\\phammemthongke\\reporttemplate\\test_my_preview.xls" ) ), "UTF8", false ) - .getDESCRIPTION_DATA_RESPONSE() ); - } -} === modified file 'dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/preview/action/XMLStructureResponse.java' --- dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/preview/action/XMLStructureResponse.java 2009-09-30 07:03:26 +0000 +++ dhis-2/dhis-web/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/preview/action/XMLStructureResponse.java 2009-09-30 10:08:05 +0000 @@ -111,11 +111,11 @@ public XMLStructureResponse() { - } public XMLStructureResponse( String pathFileName, String enc, boolean bFormat, boolean bDetailed, boolean bWriteDescription, boolean bWriteVersion, boolean bWriteDTD ) + throws Exception { this.PATH_FILE_NAME = pathFileName; @@ -210,6 +210,11 @@ private void writeFormattedXML( boolean bDetailed, boolean bWriteDescription ) throws Exception { + if ( bWriteDescription ) + { + this.writeXMLDescription(); + } + if ( this.bWRITE_VERSION ) { STRUCTURE_DATA_RESPONSE.append( PREFIX_VERSION_XML ); @@ -227,11 +232,6 @@ STRUCTURE_DATA_RESPONSE.append( PRINT_END_LINE ); FileInputStream fis = new FileInputStream( this.PATH_FILE_NAME ); - // org.apache.poi.hssf.usermodel.HSSFWorkbook wb = (HSSFWorkbook) - // WorkbookFactory.create( fis ); - // org.apache.poi.ss.usermodel.FormulaEvaluator evaluator = - // wb.getCreationHelper().createFormulaEvaluator(); - org.apache.poi.ss.usermodel.Workbook wb = new HSSFWorkbook( fis ); org.apache.poi.ss.usermodel.FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator(); @@ -328,12 +328,7 @@ STRUCTURE_DATA_RESPONSE.append( PRINT_END_LINE ); } STRUCTURE_DATA_RESPONSE.append( WORKBOOK_CLOSETAG ); - STRUCTURE_DATA_RESPONSE.append( PRINT_END_LINE + PRINT_END_LINE ); - - if ( bWriteDescription ) - { - this.writeXMLDescription(); - } + STRUCTURE_DATA_RESPONSE.append( PRINT_END_LINE ); } // ------------------------------------------------------------------------- @@ -468,4 +463,9 @@ return s; } } + + public static void main( String[] args ) throws Exception + { + System.out.println(new XMLStructureResponse("c:\\phammemthongke\\reporttemplate\\tx_bieu_2.xls", "UTF8", true, false, true, false, false).getSTRUCTURE_DATA_RESPONSE()); + } }