{"id":823,"date":"2016-07-11T08:35:34","date_gmt":"2016-07-11T08:35:34","guid":{"rendered":"http:\/\/mindfusion.eu\/blog\/?p=823"},"modified":"2021-01-20T17:44:30","modified_gmt":"2021-01-20T17:44:30","slug":"mindfusion-spreadsheet-convert-xlsx-to-pdf-2","status":"publish","type":"post","link":"https:\/\/mindfusion.dev\/blog\/mindfusion-spreadsheet-convert-xlsx-to-pdf-2\/","title":{"rendered":"MindFusion WinForms Spreadsheet Control: Convert XLSX to PDF"},"content":{"rendered":"<p>This blog demonstrates how easily you can convert <a title=\"XLSX file format\" href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/dd922181(v=office.12).aspx\">XLSX<\/a> files to PDF using the <a title=\"Windows Forms\" href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/dd30h2yb(v=vs.110).aspx\">Windows Forms<\/a> Spreadsheet control.<\/p>\n<p><strong>Setup<\/strong><\/p>\n<p><a title=\"Create a New WinForms Application\" href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/dd492132.aspx\">Create a new WinForms application<\/a> and add the necessary assemblies to the project. Add a <a title=\"WinForms Spreadsheet Control: Workbook\" href=\"http:\/\/www.mindfusion.dev\/onlinehelp\/spreadsheetwinforms\/index.htm?T_MindFusion_Spreadsheet_WorkbookView.htm\">WorkbookView<\/a> control to the main application window. Note, that this is not necessary for the conversion &#8211; it is done only to display the original XLSX file.<\/p>\n<p><strong>Perform the conversion<\/strong><\/p>\n<p>Add a button to the main form, set its text to &#8216;Convert&#8230;&#8217; and handle its Click event. In the event handler display an OpenFileDialog to query the user for the input XLSX file, then display a SaveFileDialog to request the target PDF file. Once the two files are specified, proceed with the conversion by creating an <a href=\"http:\/\/www.mindfusion.dev\/onlinehelp\/spreadsheetwinforms\/index.htm?T_MindFusion_Spreadsheet_ExcelImporter.htm\">ExcelImporter<\/a> and <a href=\"http:\/\/www.mindfusion.dev\/onlinehelp\/spreadsheetwinforms\/index.htm?T_MindFusion_Spreadsheet_PdfExporter.htm\">PdfExporter<\/a> objects and using their <a href=\"http:\/\/www.mindfusion.dev\/onlinehelp\/spreadsheetwinforms\/index.htm?M_MindFusion_Spreadsheet_ExcelImporter_Import_2_String_Workbook.htm\">Import<\/a> and <a href=\"http:\/\/www.mindfusion.dev\/onlinehelp\/spreadsheetwinforms\/index.htm?M_MindFusion_Spreadsheet_PdfExporter_Export_2_String_Worksheet.htm\">Export<\/a> methods in succession:<\/p>\n<pre>\/\/ Import the data\nvar importer = new ExcelImporter();\nimporter.Import(xlsxPath, workbook1);\n\n\/\/ Export the worksheet as PDF\nvar exporter = new PdfExporter();\nexporter.EnableGridLines = true;\nexporter.Export(workbook1.Worksheets[0], pdfPath);\n\n\/\/ Open the PDF\nSystem.Diagnostics.Process.Start(pdfPath);<\/pre>\n<p>The <em>xlsxPath<\/em> and <em>pdfPath<\/em> variables identify the respective XLSX and PDF file names. The <em>workbook1<\/em> variable represents the Workbook displayed on the form. Once the conversion is complete, the PDF file is opened in the default PDF viewer by calling Process.Start.<\/p>\n<p>The following image illustrates the result:<\/p>\n<p><a href=\"http:\/\/mindfusion.dev\/blog\/wp-content\/uploads\/2016\/07\/Spreadsheet_WinForms_ConvertPdf.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-1602\" title=\"WinForms Spreadsheet Control: Convert to PDF\" src=\"http:\/\/mindfusion.dev\/blog\/wp-content\/uploads\/2016\/07\/Spreadsheet_WinForms_ConvertPdf-300x251.png\" width=\"300\" height=\"251\" srcset=\"https:\/\/mindfusion.dev\/blog\/wp-content\/uploads\/2016\/07\/Spreadsheet_WinForms_ConvertPdf-300x251.png 300w, https:\/\/mindfusion.dev\/blog\/wp-content\/uploads\/2016\/07\/Spreadsheet_WinForms_ConvertPdf-768x643.png 768w, https:\/\/mindfusion.dev\/blog\/wp-content\/uploads\/2016\/07\/Spreadsheet_WinForms_ConvertPdf-1024x857.png 1024w, https:\/\/mindfusion.dev\/blog\/wp-content\/uploads\/2016\/07\/Spreadsheet_WinForms_ConvertPdf-358x300.png 358w, https:\/\/mindfusion.dev\/blog\/wp-content\/uploads\/2016\/07\/Spreadsheet_WinForms_ConvertPdf.png 1239w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>The source code of the project together with all necessary libraries can be downloaded from here:<\/p>\n<p><a title=\"WinForms Spreadsheet Control: Convert XLSX to PDF\" href=\"https:\/\/mindfusion.dev\/_samples\/SpreadsheetConvertPdf.zip\">Convert .XLSX to .PDF Files Using the WinForms Spreadsheet Control: Download Sample<\/a><\/p>\n<p>You are welcome to ask any questions about the <a href=\"http:\/\/www.mindfusion.dev\/onlinehelp\/spreadsheetwinforms\/index.htm?T_MindFusion_Spreadsheet_WorkbookView.htm\">WorkbookView<\/a> control at MindFusion <a href=\"http:\/\/mindfusion.dev\/Forum\/YaBB.pl?board=ss_disc\">discussion board<\/a> or per e-mail at <a href=\"mailto:support@mindfusion.dev\">support@mindfusion.dev<\/a>.<\/p>\n<p>Click here <a href=\"http:\/\/mindfusion.dev\/spreadsheet-winforms.html\">here<\/a> to visit the official page of the MindFusion WinForms Spreadsheet control.<\/p>\n<p>We hope you find this tutorial useful and thank you for your interest in MindFusion developer tools.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This blog demonstrates how easily you can convert XLSX files to PDF using the Windows Forms Spreadsheet control. Setup Create a new WinForms application and add the necessary assemblies to the project. Add a WorkbookView control to the main application &hellip; <a href=\"https:\/\/mindfusion.dev\/blog\/mindfusion-spreadsheet-convert-xlsx-to-pdf-2\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false},"version":2}},"categories":[74,163],"tags":[221,165,30,164,166,192,172],"class_list":["post-823","post","type-post","status-publish","format-standard","hentry","category-sample-code","category-spreadsheet","tag-convert","tag-excel","tag-pdf","tag-spreadsheet-2","tag-workbook","tag-worksheet","tag-xlsx"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p3RlKs-dh","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/mindfusion.dev\/blog\/wp-json\/wp\/v2\/posts\/823","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mindfusion.dev\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mindfusion.dev\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mindfusion.dev\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/mindfusion.dev\/blog\/wp-json\/wp\/v2\/comments?post=823"}],"version-history":[{"count":6,"href":"https:\/\/mindfusion.dev\/blog\/wp-json\/wp\/v2\/posts\/823\/revisions"}],"predecessor-version":[{"id":2597,"href":"https:\/\/mindfusion.dev\/blog\/wp-json\/wp\/v2\/posts\/823\/revisions\/2597"}],"wp:attachment":[{"href":"https:\/\/mindfusion.dev\/blog\/wp-json\/wp\/v2\/media?parent=823"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mindfusion.dev\/blog\/wp-json\/wp\/v2\/categories?post=823"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mindfusion.dev\/blog\/wp-json\/wp\/v2\/tags?post=823"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}