← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 17720: make HREFs clickable links in xlsx output

 

------------------------------------------------------------
revno: 17720
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2014-12-16 20:16:17 +0100
message:
  make HREFs clickable links in xlsx output
modified:
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/node/serializers/ExcelNodeSerializer.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-services/dhis-service-core/src/main/java/org/hisp/dhis/node/serializers/ExcelNodeSerializer.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/node/serializers/ExcelNodeSerializer.java	2014-12-16 17:06:12 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/node/serializers/ExcelNodeSerializer.java	2014-12-16 19:16:17 +0000
@@ -29,9 +29,12 @@
  */
 
 import com.google.common.collect.Lists;
+import org.apache.poi.ss.usermodel.Hyperlink;
 import org.apache.poi.xssf.usermodel.XSSFCell;
 import org.apache.poi.xssf.usermodel.XSSFCellStyle;
+import org.apache.poi.xssf.usermodel.XSSFCreationHelper;
 import org.apache.poi.xssf.usermodel.XSSFFont;
+import org.apache.poi.xssf.usermodel.XSSFHyperlink;
 import org.apache.poi.xssf.usermodel.XSSFRow;
 import org.apache.poi.xssf.usermodel.XSSFSheet;
 import org.apache.poi.xssf.usermodel.XSSFWorkbook;
@@ -74,7 +77,7 @@
     protected void startSerialize( RootNode rootNode, OutputStream outputStream ) throws Exception
     {
         workbook = new XSSFWorkbook();
-        sheet = workbook.createSheet("Sheet1");
+        sheet = workbook.createSheet( "Sheet1" );
 
         XSSFFont boldFont = workbook.createFont();
         boldFont.setBold( true );
@@ -131,6 +134,8 @@
     @Override
     protected void startWriteRootNode( RootNode rootNode ) throws Exception
     {
+        XSSFCreationHelper creationHelper = workbook.getCreationHelper();
+
         int rowIdx = 1;
 
         for ( Node child : rootNode.getChildren() )
@@ -148,6 +153,15 @@
                         {
                             XSSFCell cell = row.createCell( cellIdx++ );
                             cell.setCellValue( getValue( (SimpleNode) property ) );
+
+                            if ( "href".equals( property.getName() ) )
+                            {
+                                XSSFHyperlink hyperlink = creationHelper.createHyperlink( Hyperlink.LINK_URL );
+                                hyperlink.setAddress( getValue( (SimpleNode) property ) );
+                                hyperlink.setLabel( getValue( (SimpleNode) property ) );
+
+                                cell.setHyperlink( hyperlink );
+                            }
                         }
                     }
                 }