Hi
I have exported the excel and save it in a folder.
Now i need to read the excel and save it as pdf format also.
Is there any way to achieve this.
thanks.
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Chandan Kr MadalPosted May 30, 2013, 5:48 AM
as well here are sample code:
------------.ASPX--------------
<%@ Page Title="" Language="C#" MasterPageFile="~/samplebrowser.master" AutoEventWireup="true" CodeFile="ExceltoPDF.aspx.cs" Inherits="Product_Showcase_ExceltoPDF_CS_ExceltoPDF" %>
<asp:Content ContentPlaceHolderID="Title" runat="server"> asp:Content> <asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="Server"> <div>
<table width="665px"> <tr> <td> <b>Select Documentb> <div>
<br style="line-height: 10px" /> div> <div>
<asp:FileUpload ID="FileUpload1" Width="385px" runat="server" /> div> <br />
<div>
<asp:Label Width="100%" Style="text-align: justify;" ID="label6" runat="server" Text="Clicking the button below will result in a PDF document being converted from Excel document using Essential XlsIO and Essential PDF. At the end of the document generation, an option will be provided to view the generated PDF file. Please note that you need to have a PDF viewer installed in order to view the generated PDF file.">asp:Label>
div>
<table width="100%" class="style1"> <br />
<tr> <td align="left"> <b>Pdf Page Setup Optionsb> td> tr>
<tr> <td align="left"> <asp:RadioButton ID="noScaleRadioBtn" GroupName="PageSetup" runat="server" Text="No Scaling" Checked="true" /> td>
<td align="left"> <asp:RadioButton ID="allRowsRadioBtn" GroupName="PageSetup" runat="server" Text="Fit All Rows On One Page" /> td> tr>
<tr> <td align="left"> <asp:RadioButton ID="allColumnRadioBtn" GroupName="PageSetup" runat="server" Text="Fit All Columns On One Page" /> td>
<td align="left"> <asp:RadioButton ID="onePageRadioBtn" GroupName="PageSetup" runat="server" Text="Fit Sheet On One Page" /> td> tr>
table>
<br /> <div>
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr> <td valign="middle" align="left">
<asp:CheckBox runat="server" ID="CheckBox1" Text=" Open File inside Browser" AutoPostBack="false" /> td>
<td align="right"> <asp:Button ID="btnExceltoPDf" Width="200px" runat="server" Text="Convert to PDF" OnClick="btnExceltoPDFClick" /> td>
tr> table>
div>
td> tr> table>
<div>
<asp:Label Width="100%" ForeColor="red" Style="text-align: justify;" ID="label1" runat="server" Text="">asp:Label> div>
div>
asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="SampleDescription" runat="server">
<p> Essential XlsIO allows to export the Excel document into PDF document. Use the Convert method of ExcelToPDFConverter class to convert the Excel files to PDF files and save the PDF document. This enabling user easily converts the Excel document to PDF document.p>
asp:Content>
-----------.CS--------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Syncfusion.XlsIO;
using Syncfusion.Pdf;
using Syncfusion.ExcelToPdfConverter;
public partial class Product_Showcase_ExceltoPDF_CS_ExceltoPDF : System.Web.UI.Page
{
#region Page Load
protected void Page_Load(object sender, EventArgs e)
{
}
#endregion
protected void btnExceltoPDFClick(object sender, EventArgs e)
{
if (this.FileUpload1.HasFile)
{
string ext = System.IO.Path.GetExtension(this.FileUpload1.PostedFile.FileName).ToLower();
if (ext == ".xls" || ext == ".xlsx")
{
//Convert the input Excel document to a PDF file
# region Convert Excel to PDF
Stream readFile = this.FileUpload1.PostedFile.InputStream;
try
{
ExcelToPdfConverter converter = null;
if (ext == ".xls")
converter = new ExcelToPdfConverter(readFile);
else
if (ext == ".xlsx")
converter = new ExcelToPdfConverter(readFile); //Intialize the PdfDocument Class
PdfDocument pdfDoc = new PdfDocument(); //Intialize the ExcelToPdfConverterSettings class
ExcelToPdfConverterSettings settings = new ExcelToPdfConverterSettings();
//Set the Layout Options for the output Pdf page.
if (noScaleRadioBtn.Checked)
settings.LayoutOptions = LayoutOptions.NoScaling;
else
if (allRowsRadioBtn.Checked)
settings.LayoutOptions = LayoutOptions.FitAllRowsOnOnePage;
else if (allColumnRadioBtn.Checked)
settings.LayoutOptions = LayoutOptions.FitAllColumnsOnOnePage;
else
settings.LayoutOptions = LayoutOptions.FitSheetOnOnePage;
//Assign the output PdfDocument to the TemplateDocument property of ExcelToPdfConverterSettings
settings.TemplateDocument = pdfDoc;
settings.DisplayGridLines = GridLinesDisplayStyle.Invisible;
//Convert the Excel document to PDf
pdfDoc = converter.Convert(settings);
if(CheckBox1.Checked)
pdfDoc.Save("ExceltoPDF.pdf", Response, HttpReadType.Open);
else
pdfDoc.Save("ExceltoPDF.pdf", Response, HttpReadType.Save);
readFile.Close();
this.label1.Text = "";
}
catch (Exception)
{
this.label1.Text = "The input document could not be processed, Could you please email the document to [email protected] for troubleshooting";
}
# endregion
}
else
{
this.label1.Text = "Please choose xls or xlsx file to convert to PDF";
}
}
else
{
this.label1.Text = "Browse a Excel document and then click the button to convert as a PDF document";
}
}
}