How to create an Excel file in managed C++ code using XlsIO
Syncfusion Excel (XlsIO) library is a .NET Excel library used to create, read, and edit Excel documents. Also, converts Excel documents to PDF files. Using this library, you can read, write and modify Excel documents in managed C++ code.
This article explains how to create an Excel files in a managed C++ project.
Steps to create an Excel document in managed C++:
Step 1: Create a new CLR Console Application project.
Create a new CLR console application
Step 2: Name the project.
Name the project
Step 3: Verify that the Common Language Runtime Support is activated. If you create a CLR project it is activated by default. Otherwise you must activate it manually.
Common Language Runtime Support
Step 4: Add the Syncfusion.XlsIO.Base and Syncfusion.Compression.Base assemblies into the project.
Step 5: Add the following namespaces in CLRSample.cpp file.
C++
using namespace Syncfusion::XlsIO; using namespace System;
Step 6: Add the following code snippet in main method of CLRSample.cpp to create an Excel document.
C++
//Initialize ExcelEngine ExcelEngine^ excelEngine = gcnew ExcelEngine(); //Initialize IApplication IApplication^ application = excelEngine->Excel; //Set the default application version application->DefaultVersion = ExcelVersion::Excel2013; //Create a new Excel workbook IWorkbook^ workbook = application->Workbooks->Create(1); //Get the first worksheet in the workbook into IWorksheet IWorksheet^ worksheet = workbook->Worksheets[0]; //Add some text in an Excel cell in the worksheet worksheet->Range["A1"]->Text = "Hello World"; //Save the workbook workbook->SaveAs("Output.xlsx"); //Open the saved workbook to view System::Diagnostics::Process::Start("Output.xlsx");
After adding the references and executing the sample, you will get the Excel file as follows.
Output Excel document
A sample with complete code snippet can be downloaded from Create Excel in managed c++.zip.
Take a moment to peruse the documentation, where you can find basic worksheet data manipulation options along with features like Conditional Formatting, worksheet calculations through Formulas, adding Charts in worksheet or workbook, organizing and analyzing data through Tables and Pivot Tables, appending multiple records to worksheet using Template Markers, and most importantly PDF and Image conversions etc. with code examples.
Click here to explore the rich set of Syncfusion Excel (XlsIO) library features.
See Also:
Create an Excel file in Windows Forms
Create an Excel file in ASP.NET Web Forms
Create an Excel file in ASP.NET MVC
Create an Excel file in ASP.NET Core
Create an Excel file in Xamarin
Starting with v16.2.0.x, if you reference Syncfusion assemblies from trial setup or from the NuGet feed, include a license key in your projects. Refer the link to learn about generating and registering Syncfusion license key in your application to use the components without trail message.
Conclusion
I hope you enjoyed learning how to create an Excel file in managed C++ code using XlsIO.
You can refer to our WinForms Excel feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our WinForms Excel example to understand how to create and manipulate data.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!