HTML JPG PDF XML XLSX
  Product Family
DOCX

Create DOCX File in C++

Native and high performance DOCX file creation programmatically without Micorsoft Office using C++ library.

Create DOCX File Using C++

How to create DOCX file? With Aspose.Cells for C++ library, you can easily Create DOCX file programmatically with a few lines of code. Aspose.Cells for C++ is capable of building cross-platform applications with the ability to generate, modify, convert, render and print all Excel files. C++ Excel API not only convert between spreadsheet formats, it can also render Excel files as images, PDF, HTML, ODS, CSV, SVG, JSON, WORD, PPT and more, thus making it a perfect choice to exchange documents in industry-standard formats. You can download its latest version directly, just open NuGet package manager, search for Aspose.Cells.Cpp and install. You may also use the following command from the Package Manager Console.

Command


PM> Install-Package Aspose.Cells.Cpp

How to Create DOCX in C++

It is easy for the developers to create, load, modify and convert DOCX files within running reporting applications for data processing in just few lines of code.

  1. Create an object of the IWorkbook class.
  2. Get the first sheet into an IWorksheet object.
  3. Use IWorksheet->GetICells() method to get the cells of the worksheet into an ICells object.
  4. Use ICells->GetObjectByIndex() method to access the desired cell of the worksheet into an ICell object.
  5. Use ICell->PutValue() method to input value into the cell.
  6. Save the workbook as .docx file using Save() method.
 

Sample code shows how to create DOCX file in C++.


// Create an object of the IWorkbook class.
intrusive_ptr<IWorkbook> wkb = Factory::CreateIWorkbook();

// Get the first sheet into an IWorksheet object.
intrusive_ptr<IWorksheetCollection> wsc = wkb->GetIWorksheets();
intrusive_ptr<IWorksheet> ws = wsc->GetObjectByIndex(0);

// Use IWorksheet->GetICells() method to get the cells of the worksheet into an ICells object.
intrusive_ptr<ICells> cells = ws->GetICells();

// Use ICells->GetObjectByIndex() method to access the desired cell of the worksheet into an ICell object.
intrusive_ptr<ICell> cell00 = cells->GetObjectByIndex(0, 0);
intrusive_ptr<ICell> cell01 = cells->GetObjectByIndex(0, 1);
intrusive_ptr<ICell> cell10 = cells->GetObjectByIndex(1, 0);
intrusive_ptr<ICell> cell11 = cells->GetObjectByIndex(1, 1);

// Use ICell->PutValue() method to input value into the cell.
cell00->PutValue(new String("ColumnA"));
cell01->PutValue(new String("ColumnB"));
cell10->PutValue(new String("ValueA"));
cell11->PutValue(new String("ValueB"));

// Save workbook to resultFile folder
wkb->Save(new String("created_one.docx"));
 

C++ library to create DOCX file

There are three options to install “Aspose.Cells for C++” onto your system. Please choose one that resembles your needs and follow the step-by-step instructions:

  1. Install a NuGet Package . See Documentation
  2. Install the library using Include and lib Folders. See Documentation
  3. Install Aspose.Cells for C++ in Linux. See Documentation

System Requirements

Before running the C++ conversion sample source code, make sure that you have the following prerequisites.

  • Microsoft Windows or a compatible OS with C++ Runtime Environment for Windows 32 bit, Windows 64 bit and Linux 64 bit.
  • Add reference to the Aspose.Cells for C++ DLL in your project.

DOCX What is DOCX File Format?

DOCX is a well-known format for Microsoft Word documents. Introduced from 2007 with the release of Microsoft Office 2007, the structure of this new Document format was changed from plain binary to a combination of XML and binary files. Docx files can be opened with Word 2007 and lateral versions but not with the earlier versions of MS Word which support DOC file extensions.

Read More

Other Supported Sheets Generation

You can also create other Microsoft Excel files including few listed below.

XLS (Microsoft Excel Spreadsheet (Legacy))
XLSX (Open XML Workbook)
XLSB (Excel Binary Workbook)
XLSM (Macro-enabled Spreadsheet)
XLT (Excel 97 - 2003 Template)
XLTX (Excel Template)
XLTM (Excel Macro-Enabled Template)
CSV (Comma Separated Values)
TSV (Tab Separated Values)
ODS (OpenDocument Spreadsheet)
PDF (Portable Document Format)
HTML (Hyper Text Markup Language)