a contribution from S K Pradeep kumar, see this thread : http://www.nabble.com/CSV-reporting..-td20800340.html![](/confluence/images/icons/linkext7.gif)
![](/confluence/images/icons/linkext7.gif)
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import java.util.*; import org.ofbiz.entity.*; import org.ofbiz.entity.util.EntityUtil; import org.ofbiz.base.util.*; import org.ofbiz.securityext.login.*; import org.ofbiz.common.*; import org.ofbiz.party.contact.*; import org.ofbiz.party.party.*; import org.ofbiz.accounting.payment.*; import org.ofbiz.securityext.login.*; if(partyList != null) { partyListIt = partyList.iterator(); FileWriter fw = new FileWriter("E:\\RAF02Nov\\skp.csv"); fw.append("partyId"); fw.append(','); fw.append("toName"); fw.append(','); fw.append("attnName"); fw.append(','); fw.append("Address1"); fw.append(','); fw.append("Address2"); fw.append(','); fw.append("City"); fw.append(','); fw.append("PostalCode"); fw.append(','); fw.append("State"); fw.append(','); fw.append("Country"); fw.append(','); fw.append("Full Name"); fw.append('\n'); while(partyListIt.hasNext()) { fullName = ""; toName = ""; attnName =""; address1 = ""; address2 = ""; city = ""; state= ""; country = ""; postalCode = ""; email = ""; phone =""; genericPartyList = partyListIt.next(); partyId = genericPartyList.getString("partyId"); List partyContactMechValueMaps = ContactMechWorker.getPartyContactMechValueMaps(delegator, partyId, false); Iterator contactMechIt = partyContactMechValueMaps.iterator(); while(contactMechIt.hasNext()) { contactMechGV = contactMechIt.next(); otherValues = PartyWorker.getPartyOtherValues(request, partyId, "party", "lookupPerson", "lookupGroup"); lookupPerson = otherValues.get("lookupPerson"); if(lookupPerson != null) { if(lookupPerson.get("firstName") != null) fullName += lookupPerson.get("firstName"); if(lookupPerson.get("middleName") != null) fullName +=" "+lookupPerson.get("middleName"); if(lookupPerson.get("lastName") != null) fullName +=" "+lookupPerson.get("lastName"); if(lookupPerson.get("suffix") != null) fullName +=" "+lookupPerson.get("suffix"); } else { fullName += " "; } contactMech1 = contactMechGV.get("contactMech"); if("POSTAL_ADDRESS".equals(contactMech1.getString("contactMechTypeId"))) { postalAddress = contactMechGV.get("postalAddress"); if( postalAddress.get("toName") != null) { toName += postalAddress.get("toName").replace(","," "); } if(postalAddress.get("attnName") != null) { attnName += " "+postalAddress.get("attnName").replace(","," "); } address1 +=" "+postalAddress.get("address1").replace(","," "); if(postalAddress.get("address2") != null) { address2 += " "+postalAddress.get("address2").replace(","," "); } city +=" "+postalAddress.get("city").replace(","," "); postalCode += " "+postalAddress.get("postalCode").replace(","," "); if(postalAddress.get("stateProvinceGeoId") != null) { state +=" "+postalAddress.getRelatedOneCache("StateProvinceGeo").get("abbreviation").replace(","," "); } if(postalAddress.get("countryGeoId") != null) { country +=" "+postalAddress.getRelatedOneCache("CountryGeo").get("geoName").replace(","," "); } } if("EMAIL_ADDRESS".equals(contactMech1.getString("contactMechTypeId"))) { email += contactMech1.getString("infoString")+"/"; } if("TELECOM_NUMBER".equals(contactMech1.getString("contactMechTypeId"))) { telecomNumber = contactMechGV.get("telecomNumber"); if(telecomNumber.get("areaCode") != null) phone += telecomNumber.get("areaCode").trim(); phone += telecomNumber.get("contactNumber").trim(); // if(telecomNumber.partyContactMech.get("extension") != null) // phone += telecomNumber.partyContactMech.get("extension"); } // print(" partyId "+partyId+" email "+email+" fullName "+fullName+" address "+address+" phone "+phone); } fw.append(partyId); fw.append(','); fw.append(toName); fw.append(','); fw.append(attnName); fw.append(','); fw.append(address1); fw.append(','); fw.append(address2); fw.append(','); fw.append(city); fw.append(','); fw.append(postalCode); fw.append(','); fw.append(state); fw.append(','); fw.append(country); fw.append(','); fw.append(fullName); fw.append('\n'); fw.flush(); // fw.close(); //response.sendRedirect("control/main"); } }