function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Marcelo AgostinhoMarcelo Agostinho 

How can i export XLS using Apex Class?

Hello Guys... im here again to ask about exporting XLS.

 

For example i want to run a method that is associated to a commandButtom...

 

when i click in this commandButtom... this method is called and they will return the datas ready to export to a XLS file...

 

Can i do something like it?

kritinkritin

write the values in text file as comma separated and save it locally with .csv exetnsion.

kritinkritin

either you can use and call javascript function:"

<html>
<head>
<script language="javascript">
function WriteToFile()
{
var fso = new ActiveXObject("Scripting.FileSystemObject");
var s = fso.CreateTextFile("C:\\Test.txt", true);
s.WriteLine('Hello');
s.Close();
}
</script>
</head>
<body onLoad="WriteToFile()">

</body>
</html>
kritinkritin
public PageReference export(){ String recStr = 'FirstName,'; recStr += 'Lastname' ; recStr += '\n' ; recStr +='RObin,'; recStr += 'Dicosta' ; recStr += '\n' ; Blob recBlob= Blob.valueOf(recStr); Attachment att= new attachment(); att.Name = 'MYExport ' + system.now() + '.csv'; att.Body =recBlob; insert att; PageReference exportPage = new ApexPages.StandardController(att).view(); exportPage.setRedirect(true); return exportPage; }