January 2nd, 2008, 08:33 PM
VB.NET : Convert .xls to .pdf
I want to convert excel file to pdf in my system using vb.net and i'm felt disappointed because I couldn't found any solution or guide for this problem. Most of the solution given is I need to use third party installer.
So, i had tried this code that is used to convert .txt to pdf. However, the result is messy.
I really hope that anyone could help me.
Partial Class pdf
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
'Try 'try statement
Dim document As New Document()
PdfWriter.getInstance(document, New FileStream("C:\MyTemplate.pdf", FileMode.Create))
' Dim oFile As System.IO.File
Dim oRead As System.IO.StreamReader
oRead = IO.File.OpenText("C:\MyTemplate.xls")
While (oRead.Peek <> -1)
document = Nothing
'Catch ex As Exception
Thanks in advance.
January 2nd, 2008, 09:25 PM
yes you will pretty much need to use a third party installer. You could potentially do it using open office, but with .NET you need something third party, or you need to develop it from scratch using the PDF xml.
February 2nd, 2009, 08:42 AM
it is possible with Java:
import officetools.OfficeFile; // available at dancrintea.ro/doc-to-pdf/
FileInputStream fis = new FileInputStream(new File("test.doc")); // works with xls also
FileOutputStream fos = new FileOutputStream(new File("test.pdf"));
OfficeFile f = new OfficeFile(fis,"localhost","8100", true);
All possible conversions:
doc --> pdf, html, txt, rtf
xls --> pdf, html, csv
ppt --> pdf, swf
html --> pdf
February 22nd, 2009, 04:19 AM
Convert .xls to .pdf
I am quiet new to .net. i have used the code provided by you in one of my project, but the same is giving me some error. I am using Microsoft Visual studio 2008 Express addition. Can please guide me the exact steps in Visual studio to make this code working. If you possible give me a example.
Thanks for your help in advance.
March 10th, 2009, 03:37 AM
If you're developing from scratch, you can try iTextSharp http://itextsharp.sourceforge.net/
another quick thought is get our xls data and place them in crystal reports, then export as pdf...
March 11th, 2009, 04:01 AM
Thanks a lot dear, i really appreciate you for this response but as i have been working on Visual Basic 6.0 for a long time, Visual Basic 2008 is quiet new for me. Is it possible for you to provide me with a sample code for Visual basic 2008 where i can select a excel file and convert it into pdf format.
Thanks for your help in advance.
November 12th, 2009, 04:40 AM
Convert .xls to .pdf in VB.Net
There is a special .Net library to convert .xls to .pdf in VB.Net and C#, it names Excel to PDF .Net.
You asked about sample for VS2008/VB, for example, if you want to convert file to file:
This is code to convert Excel workbook to PDF in memory:
Dim xtp As New SautinSoft.XlsToPdf
Dim result As Integer = xtp.ConvertFile(xlsFile, pdfFile)
If result = 0 Then
Dim xtp As New SautinSoft.XlsToPdf
Dim xlsBytes() As Byte = Nothing
Dim pdfBytes() As Byte = Nothing
Dim result As Integer = xtp.ConvertBytes(xlsBytes, pdfBytes)
April 12th, 2011, 06:39 AM
Try to use UseOffice. Net library.
UseOffice .Net is a robust .Net component to convert between DOC, DOCX, XLS, RTF, PPT, PDF and HTML formats with tables, images, fonts, colors etc.
This component is just a class library, it requires Microsoft Office installed.
//Convert DOC file to PDF in .Net
SautinSoft.UseOffice u = new SautinSoft.UseOffice();
u.ConvertFile(@"d:\Word.doc", @"d:\Result.pdf", SautinSoft.UseOffice.eDirection.DOC_to_PDF);
October 22nd, 2011, 02:36 AM
I meet same problem, I use Spire.XLS to convert xls to pdf, aslo, xlsx support yet.
November 4th, 2011, 06:30 AM
I have used the code provided by you in one of my project, but the same is giving me some error. I am using Microsoft Visual studio 2008 Express addition.
November 4th, 2011, 10:56 AM
This is one of the most peculair posts I've ever seen.
You want to convert xls to pdf in VB.Net yet you post a java code snippet?!
March 6th, 2012, 02:23 AM
The above code is from an article in C-sharpcorner.
Private Function Convert(ByVal sourcePath As String, ByVal targetPath As String, ByVal targetType As XlFixedFormatType) As Boolean
Dim result As Boolean
Dim missing As Object = Type.Missing
Dim application As ApplicationClass = Nothing
Dim workBook As Workbook = Nothing
application = New ApplicationClass()
Dim target As Object = targetPath
Dim type As Object = targetType
workBook = application.Workbooks.Open(sourcePath, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing)
workBook.ExportAsFixedFormat(targetType, target, XlFixedFormatQuality.xlQualityStandard, True, False, missing, missing, missing, missing)
result = True
result = False
If workBook IsNot Nothing Then
workBook.Close(True, missing, missing)
workBook = Nothing
If application IsNot Nothing Then
application = Nothing
Please click here:http://www.c-sharpcorner.com/uploadfile/d2dcfc/methods-for-converting-office-documents-to-pdf-or-xps-with-C-Sharp/ to get details.
September 19th, 2013, 03:38 AM
Try this code in C# and VB.NET
I have found the code to convert xls or xlsx file to pdf in c# and vb.net from Aspose.Cells for .Net technical section and it works fine.
/// Use Aspose.Cells to perform the task
/// The main entry point for the application.
static void Main(string args)
// Uncomment the code below when you have purchased
// license for Aspose.Cells. You need to
// deploy the license in the same folder as your
// executable, alternatively you can add the license
// file as an embedded resource to your project.
// // Set license for Aspose.Cells
// Aspose.Cells.LicensecellsLicense = new
//Get the path of the Application folder.
string path = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(Application.ExecutablePath), "..\\..");
//Get the template excel file path.
stringdesignerFile = path + @"\Files\PurchasingReport.xls";
//Specify the pdf file path.
stringpdfFile = path + @"\Files\PurchasingReport.pdf";
//Create a new Workbook.
//Open the template excel file which you have to
Aspose.Cells.Workbookwb = new Aspose.Cells.Workbook(designerFile);
//Save the pdf file.
catch (Exception e)
'Use Aspose.Cells to perform the task
' Uncomment the code below when you have purchased license
' forAspose.Cells. You need to deploy the
' license in the same folder as your executable, alternatively
' you can add the license file as an embedded resource to your
' ' Set license for Aspose.Cells
' DimcellsLicense As Aspose.Cells.License = New
'Get the path of the Application folder.
Dim path As String = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(Application.ExecutablePath), "..\")
'Get the template excel file path.
Dim designerFile As String = path + "\Files\PurchasingReport.xls"
'Specify the pdf file path.
Dim pdfFile As String = path + "\Files\PurchasingReport.pdf"
'Create a new Workbook.
'Open the template excel file which you have to convert
Dim wb As Aspose.Cells.Workbook = New Aspose.Cells.Workbook(designerFile)
'Save the pdf file.
Catch e As Exception
September 24th, 2013, 07:43 AM
Use Online Software for Convert .xls to .pdf
October 2nd, 2013, 10:49 AM
Hey im also looking to convert but this wont work can someone help?