Help required in generating report in PDF format out of Excel

Hi,

I am new to Aspose.Net. I wanted some help on an issue that I am facing. We are trying to generate some reports in Excel and PDF format.We are generating report in PDF format out of Excel.

This is the relevant code:

if (outputFormat.Equals("PDF"))
{
workbookDesigner.Workbook.Save(reportName +
".pdf", FileFormatType.Pdf, SaveType.OpenInExcel, httpResponse);
}
else
{
workbookDesigner.Save(reportName +
".xls", SaveType.OpenInExcel, FileFormatType.Excel2003, httpResponse);
}

There is no issue for generating report in Excel format. However, I am facing an issue trying to generate it in PDF format.This is working only when we save into file system and it does not work when we save into stream like in example above.I do not want to save report into file system since we have limited file system access.

Complete code:

public class HttpResponseReportWriter : IReportWriter
{
#region
IReportWriter Members
public void WriteReport(object report, object output, string reportName, object reportParameters)
{
HttpResponse httpResponse;
WorkbookDesigner workbookDesigner;
IList reportParameterList;
String outputFormat = null;
if (output is HttpResponse)
{
httpResponse = output
as HttpResponse;
}
else
{
throw new Exception(output.GetType().Name + " is not compatible with HttpResponse.");
}
if (report is WorkbookDesigner)
{
workbookDesigner = report
as WorkbookDesigner;
}
else
{
throw new Exception(report.GetType().Name + " is not compatible with WorkbookDesigner.");
}
if (reportParameters is IList)
{
reportParameterList = reportParameters
as IList;
}
else
{
throw new Exception(reportParameters.GetType().Name + " is not compatible with Report Parameters.");
}
foreach (ReportParameter reportParameter in reportParameterList)
{
if (reportParameter.ReportParameterDefinition.ParamName.Equals("outputFormat"))
{
outputFormat = (
String) reportParameter.Value;
}
}
if (outputFormat == null)
{
throw new Exception(outputFormat + " output format is not supported. You have to use EXCEL ro PDF.");
}
if (outputFormat.Equals("PDF"))
{
workbookDesigner.Workbook.Save(reportName +
".pdf", FileFormatType.Pdf, SaveType.OpenInExcel, httpResponse);
}
else
{
workbookDesigner.Save(reportName +
".xls", SaveType.OpenInExcel, FileFormatType.Excel2003, httpResponse);
}
}
#endregion
}
}

Any help on this will be appreciated. Thanks in advance.

Regards,

Yamini

Hi,

Kindly use Response.End method after streaming and saving the pdf file using Response object

e.g

if (outputFormat.Equals(“PDF”))
{
workbookDesigner.Workbook.Save(reportName +
“.pdf”, SaveType.OpenInBrowser,
FileFormatType.Pdf, httpResponse);
httpResponse.End();

}
else
{
workbookDesigner.Save(reportName +
“.xls”, SaveType.OpenInExcel, FileFormatType.Excel2003, httpResponse);
}


Also, check the document for reference: http://www.aspose.com/documentation/.net-components/aspose.cells-for-.net/saving-files.html

Thank you.