Convert PDF to spreadsheets in C++
Export PDFs to XLSX, XLSM, CSV, ODS, or SpreadsheetML and configure worksheet and column options.
Configure the Aspose.PDF for C++ SDK before running these functions. Pass an existing input file and a writable destination path; create any required output directories first. Each function is an independent example, and its options do not carry over to other examples.
Convert PDF to XLSX
Select ExcelSaveOptions::ExcelFormat::XLSX.
- Open the input PDF as Document.
- Create ExcelSaveOptions.
- Set
FormattoExcelSaveOptions::ExcelFormat::XLSXin ExcelSaveOptions. - Save the result with Document::Save(), passing the output path and options.
#include <Aspose.PDF.Cpp/Document.h>
#include <Aspose.PDF.Cpp/ExcelSaveOptions.h>
namespace ConvertingExamples
{
using namespace System;
using namespace Aspose::Pdf;
void ConvertPdfToXlsx(String inputFile, String outputFile)
{
auto document = MakeObject<Document>(inputFile);
auto options = MakeObject<ExcelSaveOptions>();
options->set_Format(ExcelSaveOptions::ExcelFormat::XLSX);
document->Save(outputFile, options);
}
}
Insert a blank first column
Set InsertBlankColumnAtFirst to true for XLSX output.
- Open the input PDF as Document.
- Create ExcelSaveOptions.
- Set
FormattoExcelSaveOptions::ExcelFormat::XLSXin ExcelSaveOptions. - Set
InsertBlankColumnAtFirsttotruein ExcelSaveOptions. - Save the result with Document::Save(), passing the output path and options.
#include <Aspose.PDF.Cpp/Document.h>
#include <Aspose.PDF.Cpp/ExcelSaveOptions.h>
namespace ConvertingExamples
{
using namespace System;
using namespace Aspose::Pdf;
void ConvertPdfToXlsxWithBlankColumn(String inputFile, String outputFile)
{
auto document = MakeObject<Document>(inputFile);
auto options = MakeObject<ExcelSaveOptions>();
options->set_Format(ExcelSaveOptions::ExcelFormat::XLSX);
options->set_InsertBlankColumnAtFirst(true);
document->Save(outputFile, options);
}
}
Minimize the number of worksheets
Set MinimizeTheNumberOfWorksheets to true for XLSX output. The example requests fewer worksheets without manually merging worksheet content.
- Open the input PDF as Document.
- Create ExcelSaveOptions.
- Set
FormattoExcelSaveOptions::ExcelFormat::XLSXin ExcelSaveOptions. - Set
MinimizeTheNumberOfWorksheetstotruein ExcelSaveOptions. - Save the result with Document::Save(), passing the output path and options.
#include <Aspose.PDF.Cpp/Document.h>
#include <Aspose.PDF.Cpp/ExcelSaveOptions.h>
namespace ConvertingExamples
{
using namespace System;
using namespace Aspose::Pdf;
void ConvertPdfToXlsxSingleWorksheet(String inputFile, String outputFile)
{
auto document = MakeObject<Document>(inputFile);
auto options = MakeObject<ExcelSaveOptions>();
options->set_Format(ExcelSaveOptions::ExcelFormat::XLSX);
options->set_MinimizeTheNumberOfWorksheets(true);
document->Save(outputFile, options);
}
}
Convert PDF to XLSM
Select ExcelFormat::XLSM. This example does not add VBA macros.
- Open the input PDF as Document.
- Create ExcelSaveOptions.
- Set
FormattoExcelSaveOptions::ExcelFormat::XLSMin ExcelSaveOptions. - Save the result with Document::Save(), passing the output path and options.
#include <Aspose.PDF.Cpp/Document.h>
#include <Aspose.PDF.Cpp/ExcelSaveOptions.h>
namespace ConvertingExamples
{
using namespace System;
using namespace Aspose::Pdf;
void ConvertPdfToXlsm(String inputFile, String outputFile)
{
auto document = MakeObject<Document>(inputFile);
auto options = MakeObject<ExcelSaveOptions>();
options->set_Format(ExcelSaveOptions::ExcelFormat::XLSM);
document->Save(outputFile, options);
}
}
Convert PDF to CSV
Select ExcelFormat::CSV to save tabular output.
- Open the input PDF as Document.
- Create ExcelSaveOptions.
- Set
FormattoExcelSaveOptions::ExcelFormat::CSVin ExcelSaveOptions. - Save the result with Document::Save(), passing the output path and options.
#include <Aspose.PDF.Cpp/Document.h>
#include <Aspose.PDF.Cpp/ExcelSaveOptions.h>
namespace ConvertingExamples
{
using namespace System;
using namespace Aspose::Pdf;
void ConvertPdfToCsv(String inputFile, String outputFile)
{
auto document = MakeObject<Document>(inputFile);
auto options = MakeObject<ExcelSaveOptions>();
options->set_Format(ExcelSaveOptions::ExcelFormat::CSV);
document->Save(outputFile, options);
}
}
Convert PDF to ODS
Select ExcelFormat::ODS for OpenDocument spreadsheet output.
- Open the input PDF as Document.
- Create ExcelSaveOptions.
- Set
FormattoExcelSaveOptions::ExcelFormat::ODSin ExcelSaveOptions. - Save the result with Document::Save(), passing the output path and options.
#include <Aspose.PDF.Cpp/Document.h>
#include <Aspose.PDF.Cpp/ExcelSaveOptions.h>
namespace ConvertingExamples
{
using namespace System;
using namespace Aspose::Pdf;
void ConvertPdfToOds(String inputFile, String outputFile)
{
auto document = MakeObject<Document>(inputFile);
auto options = MakeObject<ExcelSaveOptions>();
options->set_Format(ExcelSaveOptions::ExcelFormat::ODS);
document->Save(outputFile, options);
}
}
Convert PDF to SpreadsheetML
Select ExcelFormat::XMLSpreadSheet2003 for the XML spreadsheet format.
- Open the input PDF as Document.
- Create ExcelSaveOptions.
- Set
FormattoExcelSaveOptions::ExcelFormat::XMLSpreadSheet2003in ExcelSaveOptions. - Save the result with Document::Save(), passing the output path and options.
#include <Aspose.PDF.Cpp/Document.h>
#include <Aspose.PDF.Cpp/ExcelSaveOptions.h>
namespace ConvertingExamples
{
using namespace System;
using namespace Aspose::Pdf;
void ConvertPdfToSpreadsheetMl(String inputFile, String outputFile)
{
auto document = MakeObject<Document>(inputFile);
auto options = MakeObject<ExcelSaveOptions>();
options->set_Format(ExcelSaveOptions::ExcelFormat::XMLSpreadSheet2003);
document->Save(outputFile, options);
}
}