Fórum
excel sheet File Download in Liferay 6.x
ramveer singh narwariya, modificado 11 Anos atrás.
excel sheet File Download in Liferay 6.x
Junior Member Postagens: 64 Data de Entrada: 13/04/12 Postagens Recentes
We have a requirement that we need to export data of database table into excel sheet file and allow the client to download the excel sheet file.
We want it to display the a dialog box which asks the user to save or download.
Thanks in advance.
We want it to display the a dialog box which asks the user to save or download.
Thanks in advance.
Pankaj Kathiriya, modificado 11 Anos atrás.
RE: excel sheet File Download in Liferay 6.x
Liferay Master Postagens: 722 Data de Entrada: 05/08/10 Postagens Recentes
HI Ramveer,
You can utilize report portlet of Lifeary. You can get it installed from Plugin Installation.
Thanks,
Pankaj
You can utilize report portlet of Lifeary. You can get it installed from Plugin Installation.
Thanks,
Pankaj
Jitendra Rajput, modificado 11 Anos atrás.
RE: excel sheet File Download in Liferay 6.x
Liferay Master Postagens: 875 Data de Entrada: 07/01/11 Postagens Recentes
Try by using jasper report.
Hitoshi Ozawa, modificado 11 Anos atrás.
RE: excel sheet File Download in Liferay 6.x
Liferay Legend Postagens: 7942 Data de Entrada: 24/03/10 Postagens Recentes
Just use something like Apache POI
http://poi.apache.org/
http://poi.apache.org/
ramveer singh narwariya, modificado 11 Anos atrás.
RE: excel sheet File Download in Liferay 6.x
Junior Member Postagens: 64 Data de Entrada: 13/04/12 Postagens Recentes
thank you for reply
can any one send me code
can any one send me code
Jitendra Rajput, modificado 11 Anos atrás.
RE: excel sheet File Download in Liferay 6.x
Liferay Master Postagens: 875 Data de Entrada: 07/01/11 Postagens Recentes
There are so many example on internet do some googling . Any ways below is example code hope you will get some idea based on that .
public static void reportForEmployeeData(ResourceRequest request, ResourceResponse response,
List<employeedata> result, String path)
{
try
{
JRBeanCollectionDataSource resultList = new JRBeanCollectionDataSource(result);
JasperReport report = JasperCompileManager.compileReport(path);
JasperPrint print = JasperFillManager.fillReport(report, new HashMap<string, object>(), resultList);
OutputStream opStream = response.getPortletOutputStream();
JRXlsExporter exporterXLS = new JRXlsExporter();
exporterXLS.setParameter(JRXlsExporterParameter.JASPER_PRINT, print);
exporterXLS.setParameter(JRXlsExporterParameter.OUTPUT_STREAM, opStream);
exporterXLS.setParameter(JRXlsExporterParameter.IS_ONE_PAGE_PER_SHEET, Boolean.FALSE);
exporterXLS.setParameter(JRXlsExporterParameter.IS_DETECT_CELL_TYPE, Boolean.TRUE);
exporterXLS.setParameter(JRXlsExporterParameter.IS_WHITE_PAGE_BACKGROUND, Boolean.FALSE);
exporterXLS.setParameter(JRXlsExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS, Boolean.TRUE);
exporterXLS.exportReport();
// Prompt user to save the excel file
response.setContentType("application/x-excel");
// response.setProperty("Content-Disposition",
// "attachment; filename= " + print.getName() ".xls");
SimpleDateFormat timeStampFormat = new SimpleDateFormat(TIMESTAMP_FORMAT_FOR_XLS);
String timeStamp = timeStampFormat.format(Calendar.getInstance().getTime());
response.setProperty("Content-Disposition", "attachment; filename= " + TEST_FILE_XLS + timeStamp
+ ".xls");
} catch (JRException e)
{
LOGGER.error( e.getMessage(),e);
} catch (IOException e)
{
LOGGER.error( e.getMessage(),e);
}
}
</string,></employeedata>
ramveer singh narwariya, modificado 11 Anos atrás.
RE: excel sheet File Download in Liferay 6.x
Junior Member Postagens: 64 Data de Entrada: 13/04/12 Postagens Recentes
public void readExcel(ActionRequest request, ActionResponse response)
throws PortalException, SystemException, Throwable {
String filename="";
String searchText = "";
String filePath="C:\\folder\\myfile.xls";
if (request.getParameter("searchtxt") != null) {
searchText = request.getParameter("searchtxt").toString();
}
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection conn = null;
conn = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/lportal61rc1","root","root");
Statement stmt = conn.createStatement();
String strQuery = "select * from tcsnsn_TrainingRecord where eventId like '%"+ inputFile +"%'" ;
ResultSet rs = stmt.executeQuery(strQuery);
HSSFWorkbook hwb = new HSSFWorkbook();
HSSFSheet sheet = hwb.createSheet("new sheet");
HSSFRow rowhead = sheet.createRow((short) 2);
rowhead.createCell((short) 0).setCellValue("sno");
rowhead.createCell((short) 1).setCellValue("employeeID");
rowhead.createCell((short) 2).setCellValue("projectName");
rowhead.createCell((short) 3).setCellValue("employeeName");
rowhead.createCell((short) 4).setCellValue("designation");
rowhead.createCell((short) 5).setCellValue("hasAttended");
int index = 3;
int sno = 0;
String name = "";
while (rs.next()) {
sno++;
HSSFRow row = sheet.createRow((short) index);
row.createCell((short) 0).setCellValue(sno);
row.createCell((short) 1).setCellValue(rs.getString(10));
row.createCell((short) 2).setCellValue(rs.getString(7));
row.createCell((short) 3).setCellValue(rs.getString(11));
row.createCell((short) 4).setCellValue(rs.getString(8));
row.createCell((short) 5).setCellValue(rs.getString(4));
index++;
}
FileOutputStream fileOut = new FileOutputStream(filePath);
hwb.write(fileOut);
fileOut.close();
} catch (Exception ex) {
}
}
the above code are working fine that export the excel sheet in hard coded path but we do not want the hard code the path and aslo download the file at client machine from my website.
please you help me .
throws PortalException, SystemException, Throwable {
String filename="";
String searchText = "";
String filePath="C:\\folder\\myfile.xls";
if (request.getParameter("searchtxt") != null) {
searchText = request.getParameter("searchtxt").toString();
}
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection conn = null;
conn = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/lportal61rc1","root","root");
Statement stmt = conn.createStatement();
String strQuery = "select * from tcsnsn_TrainingRecord where eventId like '%"+ inputFile +"%'" ;
ResultSet rs = stmt.executeQuery(strQuery);
HSSFWorkbook hwb = new HSSFWorkbook();
HSSFSheet sheet = hwb.createSheet("new sheet");
HSSFRow rowhead = sheet.createRow((short) 2);
rowhead.createCell((short) 0).setCellValue("sno");
rowhead.createCell((short) 1).setCellValue("employeeID");
rowhead.createCell((short) 2).setCellValue("projectName");
rowhead.createCell((short) 3).setCellValue("employeeName");
rowhead.createCell((short) 4).setCellValue("designation");
rowhead.createCell((short) 5).setCellValue("hasAttended");
int index = 3;
int sno = 0;
String name = "";
while (rs.next()) {
sno++;
HSSFRow row = sheet.createRow((short) index);
row.createCell((short) 0).setCellValue(sno);
row.createCell((short) 1).setCellValue(rs.getString(10));
row.createCell((short) 2).setCellValue(rs.getString(7));
row.createCell((short) 3).setCellValue(rs.getString(11));
row.createCell((short) 4).setCellValue(rs.getString(8));
row.createCell((short) 5).setCellValue(rs.getString(4));
index++;
}
FileOutputStream fileOut = new FileOutputStream(filePath);
hwb.write(fileOut);
fileOut.close();
} catch (Exception ex) {
}
}
the above code are working fine that export the excel sheet in hard coded path but we do not want the hard code the path and aslo download the file at client machine from my website.
please you help me .
Vishal Panchal, modificado 11 Anos atrás.
RE: excel sheet File Download in Liferay 6.x
Expert Postagens: 289 Data de Entrada: 20/05/12 Postagens Recentes
Hi ramveer singh narwariya,
I did the same in one of my project , for the same requirement as you currently have.
I made a resourceURL rather than actionURL and it is working fine for me.
For that I did following steps,
1) URL on JSP page
<portlet:resourceURL id="<%=Constants.EXPORT_ACTION%>" var="exportURL" />
<a href="<%=exportURL%>"> Export </a>
2) URL Handler in controller
@ResourceMapping(value = Constants.EXPORT_ACTION)
public void exportAction(ResourceRequest resourceRequest, ResourceResponse resourceResponse) throws IOException {
ExportDataUtil.exportExcel(resourceRequest,resourceResponse);
}
3) ExportDataUtil.java
public static OutputStream exportReturnRequest(ResourceRequest resourceRequest,ResourceResponse response)
throws IOException {
//////////// Your code for export
response.setContentType("application/vnd.ms-excel");
response.setProperty("Content-Disposition", "attachment; filename=\""+ FILENAME + "\"");
workbook.write(out);
return out;
}
Now when you will click on export link from JSP it will give you an exported file by asking where to download / save , can be saved on client side.
Hope it will help you.!
Thanks&Regards,
Vishal R. Panchal
I did the same in one of my project , for the same requirement as you currently have.
I made a resourceURL rather than actionURL and it is working fine for me.
For that I did following steps,
1) URL on JSP page
<portlet:resourceURL id="<%=Constants.EXPORT_ACTION%>" var="exportURL" />
<a href="<%=exportURL%>"> Export </a>
2) URL Handler in controller
@ResourceMapping(value = Constants.EXPORT_ACTION)
public void exportAction(ResourceRequest resourceRequest, ResourceResponse resourceResponse) throws IOException {
ExportDataUtil.exportExcel(resourceRequest,resourceResponse);
}
3) ExportDataUtil.java
public static OutputStream exportReturnRequest(ResourceRequest resourceRequest,ResourceResponse response)
throws IOException {
//////////// Your code for export
response.setContentType("application/vnd.ms-excel");
response.setProperty("Content-Disposition", "attachment; filename=\""+ FILENAME + "\"");
workbook.write(out);
return out;
}
Now when you will click on export link from JSP it will give you an exported file by asking where to download / save , can be saved on client side.
Hope it will help you.!
Thanks&Regards,
Vishal R. Panchal
ramveer singh narwariya, modificado 11 Anos atrás.
RE: excel sheet File Download in Liferay 6.x
Junior Member Postagens: 64 Data de Entrada: 13/04/12 Postagens Recentes
thank you very much for reply
Vishal Panchal, modificado 11 Anos atrás.
RE: excel sheet File Download in Liferay 6.x
Expert Postagens: 289 Data de Entrada: 20/05/12 Postagens Recentesramveer singh narwariya:
thank you very much for reply
You are well come.
please share whether you got the downloadable excel sheet File ..?
if yes, than which changes you made.?
Thanks&Regards,
Vishal R. Panchal
ramveer singh narwariya, modificado 11 Anos atrás.
RE: excel sheet File Download in Liferay 6.x
Junior Member Postagens: 64 Data de Entrada: 13/04/12 Postagens RecentesVishal Panchal:
ramveer singh narwariya:thank you very much for reply
You are well come.
please share whether you got the downloadable excel sheet File ..?
if yes, than which changes you made.?
Thanks&Regards,
Vishal R. Panchal
yes i got it.
previously i was using actionURL that reason i was getting error but now am using ResourceURL and serveResource method.
me liferay, modificado 10 Anos atrás.
RE: excel sheet File Download in Liferay 6.x
Junior Member Postagens: 25 Data de Entrada: 14/12/11 Postagens Recentes
Hi Vishal,
I am having same requirement.
My question is it seems you were using spring mvc portlet but I am using simple Liferay MVC portlet so could you please tell me what are the changes required in your code to accomodate it in my portlet?
I am having same requirement.
My question is it seems you were using spring mvc portlet but I am using simple Liferay MVC portlet so could you please tell me what are the changes required in your code to accomodate it in my portlet?
Vishal Panchal, modificado 10 Anos atrás.
RE: excel sheet File Download in Liferay 6.x
Expert Postagens: 289 Data de Entrada: 20/05/12 Postagens Recentes
Hello,
If you are using Liferay MVC then it would be pretty simple.
Try below steps,
1. create resourceURL in jsp page
2. Create handler in your PortletAction class
3. Right your code
1) URL on JSP page
<portlet:resourceURL id="exportAction" var="exportURL" />
<a href="<%=exportURL%>"> Export Link</a>
2) URL Handler in PortletAction class
serveResource(ResourceRequest resourceRequest, ResourceResponse resourceResponse){
ExportDataUtil.exportExcel(resourceRequest,resourceResponse);
}
3) ExportDataUtil.java
public static OutputStream exportReturnRequest(ResourceRequest resourceRequest,ResourceResponse response)
throws IOException {
//////////// Your code for export
response.setContentType("application/vnd.ms-excel");
response.setProperty("Content-Disposition", "attachment; filename=\""+ FILENAME + "\"");
workbook.write(out);
return out;
}
please feel free to ask if you are still having problem with this.
Thanks,
Vishal
If you are using Liferay MVC then it would be pretty simple.
Try below steps,
1. create resourceURL in jsp page
2. Create handler in your PortletAction class
3. Right your code
1) URL on JSP page
<portlet:resourceURL id="exportAction" var="exportURL" />
<a href="<%=exportURL%>"> Export Link</a>
2) URL Handler in PortletAction class
serveResource(ResourceRequest resourceRequest, ResourceResponse resourceResponse){
ExportDataUtil.exportExcel(resourceRequest,resourceResponse);
}
3) ExportDataUtil.java
public static OutputStream exportReturnRequest(ResourceRequest resourceRequest,ResourceResponse response)
throws IOException {
//////////// Your code for export
response.setContentType("application/vnd.ms-excel");
response.setProperty("Content-Disposition", "attachment; filename=\""+ FILENAME + "\"");
workbook.write(out);
return out;
}
please feel free to ask if you are still having problem with this.
Thanks,
Vishal
me liferay, modificado 10 Anos atrás.
RE: excel sheet File Download in Liferay 6.x
Junior Member Postagens: 25 Data de Entrada: 14/12/11 Postagens Recentes
Thanks Vishal It is working now .
Now I am facing problem with aui date picker component if you get a chance please have a look.
http://stackoverflow.com/questions/18097726/date-is-not-showing-up-properly-in-liferay-portlet
Date field and date calender image both are not coming in single line
Now I am facing problem with aui date picker component if you get a chance please have a look.
http://stackoverflow.com/questions/18097726/date-is-not-showing-up-properly-in-liferay-portlet
Date field and date calender image both are not coming in single line
Adel Bayoudh, modificado 9 Anos atrás.
RE: excel sheet File Download in Liferay 6.x
Junior Member Postagens: 47 Data de Entrada: 05/08/14 Postagens Recentes
Hello,
I used the same approach, but the downloaded xls file is empty and it appears to me that the file type is different from xls.
I used this code:
in jsp file :
<portlet:resourceURL id="exportAction" var="exportURL" />
<a href="<%=exportURL%>"> Export Link</a>
in portlet class
public void serveResource(ResourceRequest resourceRequest, ResourceResponse resourceResponse)
{
ExportDataUtil.exportReturnRequest(resourceRequest,resourceResponse);
}
in ExportDataUtil class
public static OutputStream exportReturnRequest(ResourceRequest resourceRequest,ResourceResponse response)
throws IOException {
HSSFWorkbook hwb = new HSSFWorkbook();
HSSFSheet sheet = hwb.createSheet("new sheet");
HSSFRow rowhead = sheet.createRow((short) 2);
rowhead.createCell(0).setCellValue("Name");
rowhead.createCell(1).setCellValue("age");
rowhead.createCell(2).setCellValue("Tel");
rowhead.createCell(3).setCellValue("Email");
FileOutputStream out = new FileOutputStream("filename");
response.setContentType("application/vnd.ms-excel");
response.setProperty("Content-Disposition", "attachment; filename=\""+ "FILENAME" + "\"");
hwb.write(out);
System.out.println();
return out;
}
I used the same approach, but the downloaded xls file is empty and it appears to me that the file type is different from xls.
I used this code:
in jsp file :
<portlet:resourceURL id="exportAction" var="exportURL" />
<a href="<%=exportURL%>"> Export Link</a>
in portlet class
public void serveResource(ResourceRequest resourceRequest, ResourceResponse resourceResponse)
{
ExportDataUtil.exportReturnRequest(resourceRequest,resourceResponse);
}
in ExportDataUtil class
public static OutputStream exportReturnRequest(ResourceRequest resourceRequest,ResourceResponse response)
throws IOException {
HSSFWorkbook hwb = new HSSFWorkbook();
HSSFSheet sheet = hwb.createSheet("new sheet");
HSSFRow rowhead = sheet.createRow((short) 2);
rowhead.createCell(0).setCellValue("Name");
rowhead.createCell(1).setCellValue("age");
rowhead.createCell(2).setCellValue("Tel");
rowhead.createCell(3).setCellValue("Email");
FileOutputStream out = new FileOutputStream("filename");
response.setContentType("application/vnd.ms-excel");
response.setProperty("Content-Disposition", "attachment; filename=\""+ "FILENAME" + "\"");
hwb.write(out);
System.out.println();
return out;
}
ismail zabiulla s, modificado 9 Anos atrás.
RE: excel sheet File Download in Liferay 6.x
Junior Member Postagens: 70 Data de Entrada: 13/07/14 Postagens Recentes
Hi Adel Bayoudh,
hi find right approach below
/// this has to work
public void serveResource(ResourceRequest resourceRequest, ResourceResponse resourceResponse)
{
HSSFWorkbook workbook =ExportDataUtil.exportReturnRequest();
resourceResponse.setContentType("application/vnd.ms-excel");
resourceResponse.addProperty("Content-Disposition", "attachment; filename="+FILENAME);
// this will wirte to OutputStream
workbook.write(resourceResponse.getPortletOutputStream());
}
public static HSSFWorkbook exportReturnRequest()
{
HSSFWorkbook hwb = new HSSFWorkbook();
HSSFSheet sheet = hwb.createSheet("new sheet");
HSSFRow rowhead = sheet.createRow((short) 2);
rowhead.createCell(0).setCellValue("Name");
rowhead.createCell(1).setCellValue("age");
rowhead.createCell(2).setCellValue("Tel");
rowhead.createCell(3).setCellValue("Email");
return hwb;
}
hi find right approach below
Adel Bayoudh:
Hello,
I used the same approach, but the downloaded xls file is empty and it appears to me that the file type is different from xls.
I used this code:
in jsp file :
<portlet:resourceURL id="exportAction" var="exportURL" />
<a href="<%=exportURL%>"> Export Link</a>
in portlet class
public void serveResource(ResourceRequest resourceRequest, ResourceResponse resourceResponse)
{
ExportDataUtil.exportReturnRequest(resourceRequest,resourceResponse);
}
in ExportDataUtil class
public static OutputStream exportReturnRequest(ResourceRequest resourceRequest,ResourceResponse response)
throws IOException {
HSSFWorkbook hwb = new HSSFWorkbook();
HSSFSheet sheet = hwb.createSheet("new sheet");
HSSFRow rowhead = sheet.createRow((short) 2);
rowhead.createCell(0).setCellValue("Name");
rowhead.createCell(1).setCellValue("age");
rowhead.createCell(2).setCellValue("Tel");
rowhead.createCell(3).setCellValue("Email");
FileOutputStream out = new FileOutputStream("filename");
response.setContentType("application/vnd.ms-excel");
response.setProperty("Content-Disposition", "attachment; filename=\""+ "FILENAME" + "\"");
hwb.write(out);
System.out.println();
return out;
}
/// this has to work
public void serveResource(ResourceRequest resourceRequest, ResourceResponse resourceResponse)
{
HSSFWorkbook workbook =ExportDataUtil.exportReturnRequest();
resourceResponse.setContentType("application/vnd.ms-excel");
resourceResponse.addProperty("Content-Disposition", "attachment; filename="+FILENAME);
// this will wirte to OutputStream
workbook.write(resourceResponse.getPortletOutputStream());
}
public static HSSFWorkbook exportReturnRequest()
{
HSSFWorkbook hwb = new HSSFWorkbook();
HSSFSheet sheet = hwb.createSheet("new sheet");
HSSFRow rowhead = sheet.createRow((short) 2);
rowhead.createCell(0).setCellValue("Name");
rowhead.createCell(1).setCellValue("age");
rowhead.createCell(2).setCellValue("Tel");
rowhead.createCell(3).setCellValue("Email");
return hwb;
}
Adel Bayoudh, modificado 9 Anos atrás.
RE: excel sheet File Download in Liferay 6.x
Junior Member Postagens: 47 Data de Entrada: 05/08/14 Postagens Recentes
thank you
Manushi Jani, modificado 9 Anos atrás.
RE: excel sheet File Download in Liferay 6.x
New Member Postagens: 9 Data de Entrada: 13/02/15 Postagens Recentes
Thanks a lot, this works perfectly well.
Only thing is we need to explicit give the extension(i.e .xls) as a suffix with filename. Then only it will give proper file in excel format.
Only thing is we need to explicit give the extension(i.e .xls) as a suffix with filename. Then only it will give proper file in excel format.
Nikolaos Kroustalakis, modificado 4 Anos atrás.
RE: excel sheet File Download in Liferay 6.x
New Member Postagens: 14 Data de Entrada: 29/07/19 Postagens Recentesismail zabiulla:
Hi Adel Bayoudh,
hi find right approach belowAdel Bayoudh:Hello,
I used the same approach, but the downloaded xls file is empty and it appears to me that the file type is different from xls.
I used this code:
in jsp file :
<portlet:resourceURL id="exportAction" var="exportURL" />
<a href="<%=exportURL%>"> Export Link</a>
in portlet class
public void serveResource(ResourceRequest resourceRequest, ResourceResponse resourceResponse)
{
ExportDataUtil.exportReturnRequest(resourceRequest,resourceResponse);
}
in ExportDataUtil class
public static OutputStream exportReturnRequest(ResourceRequest resourceRequest,ResourceResponse response)
throws IOException {
HSSFWorkbook hwb = new HSSFWorkbook();
HSSFSheet sheet = hwb.createSheet("new sheet");
HSSFRow rowhead = sheet.createRow((short) 2);
rowhead.createCell(0).setCellValue("Name");
rowhead.createCell(1).setCellValue("age");
rowhead.createCell(2).setCellValue("Tel");
rowhead.createCell(3).setCellValue("Email");
FileOutputStream out = new FileOutputStream("filename");
response.setContentType("application/vnd.ms-excel");
response.setProperty("Content-Disposition", "attachment; filename=\""+ "FILENAME" + "\"");
hwb.write(out);
System.out.println();
return out;
}
/// this has to work
public void serveResource(ResourceRequest resourceRequest, ResourceResponse resourceResponse)
{
HSSFWorkbook workbook =ExportDataUtil.exportReturnRequest();
resourceResponse.setContentType("application/vnd.ms-excel");
resourceResponse.addProperty("Content-Disposition", "attachment; filename="+FILENAME);
// this will wirte to OutputStream
workbook.write(resourceResponse.getPortletOutputStream());
}
public static HSSFWorkbook exportReturnRequest()
{
HSSFWorkbook hwb = new HSSFWorkbook();
HSSFSheet sheet = hwb.createSheet("new sheet");
HSSFRow rowhead = sheet.createRow((short) 2);
rowhead.createCell(0).setCellValue("Name");
rowhead.createCell(1).setCellValue("age");
rowhead.createCell(2).setCellValue("Tel");
rowhead.createCell(3).setCellValue("Email");
return hwb;
}
Been a few years since the post, so i'm not sure if you remember anything about it. Just wanted to ask you something.
I wrote the code you suggest and all i'm getting is a blank page and nothing on the tomcat console. I already made a post here:
https://liferay.dev/forums/-/message_boards/message/118917108
So if you have any suggestions on the matter, i'd really appreciate it.
Thank you!
Chandan Sharma, modificado 9 Anos atrás.
RE: excel sheet File Download in Liferay 6.x
Junior Member Postagens: 54 Data de Entrada: 04/03/14 Postagens RecentesVishal Panchal:
please feel free to ask if you are still having problem with this.
Thanks,
Vishal
Hi Vishal,
I am also having similar kind of requirement, where I am using Apache POI API for generating excel file to download it. But my requirement is having one add-on constraint is:
I want to pass some data from my JSP to the controller class as parameter and from that I want to create downloadable file. The data which I am sending is getting generated dynamically based on different event that user does and it is huge in size also. So I can't pass this dynamic changing huge size data as a parameter to resourceURL.
So for I using AJAX request to do that. But the problem is that through AJAX request the generated file is not getting downloaded.
I will feel very happy, if someone will really help me to do that..
I already posted a question couple of week back but didn't got any reply. You can have a look on my code snippet from this link
I am eagerly waiting for response
Thanks in advance...
Manushi Jani, modificado 8 Anos atrás.
RE: excel sheet File Download in Liferay 6.x
New Member Postagens: 9 Data de Entrada: 13/02/15 Postagens Recentes
Hi Chandan,
Try passing the data through AJAX in JSON array.This may ease out the things.
Try passing the data through AJAX in JSON array.This may ease out the things.
Chandan Sharma, modificado 8 Anos atrás.
RE: excel sheet File Download in Liferay 6.x
Junior Member Postagens: 54 Data de Entrada: 04/03/14 Postagens RecentesManushi Jani:
Hi Chandan,
Try passing the data through AJAX in JSON array.This may ease out the things.
Getting the response in JSON format in my AJAX request will not give a download window to download the file. Can you please elaborate how to get download window for response which I am getting from AJAX
Razeena P, modificado 7 Anos atrás.
RE: excel sheet File Download in Liferay 6.x
New Member Postagens: 11 Data de Entrada: 08/08/16 Postagens Recentes
Hii vishal,
As you sid I used ResourceURl only and Im facing some issue.Please Help me.
Step1In view.jsp)
<portlet:resourceURL id="exportAction" var="exUrl">
<portlet:param name="cmd" value="excl"/>
</portlet:resourceURL>
Step2ReportGenerationAction.java)
public void serveResource(ResourceRequest request, ResourceResponse response) throws IOException{
String cmd = ParamUtil.getString(request, "cmd");
if(cmd.equalIgnoreCase("excl"){
HSSFWorkbook workbook =ExportDataUtil.exportReturnRequest(request, response);
response.setContentType("application/vnd.ms-excel");
response.addProperty("Content-Disposition", "inline; filename="+ "TrakcerReport.xls");
// this will wirte to OutputStream
workbook.write(response.getPortletOutputStream());
}}
Step3ExportDataUtil.java)
public class ExportDataUtil {
public static HSSFWorkbook exportReturnRequest(ResourceRequest request,ResourceResponse response) throws IOException{
HSSFWorkbook hwb = new HSSFWorkbook();
HSSFSheet sheet = hwb.createSheet("new sheet");
HSSFRow rowhead = sheet.createRow((short)0);
rowhead.createCell(0).setCellValue("Order Item Status");
rowhead.createCell(1).setCellValue("Name");
rowhead.createCell(2).setCellValue("Quantity");
rowhead.createCell(3).setCellValue("Price");
String orderItemIds = ParamUtil.getString(request, "orderItemIds");
if(Validator.isNotNull(orderItemIds)){
System.out.println("inside validator");
String[] splittedIds = StringUtils.split(orderItemIds, StringPool.COMMA);
try {
for(int i=0; i<splittedIds.length; i++){
System.out.println("inside for loop");
OrderItem orderItem = OrderItemLocalServiceUtil.getOrderItem(Long.parseLong(splittedIds));
int index = 3;
HSSFRow row = sheet.createRow((short) index);
row.createCell(0).setCellValue(orderItem.getOrderItemStatus());
row.createCell(1).setCellValue(orderItem.getName());
row.createCell(2).setCellValue(String.valueOf(orderItem.getQuantity()));
row.createCell(3).setCellValue(String.valueOf(orderItem.getPrice()));
row.createCell(4).setCellValue(orderItemIds);
index++;
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}}
return hwb;
}
}
Can u please help me to solve my issue its some what similar to uva issue only.
ThankYou in advance.
As you sid I used ResourceURl only and Im facing some issue.Please Help me.
Step1In view.jsp)
<portlet:resourceURL id="exportAction" var="exUrl">
<portlet:param name="cmd" value="excl"/>
</portlet:resourceURL>
Step2ReportGenerationAction.java)
public void serveResource(ResourceRequest request, ResourceResponse response) throws IOException{
String cmd = ParamUtil.getString(request, "cmd");
if(cmd.equalIgnoreCase("excl"){
HSSFWorkbook workbook =ExportDataUtil.exportReturnRequest(request, response);
response.setContentType("application/vnd.ms-excel");
response.addProperty("Content-Disposition", "inline; filename="+ "TrakcerReport.xls");
// this will wirte to OutputStream
workbook.write(response.getPortletOutputStream());
}}
Step3ExportDataUtil.java)
public class ExportDataUtil {
public static HSSFWorkbook exportReturnRequest(ResourceRequest request,ResourceResponse response) throws IOException{
HSSFWorkbook hwb = new HSSFWorkbook();
HSSFSheet sheet = hwb.createSheet("new sheet");
HSSFRow rowhead = sheet.createRow((short)0);
rowhead.createCell(0).setCellValue("Order Item Status");
rowhead.createCell(1).setCellValue("Name");
rowhead.createCell(2).setCellValue("Quantity");
rowhead.createCell(3).setCellValue("Price");
String orderItemIds = ParamUtil.getString(request, "orderItemIds");
if(Validator.isNotNull(orderItemIds)){
System.out.println("inside validator");
String[] splittedIds = StringUtils.split(orderItemIds, StringPool.COMMA);
try {
for(int i=0; i<splittedIds.length; i++){
System.out.println("inside for loop");
OrderItem orderItem = OrderItemLocalServiceUtil.getOrderItem(Long.parseLong(splittedIds));
int index = 3;
HSSFRow row = sheet.createRow((short) index);
row.createCell(0).setCellValue(orderItem.getOrderItemStatus());
row.createCell(1).setCellValue(orderItem.getName());
row.createCell(2).setCellValue(String.valueOf(orderItem.getQuantity()));
row.createCell(3).setCellValue(String.valueOf(orderItem.getPrice()));
row.createCell(4).setCellValue(orderItemIds);
index++;
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}}
return hwb;
}
}
Can u please help me to solve my issue its some what similar to uva issue only.
ThankYou in advance.
Gaurav Jain, modificado 11 Anos atrás.
RE: excel sheet File Download in Liferay 6.x
Regular Member Postagens: 145 Data de Entrada: 31/01/11 Postagens Recentes
You may also use liferay way for it. So using open office document conversion.
For this you need to install open office and enable liferay open office setting from Control Panel > Server Admin ? third party
Then you can use a utility com.liferay.portal.kernel.util.DocumentConversionUtil.convert(String id, InputStream inputStream, String sourceExtension, String targetExtension)
and you can pass sourceExtension as "html" and targetExtension as "xls"
For this you need to install open office and enable liferay open office setting from Control Panel > Server Admin ? third party
Then you can use a utility com.liferay.portal.kernel.util.DocumentConversionUtil.convert(String id, InputStream inputStream, String sourceExtension, String targetExtension)
and you can pass sourceExtension as "html" and targetExtension as "xls"
Raja Seth, modificado 9 Anos atrás.
RE: excel sheet File Download in Liferay 6.x
Regular Member Postagens: 233 Data de Entrada: 18/08/11 Postagens Recentes
Hi Ramveer,
Just check the Export User functionality in liferay-src ExportUsersAction.java. You might get an idea.
Regards,
Raja
Just check the Export User functionality in liferay-src ExportUsersAction.java. You might get an idea.
Regards,
Raja