I wanted to export the list of articles and related data category in excel format, I have tried to export through knowledgeArticleVersion but unable to add data category column in the list. Could please help?
Here is my code of what I tried.
controller class:
public class contactquery{
public PageReference Export() {
return page.testExportexcel;
}
Public string Artdata;
public List<KnowledgeArticleVersion> cs{get; set;}
public contactquery()
{
List<KnowledgeArticleVersion> cs1 = new list<KnowledgeArticleVersion>();
cs = (KnowledgeArticleVersion [])database.query('Select id,ArticleNumber,ArticleType,FirstPublishedDate,Language,LastModifiedDate,LastPublishedDate,Title,urlname from KnowledgeArticleVersion where PublishStatus = \'Online\' and language = \'en_US\'');
for (KnowledgeArticleVersion c : cs)
{
System.debug(Artdata);
cs1.add(c);
}
}
}
VF page to display list of article:
<apex:page controller="contactquery" >
<apex:form >
<apex:pageBlock title="List of Published Articles" >
<div align="center">
<apex:commandButton action="{!Export}" value="Export"/>
</div>
<apex:pageBlockTable value="{!cs}" var="arti">
<apex:column value="{!arti.title}"/>
<apex:column value="{!arti.Urlname}"/>
<apex:column value="{!arti.ArticleNumber}"/>
<apex:column value="{!arti.ArticleType}"/>
<apex:column value="{!arti.FirstPublishedDate}"/>
<apex:column value="{!arti.Language}"/>
<apex:column value="{!arti.LastModifiedDate}"/>
<apex:column value="{!arti.LastPublishedDate}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
Vf page for export fuctionality:
<apex:page controller="contactquery" contentType="application/vnd.ms-excel#SalesForceExport.xls" cache="true">
<apex:pageBlock title="Export Results" >
<apex:pageBlockTable value="{!cs}" var="arti">
apex:column value="{!arti.title}"/>
<apex:column value="{!arti.Urlname}"/>
<apex:column value="{!arti.ArticleNumber}"/>
<apex:column value="{!arti.ArticleType}"/>
<apex:column value="{!arti.FirstPublishedDate}"/>
<apex:column value="{!arti.Language}"/>
<apex:column value="{!arti.LastModifiedDate}"/>
<apex:column value="{!arti.LastPublishedDate}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:page>