← Back to team overview

dhis2-devs team mailing list archive

Re: Copy data from Excel to data entry form

 

Hi Paul,

It is only available on Vietnam branch, not in main trunk. There are 2
ways. I can send the code snippet and you paste onto your current
data-entry module. The other way is to make a petition to global to include
this into trunk.

Actually code is so simple, they all are client sides and very easy to adapt


//COPY AND PASTE THIS SNIPPET TO ANY VM FILE OF THE DATAENTRY MODULE

<!--make a link on top of the page-->
<div id='exportPanel' style='position:fixed; right:30px; top:20px;
border-bottom: 1px solid grey; '>
<a href='javascript:importExcel();' style='color:white;'>Import Excel...</a>
</div>

<!--this is the dialog -->
<div id='pasteTableDialog' style='display:none;'>
Step 1. Open Excel sheet, select area and press Ctrl+C <br/>
Step 2. Press Ctr+V to paste to this box: <textarea id='excel_data'
onblur='createSourceTable();' onfocus="$(this).val('');"></textarea> <br/>
Step 3. Press this button to transfer data <input type='button'
value='Copy' onclick='copyTable();' cols='20' />

<hr/>
<div id='excel_table'></div>

</div>

<script>
$( "#pasteTableDialog" ).dialog({
width: 850,
height: 750,
autoOpen: false,
modal:true,
title:"COPY FROM EXCEL"
});

function importExcel()
{
$( "#pasteTableDialog" ).dialog('open');
}

function createSourceTable()
{
var data = $('#excel_data').val();
var rows = data.split("\n");

var table = $('<table border=1 />');

for(var y in rows)
{
    var cells = rows[y].split("\t");
    var row = $('<tr />');
    for(var x in cells) {
        row.append('<td>'+cells[x]+'</td>');
    }
    table.append(row);
}

// build the table from clipboard data
$('#excel_table').html(table);
}

function copyTable()
{

    var oSource = $("#excel_table");

    var oDest = $("#contentDiv"); //contentDiv is a dhis div

    var arrSourceInputs = oSource.find("td");

    $('.entryfield').each(function(i){
td = arrSourceInputs[i];
        $(this).val(td.innerText);
 //trigger change to call saveValue
$(this).change();
    });
}

//END OF THE SNIPPET




*Nguyễn Ngọc Thành*



On Wed, Sep 25, 2013 at 9:13 PM, Paul Amendola <Paul.Amendola@xxxxxxxxxx>wrote:

>  Hi Ngoc****
>
> ** **
>
> This feature is great and exactly what we need. How can I download the
> feature? Any chance you have an English version of the guidelines?****
>
> ** **
>
> Thanks****
>
> Paul****
>
> ** **
>
> ** **
>
> *Paul R. Amendola | Technical Advisor for Health Information Systems
> *International Rescue Committee****
>
> 122 E 42nd Street, New York, NY 10168-1289 | *Rescue.org*
> T +1 212 551 0995 | Skype paul.amendola ****
>
> [image: IRC eSignature Graphic]****
>
> ** **
>
> ** **
>
> ** **
>
> ** **
>
> *From:* Dhis2-devs [mailto:dhis2-devs-bounces+paul.amendola=
> theirc.org@xxxxxxxxxxxxxxxxxxx] *On Behalf Of *Ngoc Thanh Nguyen
> *Sent:* Wednesday, September 25, 2013 6:29 AM
> *To:* dhis2-devs; Thuy Nguyen
>
> *Subject:* [Dhis2-devs] Copy data from Excel to data entry form****
>
>  ** **
>
> I have made a feature that allows direct copy from Excel sheet and past to
> data entry form****
>
> ** **
>
> If anyone are interest, you can refer the doc below****
>
> ** **
>
> Here is some screenshots on how it works****
>
> ** **
>
> https://dl.dropboxusercontent.com/u/63702128/HuongDanImport.docx****
>
>
> ****
>
> ****
>
> *Nguyễn Ngọc Thành*****
>
> ** **
>

References