0

I have uploaded CSV file in visualforce page,When i click on the Download button then download the excel file,this is actual scenario,But here button also downloading along with excel file,How to remove the Button from downloded excel file ?

////////////visualforce page////////

<apex:page controller="importDataFromCSVController" sidebar="false" standardStylesheets="false"  cache="true" applyBodyTag="true" 
        applyHtmlTag="true" showHeader="true" contentType="{!IF(exprots = true, 'application/vnd.ms-excel#report.xls', '')}">



<script>
        function refersh(){
            var url = window.location.href;
            window.location = url;
        }
    </script> 

    <apex:form >
        <apex:pagemessages />
        <apex:pageBlock >
        <apex:pageBlockSection columns="4"  > 


                <apex:inputFile value="{!csvFileBody}"  filename="{!csvAsString}"/>
            <apex:commandButton value="Import CAMT File" action="{!importCSVFile}" rendered="{!camtlist.size!=Null}" disabled="{!IF((camtlist.size>0 ), true, false)}"/>
                <!-- <apex:commandButton value="Import CAMT File" action="{!importCSVFile}" rendered="{!camtlist.size!=Null}"/>   rendered="{!camtlist.size!=Null}"-->

                <!--<apex:commandButton value="Download Excel" action="{!ExcelFileDownload}" /> -->

        </apex:pageBlockSection>
        <!--- <apex:outputText value="{!trno}"></apex:outputText>--->

        </apex:pageBlock>
        <apex:pageBlock rendered="{!camtlist.size>0}">
        <apex:pageblocktable value="{!camtlist}" var="cam">

                <!--- CAMT File Uploaded --->
            <!---  <apex:column value="{!cam.Name}" headerValue="ESR Number"/>
            <apex:column value="{!cam.CAMT_ESRNumber_optional__c}" headerValue="CAMT ESR Number"/>
            <apex:column value="{!cam.Status__c}" headerValue="CAMT Status"/>  --->

            <apex:column value="{!cam.CAMT_IDNUMBER__c  }" headerValue="CAMT ESR ID"/>
        <!--- <apex:column value="{!cam.CAMT_ESR_Numberformula_del__c}" headerValue="CAMT ESR ID"/> --->
            <apex:column value="{!cam.CAMT_ESRNumber__c}" headerValue="CAMT ESRNUmber"/>
            <apex:column value="{!cam.CAMT_TotalAmount__c}" headerValue="CAMT Total Amount"/>
            <apex:column value="{!cam.CAMT_Customer_Name__c}" headerValue="CAMT Customer Name"/>
            <apex:column value="{!cam.CAMT_CustomerAddress__c}" headerValue="CAMT Customer Address" /> 
            <apex:column value="{!cam.CAMT_Payment_Date__c}" headerValue="CAMT Payment Date"/>

            <!--- <apex:column value="{!cam.CAMT_Upload_Date_File__c}" headerValue="CAMT:Upload Date File" />--------->
            <!---<apex:column value="{!cam.CAMT_Payment__c}" headerValue="CAMT:CAMT Payment" />--->
            <!--- <apex:column value="{!cam.CAMT_CustomerAddress__c}" headerValue="CAMT Customer Address" /> --->


            <!---- Fetch Data From Data Base --->

            <apex:column value="{!cam.ESR_Status__c}" headerValue="Process Match" />
            <apex:column value="{!cam.Name}"  headerValue="ESRNumber"/>
            <apex:column value="{!cam.Total_Amount__c}" headerValue="Total Amount"/>
            <apex:column value="{!cam.ThreShold__c}" headerValue="Threshold Value"/>
            <apex:column value="{!cam.Customer_Name__c}" headerValue="Customer Name"/>
            <apex:column value="{!cam.Customer_Street__c}" headerValue="Customer street" />
            <apex:column value="{!cam.Customer_City_del__c}" headerValue="Customer City" />
            <apex:column value="{!cam.Customer_State__c}" headerValue="Customer State" />
            <apex:column value="{!cam.Customer_Country_del__c}" headerValue="Customer Country" />
            <apex:column value="{!cam.Customer_Pincode_del__c}" headerValue="Customer Pincode" />
            <apex:column value="{!cam.Company_Name__c}" headerValue="Company Name" />
            <apex:column value="{!cam.Payment__c}" headerValue="Payment" /> 
            <apex:column value="{!cam.Payment_Date__c}" headerValue="Payment Date" /> 
            <apex:column value="{!cam.Difference__c}" headerValue="Difference" /> 

            <!--- <apex:column headerValue="Adress">

            <apex:outputText value="{!cam.Customer_Address1__c}">
            </apex:outputText> 
            </apex:column>  --->

        </apex:pageblocktable>

    <apex:pageBlockButtons >
                <apex:actionregion >
                    <apex:commandButton value="Download Excel" action="{!ExcelFileDownload}" rendered="{!camtlist.size>0}" />
                    <input type="button" class="btn" value="Clear" onclick="refersh();" style="{!IF((camtlist.size>0 ), '', 'display:none')}"/>
                </apex:actionregion>
            </apex:pageBlockButtons> 
    </apex:pageBlock>



</apex:form>
</apex:page>

//////////////////////controll class/////////////

public with sharing class importDataFromCSVController {

public Blob csvFileBody {get;set;}
public String csvAsString {get;set;}
public String[] CsvFileLines {get;set;}
public List < ESR_Assignment__c > camtlist {get;set;}
public Boolean exprots {get;set;}
public Map < String, ESR_Assignment__c > esrNoByESR;
public decimal trno {get;set;}
public String xmlheader {get;set;}
public String endfile{get;set;}

public importDataFromCSVController() {
exprots = False;
CsvFileLines = new string[] {};
camtlist = new list < ESR_Assignment__c > ();
esrNoByESR = new Map < String, ESR_Assignment__c > ();

for (ESR_Assignment__c objesrs: [select id, Name, ESR_Status__c, Payment__c, Payment_Date__c, Company_Name__c, Difference__c, Customer_Street__c,Customer_City_del__c,Customer_State__c,
                                    Customer_Country_del__c,Customer_Pincode_del__c,CAMT_Payment_Date__c,CAMT_IDNUMBER__c,Threshold__c,
                                    CAMT_ESRNumber__c, Total_Amount__c, CAMT_TotalAmount__c, Customer_Name__c,
                                    CAMT_Customer_Name__c, CAMT_CustomerAddress__c,
                                    CAMT_Upload_Date_File__c from ESR_Assignment__c
                                ]) {

        esrNoByESR.put(objesrs.Name, objesrs);
        esrNoByESR.put(objesrs.CAMT_ESRNumber__c, objesrs);
}
    system.debug('==33==' + esrNoByESR);
}

public void importCSVFile() {
csvAsString = csvFileBody.toString();
CsvFileLines = csvAsString.split('\n');
system.debug('====' + esrNoByESR);
List < ESR_Assignment__c > upertToList = new List < ESR_Assignment__c > ();

for (Integer i = 1; i < CsvFileLines.size(); i++) {

String[] CsvRecordData = CsvFileLines[i].split(',');
ESR_Assignment__c objesrs = new ESR_Assignment__c();


    String esrnum = (CsvRecordData[1]).trim();

//String esrnum = (CsvRecordData[0]).trim();
system.debug('==='+(CsvRecordData[1]).trim());


Decimal camttotalAmount =0.00;
if(!String.isEmpty((CsvRecordData[2]).trim())){
    camttotalAmount = decimal.valueof((CsvRecordData[2]).trim());
}

// Decimal thr=0.00;
// thr=decimal.valueof(Threshold__c); 


///////////////////////scenario3/////////////

if (esrNoByESR.keySet() !=Null && esrNoByESR.containsKey(esrnum)){
    objesrs.id = esrNoByESR.get(esrnum).id;
    objesrs.Name = (CsvRecordData[1]);
//  objesrs.Payment__c=(CsvRecordData[1]);
    //String de = String.valueof(CsvRecordData[0]);
    //system.debug('dedded=' + de);
// objesrs.CAMT_ESRNumber__c = Decimal.valueof(de.trim());

/*  objesrs.CAMT_ESRNumber__c =(CsvRecordData[0]);
    objesrs.CAMT_IDNUMBER__c=(CsvRecordData[4]);
    objesrs.CAMT_Payment_Date__c=mydate; */

    //objesrs.Name=objesrs.CAMT_ESRNumber__c;
    // if( objesrs.Status__c == ''){
    // objesrs.Status__c = 'Match';
    // upertToList.add(objesrs);
    // }
        } 

    /*if there is ESR Number is not matched to csv file number this else part will create new esr recordaccordingly */
    else{    
        // objesrs.Name = (CsvRecordData[0]);
        // String de = String.valueof(CsvRecordData[0]);
        //system.debug('dedded=' + de);
        // objesrs.CAMT_ESRNumber_optional__c = Decimal.valueof(de.trim());
    // objesrs.CAMT_ESR_Numberformula_del__c=(CsvRecordData[0]);
        objesrs.CAMT_IDNUMBER__c=(CsvRecordData[0]);
        objesrs.CAMT_ESRNumber__c =(CsvRecordData[1]);
        objesrs.CAMT_TotalAmount__c = camttotalAmount ;
        objesrs.CAMT_Customer_Name__c=(CsvRecordData[3]);
        objesrs.CAMT_CustomerAddress__c=(CsvRecordData[4]);
        objesrs.CAMT_Payment_Date__c=Date.valueof((CsvRecordData[5])); 


        objesrs.ESR_Status__c= 'No Match';
        objesrs.Name='0';
        objesrs.Total_Amount__c=0;
        objesrs.Company_Name__c='Null';
        objesrs.Customer_Name__c='Null';
        objesrs.Customer_Street__c='Null';
        objesrs.Customer_City_del__c='Null';
        objesrs.Customer_State__c='Null';
        objesrs.Customer_Country_del__c='Null';
        objesrs.Customer_Pincode_del__c='Null';
        objesrs.Threshold__c=0;


        objesrs.Payment__c=Null;
        objesrs.Difference__c=0; 
    //  upertToList.add(objesrs);
        }

////////////////////////secanrio4///////////////////

if (esrNoByESR.keySet() != Null && esrNoByESR.containsKey(esrnum) && esrNoByESR.get(esrnum).Payment__c == 'Not Paid' &&
    esrNoByESR.get(esrnum).Total_Amount__c == camttotalAmount && esrNoByESR.get(esrnum).Total_Amount__c < = esrNoByESR.get(esrnum).Threshold__c) {


// if (esrNoByESR.keySet() != Null && esrNoByESR.containsKey(esrnum) && esrNoByESR.get(esrnum).Payment__c == 'Not Paid' && esrNoByESR.get(esrnum).Total_Amount__c == camttotalAmount ) {
    objesrs.id = esrNoByESR.get(esrnum).id;
    objesrs.Name = (CsvRecordData[1]);
    //objesrs.CAMT_ESR_Numberformula__c= camtesrnumber;
    objesrs.CAMT_IDNUMBER__c=(CsvRecordData[0]);
    objesrs.CAMT_ESRNumber__c =(CsvRecordData[1]);
    objesrs.CAMT_TotalAmount__c = camttotalAmount ;
    objesrs.CAMT_Customer_Name__c=(CsvRecordData[3]);
    objesrs.CAMT_CustomerAddress__c=(CsvRecordData[4]);
    objesrs.CAMT_Payment_Date__c=Date.valueof((CsvRecordData[5])); 


    system.debug('esrNoByESR.get(esrnum).Total_Amount__c=' + esrNoByESR.get(esrnum).Total_Amount__c);
    objesrs.Total_Amount__c = esrNoByESR.get(esrnum).Total_Amount__c;
    objesrs.Customer_Name__c = esrNoByESR.get(esrnum).Customer_Name__c;
    objesrs.Difference__c = esrNoByESR.get(esrnum).Difference__c;
    objesrs.Payment__c = esrNoByESR.get(esrnum).Payment__c;
    objesrs.Payment_Date__c = esrNoByESR.get(esrnum).Payment_Date__c;
    objesrs.Company_Name__c = esrNoByESR.get(esrnum).Company_Name__c;
    objesrs.Customer_Street__c=esrNoByESR.get(esrnum).Customer_Street__c;
    objesrs.Customer_City_del__c=esrNoByESR.get(esrnum).Customer_City_del__c;
    objesrs.Customer_State__c=esrNoByESR.get(esrnum).Customer_State__c;
    objesrs.Customer_Country_del__c=esrNoByESR.get(esrnum).Customer_Country_del__c;
    objesrs.Customer_Pincode_del__c=esrNoByESR.get(esrnum).Customer_Pincode_del__c;
    objesrs.Threshold__c=esrNoByESR.get(esrnum).Threshold__c;


//   objesrs.Test__c = Integer.valueof((CsvRecordData[0]).trim());

    objesrs.Payment__c ='Paid';
    objesrs.ESR_Status__c= 'Match';
    objesrs.Difference__c=0;
    upertToList.add(objesrs);
}

//////////////////////////secanrio 5//////////
else if (esrNoByESR.keySet() != Null && esrNoByESR.containsKey(esrnum) && esrNoByESR.get(esrnum).Payment__c == 'Not Paid' &&
    esrNoByESR.get(esrnum).Total_Amount__c != camttotalAmount && esrNoByESR.get(esrnum).Total_Amount__c < = esrNoByESR.get(esrnum).Threshold__c) {


//  else if (esrNoByESR.keySet() != Null && esrNoByESR.containsKey(esrnum) && esrNoByESR.get(esrnum).Payment__c == 'Not Paid' && esrNoByESR.get(esrnum).Total_Amount__c != camttotalAmount  ) {


    objesrs.id = esrNoByESR.get(esrnum).id;
    objesrs.Name = (CsvRecordData[1]);
//  objesrs.Test__c = Integer.valueof((CsvRecordData[0]).trim());

    //objesrs.CAMT_ESR_Numberformula__c= camtesrnumber;
    objesrs.CAMT_IDNUMBER__c=(CsvRecordData[0]);
    objesrs.CAMT_ESRNumber__c =(CsvRecordData[1]);
    objesrs.CAMT_TotalAmount__c = camttotalAmount ;
    objesrs.CAMT_Customer_Name__c=(CsvRecordData[3]);
    objesrs.CAMT_CustomerAddress__c=(CsvRecordData[4]);
    objesrs.CAMT_Payment_Date__c=Date.valueof((CsvRecordData[5])); 

    system.debug('esrNoByESR.get(esrnum).Total_Amount__c=' + esrNoByESR.get(esrnum).Total_Amount__c);
    objesrs.Total_Amount__c = esrNoByESR.get(esrnum).Total_Amount__c;
    objesrs.Customer_Name__c = esrNoByESR.get(esrnum).Customer_Name__c;
    objesrs.Difference__c = esrNoByESR.get(esrnum).Difference__c;
    objesrs.Payment__c = esrNoByESR.get(esrnum).Payment__c;
    objesrs.Payment_Date__c = esrNoByESR.get(esrnum).Payment_Date__c;
    objesrs.Company_Name__c = esrNoByESR.get(esrnum).Company_Name__c;
    system.debug(camttotalAmount+'==='+esrNoByESR.get(esrnum).Total_Amount__c+'===='+(camttotalAmount-esrNoByESR.get(esrnum).Total_Amount__c).toPlainString());
    objesrs.Difference__c=camttotalAmount-esrNoByESR.get(esrnum).Total_Amount__c;
    objesrs.Customer_Street__c=esrNoByESR.get(esrnum).Customer_Street__c;
    objesrs.Customer_City_del__c=esrNoByESR.get(esrnum).Customer_City_del__c;
    objesrs.Customer_State__c=esrNoByESR.get(esrnum).Customer_State__c;
    objesrs.Customer_Country_del__c=esrNoByESR.get(esrnum).Customer_Country_del__c;
    objesrs.Customer_Pincode_del__c=esrNoByESR.get(esrnum).Customer_Pincode_del__c;
    objesrs.Threshold__c=esrNoByESR.get(esrnum).Threshold__c;

    objesrs.ESR_Status__c= 'Difference';
//  objesrs.Test__c = Integer.valueof((CsvRecordData[0]).trim());

    upertToList.add(objesrs);

}

//////////////////////secanrio 6////////////////////
/*if there is ESR Number is not matched to csv file number this else part will create new esr recordaccordingly */
else if (esrNoByESR.keySet() != Null && esrNoByESR.containsKey(esrnum) && esrNoByESR.get(esrnum).Payment__c == 'Paid') {
    objesrs.id = esrNoByESR.get(esrnum).id;
    objesrs.Name = (CsvRecordData[1]);
    //objesrs.CAMT_ESR_Numberformula__c= camtesrnumber;//objesrs.Test__c = Integer.valueof((CsvRecordData[0]).trim());
    objesrs.CAMT_IDNUMBER__c=(CsvRecordData[0]);
    objesrs.CAMT_ESRNumber__c =(CsvRecordData[1]);
    objesrs.CAMT_TotalAmount__c = camttotalAmount;
    objesrs.CAMT_Customer_Name__c=(CsvRecordData[3]);
    objesrs.CAMT_CustomerAddress__c=(CsvRecordData[4]);
    objesrs.CAMT_Payment_Date__c=Date.valueof((CsvRecordData[5]));  


    system.debug('esrNoByESR.get(esrnum).Total_Amount__c=' + esrNoByESR.get(esrnum).Total_Amount__c);
    objesrs.Total_Amount__c = esrNoByESR.get(esrnum).Total_Amount__c;
    objesrs.Customer_Name__c = esrNoByESR.get(esrnum).Customer_Name__c;
    objesrs.Difference__c = esrNoByESR.get(esrnum).Difference__c;
    objesrs.Payment__c = esrNoByESR.get(esrnum).Payment__c;
    objesrs.Payment_Date__c = esrNoByESR.get(esrnum).Payment_Date__c;
    objesrs.Company_Name__c = esrNoByESR.get(esrnum).Company_Name__c;
    objesrs.Customer_Street__c=esrNoByESR.get(esrnum).Customer_Street__c;
    objesrs.Customer_City_del__c=esrNoByESR.get(esrnum).Customer_City_del__c;
    objesrs.Customer_State__c=esrNoByESR.get(esrnum).Customer_State__c;
    objesrs.Customer_Country_del__c=esrNoByESR.get(esrnum).Customer_Country_del__c;
    objesrs.Customer_Pincode_del__c=esrNoByESR.get(esrnum).Customer_Pincode_del__c;
    objesrs.Threshold__c=esrNoByESR.get(esrnum).Threshold__c;

    objesrs.ESR_Status__c= 'Already Match';
    objesrs.Difference__c=0;
    upertToList.add(objesrs);
}



camtlist.add(objesrs);
}


system.debug('list==' + camtlist);
// try{
system.debug('coming' + upertToList);
if (camtlist.size() > 0)
update upertToList;
system.debug('going out ' + upertToList);
//  }     
/* Catch(Exception e){

    Apexpages.Message errorMessage =new Apexpages.Message(Apexpages.severity.ERROR,'An error is occured when importing data Please make sure input csv file is correct');

Apexpages.AddMessage(errorMessage );
}
*/
// return null;
}


public PageReference ExcelFileDownload() {


////////////////

//xmlheader ='<?xml version="1.0"?><?mso-application progid="Excel.Sheet"?>';
// endfile = '</Workbook>';
// opportunities = [SELECT Id, Name, StageName, Amount FROM Opportunity LIMIT 10];
// oppSize = opportunities.size();

////////////

exprots = true;
return null;
}

}
  • Please give me anyone solutions. – hari Jan 8 at 4:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.