PUB to Excel in C#

Microsoft Publisher files (PUB)1 are often used to design brochures, flyers, and newsletters. Sometimes you need to extract data or reorganize it into a spreadsheet for analysis or reporting. Although PUB is versatile, Excel2 is better for numerical data handling. This post shows how to convert PUB to Excel in C#. The code snippet lets you quickly transform Publisher documents into Excel spreadsheets.

Why Convert PUB to Excel?

Converting PUB files to Excel spreadsheets can be crucial for a variety of reasons:

  1. Data Analysis and Manipulation: PUB files often contain tables or structured data that may require further analysis, calculations, or formatting adjustments, which are better handled in Excel.

  2. Compatibility with Business Tools: Excel files integrate seamlessly with popular business tools such as ERP systems, financial applications, and database management tools.

  3. Enhanced Data Organization: Excel provides superior sorting, filtering, and visualization tools, making it easier to analyze the content extracted from PUB files.

  4. Collaboration and Accessibility: Sharing Excel files is more convenient in collaborative environments as Excel is a widely supported format across platforms and software.

By converting PUB to Excel, businesses and developers can unlock new opportunities for data utilization, ensuring better productivity and workflow efficiency.

PUB to Excel Conversion - C# API Installation

You can convert Publisher files by installing Conholdate.Total for .NET6. Run the NuGet command below in Visual Studio:

PM> NuGet\Install-Package Conholdate.Total

Convert PUB to Excel in C#

This guide shows how to initialize objects, convert PUB to PDF as an intermediate step, and then export to Excel.

Below is a step-by-step guide to convert PUB files to Excel using C#:

  • Initialize a MemoryStream: A MemoryStream object holds the intermediate PDF output in memory.

  • Load and Parse the PUB File: The PubFactory.CreateParser method loads the input PUB file. The Parse method converts it into an internal document object.

  • Convert PUB to PDF: Using the PubFactory.CreatePdfConverter method, the parsed PUB file is converted to PDF format and saved into the memory stream.

  • Load PDF and Export to Excel: The Document class loads the PDF from the memory stream. The ExcelSaveOptions class sets the output format to XLSX. Finally, the Excel file is saved to the specified output path.

Below is the code snippet for converting a Microsoft Publisher (PUB) file to an Excel spreadsheet using C#:

Get a Free License

You can request a free temporary license to evaluate the API to its full potential without any evaluation restrictions.

Summing up

Converting Publisher (PUB) files to Excel in C# is straightforward. Follow this guide to transform PUB files into Excel spreadsheets for easier data manipulation, sharing, and analysis. Whether you handle large PUB files or need a single conversion, this solution offers accuracy and ease of use. For questions, contact us on the forum.

See Also