cancel
Showing results for 
Search instead for 
Did you mean: 

export search result to excel

grg021
Champ in-the-making
Champ in-the-making
hi everyone,

I'm new to alfresco and would like to ask for help. I want to be able to export search results in the repository view or documents library view.

<em>SAMPLE USER CASE</em>
<ol>
<li>login to alfresco share</li>
<li>select a site</li>
<li>click on documents library</li>
<li>click on a category</li>
<li>export document list with the following column (document name, author, category)</li>
</ol>

I found a thread <a href="http://forums.alfresco.com/forum/developer-discussions/alfresco-share-development/how-send-webscript...">here</a> that discusses this however, I think its a solution by an expert and I couldn't quite follow how he did it.
Hope someone here can help.

Cheers!
6 REPLIES 6

mitpatoliya
Star Collaborator
Star Collaborator
You need to create webscript.
http://wiki.alfresco.com/wiki/Web_Scripts

First you need to familiar with that then you need to create webscript which fetches all the documents belongs to current site and generate response int the csv file.

then add button on the document library page which will invoke that script.

I know it would be difficult if you are newbie in alfresco but once you dig in to the code you will get to know the things gradually.

zladuric
Champ on-the-rise
Champ on-the-rise
Alfresco is almost ready to provide this for you. If you look at the search webscript, it has a JS controller (*.get.js, that does the actual search and filtering) and it has a JSON format template (*get.json.ftl, which formats the results in a JSON data).
What you need to do is:
1. Add a, ie, CSV formatter (*.get.csv.ftl) and have Freemarker render results in a CSV format for you.
It should be relatively easy even if you don't know alfresco (as long as you do have some programming experience), just copy/paste the json.ftl file and see how to format the data in a CSV format.
2. Add a button to the search page frontend that will repeat the same search but append a &format=csv to the search URL. That requires some client-side javascript handling, but it also should not be all that difficult.


Another way to do this would be to add some java-backed webscript and have java generate and return the CSV file for you. Or have the controller (js) create a file and provide a download link back to the frontend. But the one above seems the easiest one.

Ask more specific questions if you get stuck.

kranthi
Star Contributor
Star Contributor

Actually I am adding export button at out of box search page only there after getting results want to export that results to csv file.Here I can we perform that operation.In search-min.js only I wrote onclick event for export search button from here I struct how to do it.

ipierrot
Champ in-the-making
Champ in-the-making
Hi Zlatko, I have followed your advices, and I guess it is almost working. My problem is, I don't know what to do when my request come back. I thought it would open a pop-up to download the document, but instead nothing happens. I have created a search.get.csv.ftl, which is called, I have all my information back, when I inspect it with firebug, it is just there's no file.
I have added in my web-scripts-application-context.xml this lines in order to open the documents, but it doesn't seem to work.

<bean parent="webscripts.formatmap">
      <property name="formats">
            <props>
                 <prop key="csv">text/csv</prop>
            </props>
      </property>
   </bean>

So, if you have any idea of what could be wrong, it would be really nice of you to help me out. Still, your advices were really good, and I, maybe, can find the solution myself. If you need more information about my problem, ask me.

jlabuelo
Champ on-the-rise
Champ on-the-rise
Hi all

I am trying to do the same as you have explained here, however I am following the instructions of this site
https://sudheerreddyduganapalli.wordpress.com/2015/01/21/alfresco-share-export-to-excel-from-yui-dat...

Seems like an easy code to implement to get all the results with their property metadata exported to a CSV file. To do so, I have added this script code to a funcion in a js file that is now present in Alfresco. I have added the button in the "results" page of the advanced-search section…. but I am stucked as I do not know how to send the datatable of the results to the function.

here is the code where I add the button to the search.get.html.ftl


<div class="yui-u align-right">

     <span id="${el}-export-excel-button" class="yui-button yui-push-button exportToExcel-icon">

        <span class="first-child">

           <button type="button">${msg('button.exportToExcel')}</button>

        </span>

     </span>

</div>


However I have no idea how to call the funcion "exportToEXCEL(e, options)" from here.

Any ideas to help me solve this issue, or any post or documents that I can reference to better drive this objective?

Thanks a lot in advance!!

krutik_jayswal
Elite Collaborator
Elite Collaborator

You can export data into excel using apache poi api.Use this api with in webscript which extends AbstractWebscript class, with this you will be able to control the repsonse. Below link will help you in creating this stuff.

Alfresco Webscript : Export Data In Excel | Krutik Jayswal