Knowledgebase (2300)
PDF files are great for delivering documents in a standard format that looks exactly the same no matter what device or software you use to view them, but they are difficult to edit. If you have a spreadsheet in PDF format, usually the easiest way to work with the data is to convert the PDF to Excel and edit it there. In this article, you will learn how to convert PDF to Excel in C++ using Spire.PDF for C++.
Install Spire.PDF for C++
There are two ways to integrate Spire.PDF for C++ into your application. One way is to install it through NuGet, and the other way is to download the package from our website and copy the libraries into your program. Installation via NuGet is simpler and more recommended. You can find more details by visiting the following link.
Integrate Spire.PDF for C++ in a C++ Application
Convert PDF to Excel in C++
Spire.PDF for C++ offers the PdfDocument->SaveToFile() method to convert PDF documents to other file formats including XLSX. Before converting, you can set the conversion options by using PdfDocument->GetConvertOptions->SetPdfToXlsxOptions() method. This method takes the XlsxLineLayoutOptions object as a parameter, and the constructor of the XlsxLineLayoutOptions class has the following five parameters, enabling you to control how PDF will be converted to Excel.
- bool convertToMultipleSheet: Indicates whether each page of the PDF will be converted to a worksheet in Excel.
- bool rotatedText: Indicates whether to show rotated text.
- bool splitCell: Indicates whether a PDF table cell containing text spanning several lines will be split into multiple rows in Excel.
- bool wrapText: Indicates whether to wrap text in an Excel cell.
- bool overlapText: Indicates whether to display overlapping text.
- C++
#include "Spire.Pdf.o.h";
using namespace Spire::Pdf;
int main() {
//Create a PdfDcoument object
PdfDocument* doc = new PdfDocument();
//Load a PDF document
doc->LoadFromFile(L"C:\\Users\\Administrator\\Desktop\\Business sales invoice.pdf");
//Create a XlsxLineLayoutOptions object
XlsxLineLayoutOptions* options = new XlsxLineLayoutOptions(true, true, false, true, false);
//Set PDF to XLSX convert options
doc->GetConvertOptions()->SetPdfToXlsxOptions(options);
//Save the PDF document to Excel
doc->SaveToFile(L"output/PdfToExcel.xlsx", FileFormat::XLSX);
doc->Close();
delete doc;
}

Apply for a Temporary License
If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.
Grouping rows and columns in Excel is a valuable feature that can simplify working with large or complex datasets. This feature enables you to hide or show individual sections of data for better viewing and analysis. For instance, if you have a worksheet with data for various regions or departments, you can group the rows for each region or department together. Once grouped, you can collapse or expand each group as required, which makes it easier for you to focus on specific parts of the data while keeping the rest of the worksheet unaffected. In this article, you will learn how to group or ungroup rows and columns, along with how to expand or collapse groups in Excel in C++ using Spire.XLS for C++.
- Group Rows and Columns in Excel in C++
- Ungroup Rows and Columns in Excel in C++
- Expand or Collapse Groups in Excel in C++
Install Spire.XLS for C++
There are two ways to integrate Spire.XLS for C++ into your application. One way is to install it through NuGet, and the other way is to download the packageThere are two ways to integrate Spire.XLS for C++ into your application. One way is to install it through NuGet, and the other way is to download the package from our website and copy the libraries into your program. Installation via NuGet is simpler and more recommended. You can find more details by visiting the following link.from our website and copy the libraries into your program. Installation via NuGet is simpler and more recommended. You can find more details by visiting the following link.
Integrate Spire.XLS for C++ in a C++ Application
Group Rows and Columns in Excel in C++
The XlsWorksheet->GroupByRows(int firstRow, int lastRow, bool isCollapsed) and XlsWorksheet->GroupByColumns (int firstColumn, int lastColumn, bool isCollapsed) methods in Spire.XLS for C++ can be used to group specific rows and columns in an Excel worksheet. The detailed steps are as follows:
- Initialize an instance of the Workbook class.
- Load an Excel file using the Workbook->LoadFromFile(LPCWSTR_S fileName) method.
- Get a specific worksheet by its index using the Workbook->GetWorksheets()->Get(int index) method.
- Group specific rows in the worksheet using the XlsWorksheet->GroupByRows(int firstRow, int lastRow, bool isCollapsed) method.
- Group specific columns in the worksheet using the XlsWorksheet->GroupByColumns (int firstColumn, int lastColumn, bool isCollapsed) method.
- Save the result file using the Workbook->SaveToFile (LPCWSTR_S fileName, ExcelVersion version) method.
- C++
#include "Spire.Xls.o.h";
using namespace Spire::Xls;
int main()
{
//Initialize an instance of the Workbook class
Workbook* workbook = new Workbook();
//Load an Excel file
workbook->LoadFromFile(L"Sample.xlsx");
//Get the first worksheet
Worksheet* sheet = workbook->GetWorksheets()->Get(0);
//Group the 2nd, 3rd, 4th, 5th and 6th rows
sheet->GroupByRows(2, 6, false);
//Group the 3rd and 4th columns
sheet->GroupByColumns(3, 4, false);
//Save the result file
workbook->SaveToFile(L"GroupRowsAndColumns.xlsx", ExcelVersion::Version2013);
workbook->Dispose();
delete workbook;
}

Ungroup Rows and Columns in Excel in C++
By ungrouping rows and columns, you can restore each cell to its initial, standalone state, helping you view the data as it was originally presented.
Spire.XLS for C++ offers the XlsWorksheet->UngroupByRows(int firstRow, int lastRow) and XlsWorksheet->UngroupByColumns (int firstColumn, int lastColumn) methods to help you ungroup rows and columns. The detailed steps are as follows:
- Initialize an instance of the Workbook class.
- Load an Excel file using the Workbook->LoadFromFile(LPCWSTR_S fileName) method.
- Get a specific worksheet by its index using the Workbook->GetWorksheets()->Get(int index) method.
- Ungroup specific rows in the worksheet using the XlsWorksheet->UngroupByRows(int firstRow, int lastRow) method.
- Ungroup specific columns in the worksheet using the XlsWorksheet->UngroupByColumns (int firstColumn, int lastColumn) method.
- Save the result file using the Workbook->SaveToFile (LPCWSTR_S fileName, ExcelVersion version) method.
- C++
#include "Spire.Xls.o.h";
using namespace Spire::Xls;
int main()
{
//Initialize an instance of the Workbook class
Workbook* workbook = new Workbook();
//Load an Excel file
workbook->LoadFromFile(L" GroupRowsAndColumns.xlsx");
//Get the first worksheet
Worksheet* sheet = workbook->GetWorksheets()->Get(0);
//Ungroup the 2nd, 3rd, 4th, 5th and 6th rows
sheet->UngroupByRows(2, 6);
//Ungroup the 3rd and 4th columns
sheet->UngroupByColumns(3, 4);
//Save the result file
workbook->SaveToFile(L"UngroupRowsAndColumns.xlsx", ExcelVersion::Version2013);
workbook->Dispose();
delete workbook;
}

Expand or Collapse Groups in Excel in C++
When grouping rows or columns in Excel, you can click the expand (+) or collapse (-) button to show or hide the grouped data. In Spire.XLS for C++, you can use the Worksheet->GetRange(LPCWSTR_S name)->ExpandGroup(GroupByType groupBy) method or the Worksheet->GetRange(LPCWSTR_S name)->CollapseGroup(GroupByType groupBy) method to achieve the same expanding or collapsing effect. The detailed steps are as follows:
- Initialize an instance of the Workbook class.
- Load an Excel file using the Workbook->LoadFromFile(LPCWSTR_S fileName) method.
- Get a specific worksheet by its index using the Workbook->GetWorksheets()->Get(int index) method.
- Expand a specific group using the Worksheet->GetRange(LPCWSTR_S name)->ExpandGroup(GroupByType groupBy) method.
- Collapse a specific group using the Worksheet->GetRange(LPCWSTR_S name)->CollapseGroup(GroupByType groupBy) method.
- Save the result file using the Workbook->SaveToFile (LPCWSTR_S fileName, ExcelVersion version) method.
- C++
#include "Spire.Xls.o.h";
using namespace Spire::Xls;
int main()
{
//Initialize an instance of the Workbook class
Workbook* workbook = new Workbook();
//Load an Excel file
workbook->LoadFromFile(L"Input.xlsx");
//Get the first worksheet
Worksheet* sheet = workbook->GetWorksheets()->Get(0);
//Expand a group
sheet->GetRange(L"A2:E6")->ExpandGroup(GroupByType::ByRows);
//Collapse a group
sheet->GetRange(L"C1:D11")->CollapseGroup(GroupByType::ByColumns);
//Save the result file
workbook->SaveToFile(L"ExpandOrCollapseGroups.xlsx", ExcelVersion::Version2013);
workbook->Dispose();
delete workbook;
}

Apply for a Temporary License
If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.
Comparison of two versions of a document is the process of checking the new version against the previous one to identify changes made by different contributors. By comparing documents, legal staffs can easily review contracts to determine what changes have been made or still need to be made, and teachers can quickly compare student papers to determine whether or not necessary changes have been applied. In this article, you will learn how to compare two Word documents in C++ using Spire.Doc for C++.
The following is a screenshot of the two Word documents we’re going to compare.

Install Spire.Doc for C++
There are two ways to integrate Spire.Doc for C++ into your application. One way is to install it through NuGet, and the other way is to download the package from our website and copy the libraries into your program. Installation via NuGet is simpler and more recommended. You can find more details by visiting the following link.
Integrate Spire.Doc for C++ in a C++ Application
Compare Two Word Documents in C++
Spire.Doc for C++ allows to compare two Word documents and save the result in a third document. When opening this document with MS Word, you can see all changes that have been made to the original document, including insertions, deletions as well as formatting modifications. The following are the detailed steps.
- Load two Word documents separately while initialing two different Document objects.
- Compare these two documents using Document->Compare() method.
- Save the result in a third Word document using Document->SaveToFile() method.
- C++
#include "Spire.Doc.o.h"
using namespace Spire::Doc;
int main() {
//Load the first document
Document* doc1 = new Document(L"C:\\Users\\Administrator\\Desktop\\Original.docx");
//Load the second document
Document* doc2 = new Document(L"C:\\Users\\Administrator\\Desktop\\Revised.docx");
//Compare the second document on the basis of the first document
doc1->Compare(doc2, L"Patrick");
//Save to a docx file
doc1->SaveToFile(L"output/Result.docx", Spire::Doc::FileFormat::Docx2013);
doc1->Close();
doc2->Close();
delete doc1;
delete doc2;
}

Apply for a Temporary License
If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.