### Configure Different Page Setup for Document Sections Source: https://github.com/eiceblue/spire.doc-for-c/blob/main/C++ Examples/doc_c.md Shows how to configure different page setups for document sections using Spire.Doc C++ API. This example demonstrates changing the page orientation and size for a specific section. ```cpp //Create a Word document intrusive_ptr doc = new Document(); //Get the second section intrusive_ptr
SectionTwo = doc->GetSections()->GetItemInSectionCollection(1); //Set the orientation SectionTwo->GetPageSetup()->SetOrientation(PageOrientation::Landscape); //Set page size //SectionTwo.PageSetup.PageSize = new SizeF(800, 800); ``` -------------------------------- ### Insert and Format Footnote Source: https://github.com/eiceblue/spire.doc-for-c/blob/main/C++ Examples/doc_c.md Demonstrates how to find a string, get its text range, append a footnote, format the footnote text, and format the footnote marker. ```cpp intrusive_ptr selection = document->FindString(L"Spire.Doc", false, true); intrusive_ptr textRange = selection->GetAsOneRange(); intrusive_ptr paragraph = textRange->GetOwnerParagraph(); int index = paragraph->GetChildObjects()->IndexOf(textRange); intrusive_ptr footnote = paragraph->AppendFootnote(FootnoteType::Footnote); paragraph->GetChildObjects()->Insert(index + 1, footnote); textRange = footnote->GetTextBody()->AddParagraph()->AppendText(L"Welcome to evaluate Spire.Doc"); textRange->GetCharacterFormat()->SetFontName(L"Arial Black"); textRange->GetCharacterFormat()->SetFontSize(10); textRange->GetCharacterFormat()->SetTextColor(Color::GetDarkGray()); footnote->GetMarkerCharacterFormat()->SetFontName(L"Calibri"); footnote->GetMarkerCharacterFormat()->SetFontSize(12); footnote->GetMarkerCharacterFormat()->SetBold(true); footnote->GetMarkerCharacterFormat()->SetTextColor(Color::GetDarkGreen()); ``` -------------------------------- ### Modify Page Setup of Sections (C++) Source: https://github.com/eiceblue/spire.doc-for-c/blob/main/C++ Examples/doc_c.md Demonstrates how to modify the margins and page size of sections in a Word document using Spire.Doc for C++. ```cpp //Loop through all sections for (int i = 0; i < doc->GetSections()->GetCount(); i++) { intrusive_ptr
section = doc->GetSections()->GetItemInSectionCollection(i); //Modify the margins section->GetPageSetup()->SetMargins(new MarginsF(100, 80, 100, 80)); //Modify the page size section->GetPageSetup()->SetPageSize(PageSize::Letter()); } ``` -------------------------------- ### C++ Spire.Doc: Create Hello World Document Source: https://github.com/eiceblue/spire.doc-for-c/blob/main/C++ Examples/doc_c.md Demonstrates the creation of a simple Word document with 'Hello World!' text using the Spire.Doc C++ library. It involves creating a document, adding a section, a paragraph, and appending the text. ```cpp //Create word document intrusive_ptr document = new Document(); //Create a new section intrusive_ptr
section = document->AddSection(); //Create a new paragraph intrusive_ptr paragraph = section->AddParagraph(); //Append Text paragraph->AppendText(L"Hello World!"); ``` -------------------------------- ### Retrieve Document Variables Source: https://github.com/eiceblue/spire.doc-for-c/blob/main/C++ Examples/doc_c.md Provides examples for retrieving document variables by their index and name using Spire.Doc C++ API. It shows how to get the name and value of a variable. ```cpp //Retrieve name of the variable by index. std::wstring s1 = document->GetVariables()->GetNameByIndex(0); //Retrieve value of the variable by index. std::wstring s2 = document->GetVariables()->GetValueByIndex(0); //Retrieve the value of the variable by name. std::wstring s3 = document->GetVariables()->GetItem(L"A1"); ``` -------------------------------- ### Get Field Text from Document Source: https://github.com/eiceblue/spire.doc-for-c/blob/main/C++ Examples/doc_c.md Shows how to retrieve all fields within a Word document and extract the text content of each field. ```cpp //Open a Word document intrusive_ptr document = new Document(); //Get all fields in document intrusive_ptr fields = document->GetFields(); for (int i = 0; i < fields->GetCount(); i++) { intrusive_ptr field = fields->GetItem(i); //Get field text std::wstring fieldText = field->GetFieldText(); } ``` -------------------------------- ### Create a Simple Hello World Document Source: https://github.com/eiceblue/spire.doc-for-c/blob/main/C++ Examples/doc_c.md This C++ code snippet demonstrates the basic usage of Spire.Doc to create a new Word document, add a section, and append a 'Hello World!' text to a paragraph. ```cpp using namespace Spire::Doc; //Create word document intrusive_ptr document = new Document(); //Create a new section intrusive_ptr
section = document->AddSection(); //Create a new paragraph intrusive_ptr paragraph = section->AddParagraph(); //Append Text paragraph->AppendText(L"Hello World!"); ``` -------------------------------- ### Get Collection of Form Fields Source: https://github.com/eiceblue/spire.doc-for-c/blob/main/C++ Examples/doc_c.md Demonstrates how to load a Word document and retrieve the collection of all form fields within the first section. ```cpp //Open a Word document intrusive_ptr document = new Document(); document->LoadFromFile(inputFile.c_str()); //Get the first section intrusive_ptr
section = document->GetSections()->GetItemInSectionCollection(0); intrusive_ptr formFields = section->GetBody()->GetFormFields(); ``` -------------------------------- ### Insert Table into Textbox and Set Style Source: https://github.com/eiceblue/spire.doc-for-c/blob/main/C++ Examples/doc_c.md Demonstrates how to create a document, add a textbox, insert a table into the textbox, specify table dimensions, and apply a style. This involves creating document elements, positioning the textbox, and formatting the table. ```cpp intrusive_ptr doc = new Document(); //Add a section intrusive_ptr
section = doc->AddSection(); //Add a paragraph to the section intrusive_ptr paragraph = section->AddParagraph(); //Add a textbox to the paragraph intrusive_ptr textbox = paragraph->AppendTextBox(300, 100); //Set the position of the textbox textbox->GetFormat()->SetHorizontalOrigin(HorizontalOrigin::Page); textbox->GetFormat()->SetHorizontalPosition(140); textbox->GetFormat()->SetVerticalOrigin(VerticalOrigin::Page); textbox->GetFormat()->SetVerticalPosition(50); //Add text to the textbox intrusive_ptr textboxParagraph = textbox->GetBody()->AddParagraph(); intrusive_ptr textboxRange = textboxParagraph->AppendText(L"Table 1"); textboxRange->GetCharacterFormat()->SetFontName(L"Arial"); //Insert table to the textbox intrusive_ptr table = textbox->GetBody()->AddTable(true); //Specify the number of rows and columns of the table table->ResetCells(4, 4); //Apply style to the table table->ApplyStyle(DefaultTableStyle::TableColorful2); ``` -------------------------------- ### Extract Paragraph Content to Table Source: https://github.com/eiceblue/spire.doc-for-c/blob/main/C++ Examples/doc_c.md This C++ function, ExtractByTable, extracts content from a source document starting from a specified paragraph and up to a given table. It identifies the table, determines its index in the document body, and then clones and adds the document objects from the starting paragraph up to the table's position into a destination document. ```cpp void ExtractByTable(intrusive_ptr sourceDocument, intrusive_ptr destinationDocument, int startPara, int tableNo) { //Get the table from the source document intrusive_ptr
table = Object::Dynamic_cast
(sourceDocument->GetSections()->GetItemInSectionCollection(0)->GetTables()->GetItemInTableCollection(tableNo - 1)); //Get the table index int index = sourceDocument->GetSections()->GetItemInSectionCollection(0)->GetBody()->GetChildObjects()->IndexOf(table); for (int i = startPara - 1; i <= index; i++) { //Clone the ChildObjects of source document intrusive_ptr doobj = sourceDocument->GetSections()->GetItemInSectionCollection(0)->GetBody()->GetChildObjects()->GetItem(i)->Clone(); //Add to destination document destinationDocument->GetSections()->GetItemInSectionCollection(0)->GetBody()->GetChildObjects()->Add(doobj); } } ``` -------------------------------- ### Load and Save Document to Disk Source: https://github.com/eiceblue/spire.doc-for-c/blob/main/C++ Examples/doc_c.md Demonstrates loading a document from a file path and saving it to disk in a specified format. ```cpp using namespace Spire::Doc; int main() { // Create a new document intrusive_ptr doc = new Document(); // Load the document from the absolute/relative path on disk. doc->LoadFromFile(L"Template.docx"); // Save the document to disk doc->SaveToFile(L"LoadAndSaveToDisk.docx", FileFormat::Docx); doc->Close(); } ``` -------------------------------- ### Create and Format Hyperlinks in Document Source: https://github.com/eiceblue/spire.doc-for-c/blob/main/C++ Examples/doc_c.md Demonstrates how to create hyperlinks in a document, append them to paragraphs, and format their appearance including font, size, color, and underline style using Spire.Doc for C++. ```cpp //Load Document intrusive_ptr doc = new Document(); doc->LoadFromFile(inputFile.c_str()); intrusive_ptr
section = doc->GetSections()->GetItemInSectionCollection(0); //Add a paragraph and append a hyperlink to the paragraph intrusive_ptr para1 = section->AddParagraph(); para1->AppendText(L"Regular Link: "); //Format the hyperlink with default color and underline style intrusive_ptr txtRange1 = para1->AppendHyperlink(L"www.e-iceblue.com", L"www.e-iceblue.com", HyperlinkType::WebLink); txtRange1->GetCharacterFormat()->SetFontName(L"Times New Roman"); txtRange1->GetCharacterFormat()->SetFontSize(12); intrusive_ptr blankPara1 = section->AddParagraph(); //Add a paragraph and append a hyperlink to the paragraph intrusive_ptr para2 = section->AddParagraph(); para2->AppendText(L"Change Color: "); //Format the hyperlink with red color and underline style intrusive_ptr txtRange2 = para2->AppendHyperlink(L"www.e-iceblue.com", L"www.e-iceblue.com", HyperlinkType::WebLink); txtRange2->GetCharacterFormat()->SetFontName(L"Times New Roman"); txtRange2->GetCharacterFormat()->SetFontSize(12); txtRange2->GetCharacterFormat()->SetTextColor(Color::GetRed()); intrusive_ptr blankPara2 = section->AddParagraph(); //Add a paragraph and append a hyperlink to the paragraph intrusive_ptr para3 = section->AddParagraph(); para3->AppendText(L"Remove Underline: "); //Format the hyperlink with red color and no underline style intrusive_ptr txtRange3 = para3->AppendHyperlink(L"www.e-iceblue.com", L"www.e-iceblue.com", HyperlinkType::WebLink); txtRange3->GetCharacterFormat()->SetFontName(L"Times New Roman"); txtRange3->GetCharacterFormat()->SetFontSize(12); txtRange3->GetCharacterFormat()->SetUnderlineStyle(UnderlineStyle::None); ``` -------------------------------- ### Insert Document Content at Bookmark Location Source: https://github.com/eiceblue/spire.doc-for-c/blob/main/C++ Examples/doc_c.md This example illustrates how to insert the content of one document into another at a specific bookmark's location. It involves navigating to the bookmark, identifying its start position within a paragraph, and then inserting paragraphs from the second document into the first document's body at the calculated index. ```cpp //Create the first document intrusive_ptr document1 = new Document(); //Create the second document intrusive_ptr document2 = new Document(); //Get the first section of the first document intrusive_ptr
section1 = document1->GetSections()->GetItemInSectionCollection(0); //Locate the bookmark intrusive_ptr bn = new BookmarksNavigator(document1); //Find bookmark by name bn->MoveToBookmark(L"Test", true, true); //Get bookmarkStart intrusive_ptr start = bn->GetCurrentBookmark()->GetBookmarkStart(); //Get the owner paragraph intrusive_ptr para = start->GetOwnerParagraph(); //Get the para index int index = section1->GetBody()->GetChildObjects()->IndexOf(para); //Insert the paragraphs of document2 for (int i = 0; i < document2->GetSections()->GetCount(); i++) { intrusive_ptr
section2 = document2->GetSections()->GetItemInSectionCollection(i); for (int j = 0; j < section2->GetParagraphs()->GetCount(); j++) { intrusive_ptr paragraph = section2->GetParagraphs()->GetItemInParagraphCollection(j); section1->GetBody()->GetChildObjects()->Insert(index + 1, Object::Dynamic_cast(paragraph->Clone())); } } ``` -------------------------------- ### Apply Multiple Styles in a Paragraph Source: https://github.com/eiceblue/spire.doc-for-c/blob/main/C++ Examples/doc_c.md Demonstrates how to create a Word document, add a section and paragraph, and then append text ranges with different character formatting, including font name, size, color, bold, and underline. ```cpp //Create a Word document intrusive_ptr doc = new Document(); //Add a section intrusive_ptr
section = doc->AddSection(); //Add a paragraph intrusive_ptr para = section->AddParagraph(); //Add a text range 1 and set its style intrusive_ptr range = para->AppendText(L"Spire.Doc for .NET "); range->GetCharacterFormat()->SetFontName(L"Calibri"); range->GetCharacterFormat()->SetFontSize(16.0f); range->GetCharacterFormat()->SetTextColor(Color::GetBlue()); range->GetCharacterFormat()->SetBold(true); range->GetCharacterFormat()->SetUnderlineStyle(UnderlineStyle::Single); //Add a text range 2 and set its style range = para->AppendText(L"is a professional Word .NET library"); range->GetCharacterFormat()->SetFontName(L"Calibri"); range->GetCharacterFormat()->SetFontSize(15.0f); ``` -------------------------------- ### Load Document from Stream and Save to Stream Source: https://github.com/eiceblue/spire.doc-for-c/blob/main/C++ Examples/doc_c.md Shows how to load a document from an input stream and save it to an output stream in a different format. ```cpp // Open the stream. Read only access is enough to load a document. intrusive_ptr stream = new Stream(inputFile.c_str()); // Load the entire document into memory. intrusive_ptr doc = new Document(stream); // You can close the stream now, it is no longer needed because the document is in memory. stream->Close(); // Do something with the document // Convert the document to a different format and save to stream. intrusive_ptr newStream = new Stream(); doc->SaveToStream(newStream, FileFormat::Rtf); newStream->Save(outputFile.c_str()); doc->Close(); ``` -------------------------------- ### Compare Two Documents Source: https://github.com/eiceblue/spire.doc-for-c/blob/main/C++ Examples/doc_c.md Loads two documents and compares them. The comparison can include options to ignore formatting. ```cpp //Load the first document intrusive_ptr doc1 = new Document(); doc1->LoadFromFile(inputFile_1.c_str()); //Load the second document intrusive_ptr doc2 = new Document(); doc2->LoadFromFile(inputFile_2.c_str()); //Compare the two documents doc1->Compare(doc2, L"E-iceblue"); ``` ```cpp intrusive_ptr doc1 = new Document(); intrusive_ptr doc2 = new Document(); CompareOptions* compareOptions = new CompareOptions(); compareOptions->SetIgnoreFormatting(true); doc1->Compare(doc2, L"E-iceblue", DateTime::GetNow(), compareOptions); ``` -------------------------------- ### XMLAttribute Name and Value Retrieval Source: https://github.com/eiceblue/spire.doc-for-c/blob/main/C++ Examples/doc_c.md Provides methods to get the name and value of an XML attribute. These are fundamental for accessing attribute data within an XML element. ```C++ const char* XMLAttribute::Name() const { return _name.GetStr(); } const char* XMLAttribute::Value() const { return _value.GetStr(); } ``` -------------------------------- ### Load and Save Word Document with Macros Source: https://github.com/eiceblue/spire.doc-for-c/blob/main/C++ Examples/doc_c.md Demonstrates loading a Word document with macros (.docm) and saving it. ```cpp using namespace Spire::Doc; //Create a new document intrusive_ptr document = new Document(); //Loading document with macros document->LoadFromFile(inputFile.c_str(), FileFormat::Docm); //Save docm file document->SaveToFile(outputFile.c_str(), FileFormat::Docm); document->Close(); ``` -------------------------------- ### Get Document Variables Source: https://github.com/eiceblue/spire.doc-for-c/blob/main/C++ Examples/doc_c.md This C++ code demonstrates how to load a Word document, iterate through all its document variables, and retrieve their names and values, formatting them into a readable string. ```cpp intrusive_ptr document = new Document(); //Load the file from disk. document->LoadFromFile(inputFile.c_str()); std::wstring stringBuilder; stringBuilder.append(L"This document has following variables:\n"); int variablesCount = document->GetVariables()->GetCount(); for (int i = 0; i < variablesCount; i++) { std::wstring name = document->GetVariables()->GetNameByIndex(i); std::wstring value = document->GetVariables()->GetValueByIndex(i); stringBuilder.append(L"Name: " + name + L", " + L"Value: " + value); stringBuilder.append(L"\n"); } ``` -------------------------------- ### AutoFit Table to Window Source: https://github.com/eiceblue/spire.doc-for-c/blob/main/C++ Examples/doc_c.md Demonstrates how to make a table automatically adjust its width to fit the window in Spire.Doc C++. This is achieved by using the `AutoFitToWindow` behavior. ```cpp intrusive_ptr
section = document->GetSections()->GetItemInSectionCollection(0); intrusive_ptr
table = Object::Dynamic_cast
(section->GetTables()->GetItemInTableCollection(0)); //Automatically fit the table to the active window width table->AutoFit(AutoFitBehaviorType::AutoFitToWindow); ``` -------------------------------- ### Manage Paragraph Pagination Source: https://github.com/eiceblue/spire.doc-for-c/blob/main/C++ Examples/doc_c.md Illustrates how to control the pagination of a specific paragraph within a Word document by setting the Format.PageBreakBefore property to true, ensuring it starts on a new page. ```cpp //Get the first section and the paragraph we want to manage the pagination. intrusive_ptr
sec = document->GetSections()->GetItemInSectionCollection(0); intrusive_ptr para = sec->GetParagraphs()->GetItemInParagraphCollection(4); //Set the pagination format as Format.PageBreakBefore for the checked paragraph. para->GetFormat()->SetPageBreakBefore(true); ``` -------------------------------- ### C++ XML Element Name Operations Source: https://github.com/eiceblue/spire.doc-for-c/blob/main/C++ Examples/doc_c.md Provides methods to get and set the name of an XML element. The SetName method includes an option to manage memory for the string. ```C++ const char* Name() const { return Value(); } void SetName( const char* str, bool staticMem=false ) { SetValue( str, staticMem ); } ``` -------------------------------- ### Create Catalog with Heading Styles and List Formatting Source: https://github.com/eiceblue/spire.doc-for-c/blob/main/C++ Examples/doc_c.md Provides C++ code to create a document catalog using Spire.Doc. It includes adding headings with different built-in styles (Heading1, Heading2, Heading3) and applying custom numbered list formatting to them. ```cpp //Create Word document. intrusive_ptr document = new Document(); //Add a new section. intrusive_ptr
section = document->AddSection(); intrusive_ptr paragraph = section->GetParagraphs()->GetCount() > 0 ? section->GetParagraphs()->GetItemInParagraphCollection(0) : section->AddParagraph(); //Add Heading 1. paragraph = section->AddParagraph(); paragraph->AppendText(L"Heading1"); paragraph->ApplyStyle(BuiltinStyle::Heading1); paragraph->GetListFormat()->ApplyNumberedStyle(); //Add Heading 2. paragraph = section->AddParagraph(); paragraph->AppendText(L"Heading2"); paragraph->ApplyStyle(BuiltinStyle::Heading2); //List style for Headings 2. intrusive_ptr listSty2 = new ListStyle(document, ListType::Numbered); for (int i = 0; i < listSty2->GetLevels()->GetCount(); i++) { intrusive_ptr listLev = listSty2->GetLevels()->GetItem(i); listLev->SetUsePrevLevelPattern(true); listLev->SetNumberPrefix(L"1."); } listSty2->SetName(L"MyStyle2"); document->GetListStyles()->Add(listSty2); paragraph->GetListFormat()->ApplyStyle(listSty2->GetName()); //Add list style 3. intrusive_ptr listSty3 = new ListStyle(document, ListType::Numbered); for (int i = 0; i < listSty3->GetLevels()->GetCount(); i++) { intrusive_ptr listlev = listSty3->GetLevels()->GetItem(i); listlev->SetUsePrevLevelPattern(true); listlev->SetNumberPrefix(L"1.1."); } listSty3->SetName(L"MyStyle3"); document->GetListStyles()->Add(listSty3); //Add Heading 3. for (int i = 0; i < 4; i++) { paragraph = section->AddParagraph(); //Append text paragraph->AppendText(L"Heading3"); //Apply list style 3 for Heading 3 paragraph->ApplyStyle(BuiltinStyle::Heading3); paragraph->GetListFormat()->ApplyStyle(listSty3->GetName()); } ``` -------------------------------- ### Get Text by Style Name Source: https://github.com/eiceblue/spire.doc-for-c/blob/main/C++ Examples/doc_c.md Extracts text from paragraphs that have a specific style name, in this case, 'Heading1'. It iterates through all sections and paragraphs of the document to find matching text. ```cpp //Create string builder wstring* builder = new wstring(); //Loop through sections for (int i = 0; i < doc->GetSections()->GetCount(); i++) { intrusive_ptr
section = doc->GetSections()->GetItemInSectionCollection(i); //Loop through paragraphs for (int j = 0; j < section->GetParagraphs()->GetCount(); j++) { intrusive_ptr para = section->GetParagraphs()->GetItemInParagraphCollection(j); //Find the paragraph whose style name is "Heading1" wstring style_name = para->GetStyleName(); if (style_name.compare(L"Heading1") == 0) { //Write the text of paragraph builder->append(para->GetText()); builder->append(L"\n"); } } } ``` -------------------------------- ### Add Image and Textbox to Document Footer Source: https://github.com/eiceblue/spire.doc-for-c/blob/main/C++ Examples/doc_c.md Shows how to open a Word document, add a picture and a textbox to the footer, and set their positions and properties using Spire.Doc for C++. ```cpp //Open a Word document intrusive_ptr document = new Document(); document->LoadFromFile(inputFile.c_str()); //Add a picture in footer and set it's position intrusive_ptr picture = document->GetSections()->GetItemInSectionCollection(0)->GetHeadersFooters()->GetFooter()->AddParagraph()->AppendPicture(imgPath.c_str()); picture->SetVerticalOrigin(VerticalOrigin::Page); picture->SetHorizontalOrigin(HorizontalOrigin::Page); picture->SetVerticalAlignment(ShapeVerticalAlignment::Bottom); picture->SetTextWrappingStyle(TextWrappingStyle::None); //Add a textbox in footer and set it's position intrusive_ptr textbox = document->GetSections()->GetItemInSectionCollection(0)->GetHeadersFooters()->GetFooter()->AddParagraph()->AppendTextBox(150, 20); textbox->SetVerticalOrigin(VerticalOrigin::Page); textbox->SetHorizontalOrigin(HorizontalOrigin::Page); textbox->SetHorizontalPosition(300); textbox->SetVerticalPosition(700); textbox->GetBody()->AddParagraph()->AppendText(L"Welcome to E-iceblue"); ``` -------------------------------- ### C++ XML Element Text Content Access Source: https://github.com/eiceblue/spire.doc-for-c/blob/main/C++ Examples/doc_c.md Methods for getting and setting the text content of an XML element. Supports setting text content with various data types. ```C++ const char* GetText() const; void SetText( const char* inText ); void SetText( int value ); void SetText( unsigned value ); void SetText(int64_t value); void SetText(uint64_t value); void SetText( bool value ); void SetText( double value ); void SetText( float value ); ``` -------------------------------- ### Create and Apply List Styles in Word Document Source: https://github.com/eiceblue/spire.doc-for-c/blob/main/C++ Examples/doc_c.md Demonstrates how to create custom numbered and bulleted list styles and apply them to paragraphs within a Spire.Doc document. It includes setting prefixes and patterns for numbered lists. ```cpp //Initialize a document intrusive_ptr document = new Document(); //Add a section intrusive_ptr
sec = document->AddSection(); //Add paragraph and set list style intrusive_ptr paragraph = sec->AddParagraph(); paragraph->AppendText(L"Lists"); paragraph->ApplyStyle(BuiltinStyle::Title); paragraph = sec->AddParagraph(); paragraph->AppendText(L"Numbered List:")->GetCharacterFormat()->SetBold(true); //Create list style intrusive_ptr numberList = new ListStyle(document, ListType::Numbered); numberList->SetName(L"numberList"); //%1-%9 numberList->GetLevels()->GetItem(1)->SetNumberPrefix(L"%1."); numberList->GetLevels()->GetItem(1)->SetPatternType(ListPatternType::Arabic); numberList->GetLevels()->GetItem(2)->SetNumberPrefix(L"%1.%2."); numberList->GetLevels()->GetItem(2)->SetPatternType(ListPatternType::Arabic); intrusive_ptr bulletList = new ListStyle(document, ListType::Bulleted); bulletList->SetName(L"bulletList"); //add the list style into document document->GetListStyles()->Add(numberList); document->GetListStyles()->Add(bulletList); //Add paragraph and apply the list style paragraph = sec->AddParagraph(); paragraph->AppendText(L"List Item 1"); paragraph->GetListFormat()->ApplyStyle(numberList->GetName()); paragraph = sec->AddParagraph(); paragraph->AppendText(L"List Item 2"); paragraph->GetListFormat()->ApplyStyle(numberList->GetName()); paragraph = sec->AddParagraph(); paragraph->AppendText(L"List Item 2.1"); paragraph->GetListFormat()->ApplyStyle(numberList->GetName()); paragraph->GetListFormat()->SetListLevelNumber(1); paragraph = sec->AddParagraph(); paragraph->AppendText(L"Bulleted List:")->GetCharacterFormat()->SetBold(true); paragraph = sec->AddParagraph(); paragraph->AppendText(L"List Item 1"); paragraph->GetListFormat()->ApplyStyle(bulletList->GetName()); paragraph = sec->AddParagraph(); paragraph->AppendText(L"List Item 2"); paragraph->GetListFormat()->ApplyStyle(bulletList->GetName()); paragraph = sec->AddParagraph(); paragraph->AppendText(L"List Item 2.1"); paragraph->GetListFormat()->ApplyStyle(bulletList->GetName()); paragraph->GetListFormat()->SetListLevelNumber(1); ``` -------------------------------- ### Get Form Field by Name and Type Source: https://github.com/eiceblue/spire.doc-for-c/blob/main/C++ Examples/doc_c.md Illustrates how to retrieve a specific form field by its name and determine its type. Includes a helper function to convert FormFieldType enum to a string. ```cpp wstring getFormFieldType(FormFieldType type) { switch (type) { case FormFieldType::CheckBox: return L"CheckBox"; break; case FormFieldType::DropDown: return L"DropDown"; break; case FormFieldType::TextInput: return L"TextInput"; break; case FormFieldType::Unknown: return L"Unknown"; break; } return L""; } //Get the first section intrusive_ptr
section = document->GetSections()->GetItemInSectionCollection(0); //Get form field by name intrusive_ptr formField = section->GetBody()->GetFormFields()->GetItem(L"email"); wstring formFieldName = formField->GetName(); wstring formFieldNameType = getFormFieldType(formField->GetFormFieldType()); ``` -------------------------------- ### Convert HTML to XPS Format Source: https://github.com/eiceblue/spire.doc-for-c/blob/main/C++ Examples/doc_c.md This C++ code snippet demonstrates the conversion of an HTML file to the XPS format using Spire.Doc. It loads an HTML file and saves the content to an XPS file. ```cpp //Create Word document. intrusive_ptr document = new Document(); //Load the file from disk. document->LoadFromFile(inputFile.c_str(), FileFormat::Html, XHTMLValidationType::None); //Save to file. document->SaveToFile(outputFile.c_str(), FileFormat::XPS); document->Close(); ``` -------------------------------- ### Extract Document Content Starting from Form Field Source: https://github.com/eiceblue/spire.doc-for-c/blob/main/C++ Examples/doc_c.md This C++ code snippet demonstrates how to extract document content starting from a specific form field. It iterates through the form fields in a document, identifies a 'FieldFormTextInput' type field, finds its owner paragraph's index, and then extracts a specified number of subsequent document objects, adding them to a destination document. ```cpp //Create the source document intrusive_ptr sourceDocument = new Document(); //Create a destination document intrusive_ptr destinationDoc = new Document(); //Add a section intrusive_ptr
section = destinationDoc->AddSection(); //Define a variables int index = 0; //Traverse FormFields for (int i = 0; i < sourceDocument->GetSections()->GetItemInSectionCollection(0)->GetBody()->GetFormFields()->GetCount(); i++) { intrusive_ptr field = sourceDocument->GetSections()->GetItemInSectionCollection(0)->GetBody()->GetFormFields()->GetItem(i); //Find FieldFormTextInput type field if (field->GetType() == FieldType::FieldFormTextInput) { //Get the paragraph intrusive_ptr paragraph = field->GetOwnerParagraph(); //Get the index index = sourceDocument->GetSections()->GetItemInSectionCollection(0)->GetBody()->GetChildObjects()->IndexOf(paragraph); break; } } //Extract the content for (int i = index; i < index + 3; i++) { //Clone the ChildObjects of source document intrusive_ptr doobj = sourceDocument->GetSections()->GetItemInSectionCollection(0)->GetBody()->GetChildObjects()->GetItem(i)->Clone(); //Add to destination document section->GetBody()->GetChildObjects()->Add(doobj); } ``` -------------------------------- ### C++ Precompiled Header for Spire.Doc Source: https://github.com/eiceblue/spire.doc-for-c/blob/main/C++ Examples/doc_c.md This snippet shows how to define the library linking for Spire.Doc using a C++ precompiled header directive. ```cpp #pragma comment(lib,"../lib/Spire.Doc.Cpp.lib") ``` -------------------------------- ### Create Table Directly in Word Document (C++) Source: https://github.com/eiceblue/spire.doc-for-c/blob/main/C++ Examples/doc_c.md This C++ code demonstrates the basic creation of a Word document and a table within it using Spire.Doc. It covers initializing a document, adding a section, creating a table with specified dimensions, setting table width and borders, and populating a single row with two cells, each containing text and a background color. ```cpp //Create a Word document intrusive_ptr doc = new Document(); //Add a section intrusive_ptr
section = doc->AddSection(); //Create a table intrusive_ptr
table = new Table(doc); table->ResetCells(1, 2); //Set the width of table table->SetPreferredWidth(new PreferredWidth(WidthType::Percentage, 100)); //Set the border of table table->GetFormat()->GetBorders()->SetBorderType(BorderStyle::Single); //Create a table row intrusive_ptr row = table->GetRows()->GetItemInRowCollection(0); row->SetHeight(50.0f); //Create a table cell intrusive_ptr cell1 = table->GetRows()->GetItemInRowCollection(0)->GetCells()->GetItemInCellCollection(0); //Add a paragraph intrusive_ptr para1 = cell1->AddParagraph(); //Append text in the paragraph para1->AppendText(L"Row 1, Cell 1"); //Set the horizontal alignment of paragrah para1->GetFormat()->SetHorizontalAlignment(HorizontalAlignment::Center); //Set the background color of cell cell1->GetCellFormat()->GetShading()->SetBackgroundPatternColor(Color::GetCadetBlue()); //Set the vertical alignment of paragraph cell1->GetCellFormat()->SetVerticalAlignment(VerticalAlignment::Middle); //Create a table cell intrusive_ptr cell2 = table->GetRows()->GetItemInRowCollection(0)->GetCells()->GetItemInCellCollection(1); intrusive_ptr para2 = cell2->AddParagraph(); para2->AppendText(L"Row 1, Cell 2"); para2->GetFormat()->SetHorizontalAlignment(HorizontalAlignment::Center); cell2->GetCellFormat()->GetShading()->SetBackgroundPatternColor(Color::GetCadetBlue()); cell2->GetCellFormat()->SetVerticalAlignment(VerticalAlignment::Middle); row->GetCells()->Add(cell2); //Add the table in the section section->GetTables()->Add(table); ``` -------------------------------- ### XMLDocument Parse Method Source: https://github.com/eiceblue/spire.doc-for-c/blob/main/C++ Examples/doc_c.md Parses an XML string, handling potential errors like empty documents. It initializes the document, allocates a character buffer, and starts the deep parsing process. ```C++ XMLError XMLDocument::Parse( const char* xml, size_t nBytes ) { Clear(); if ( nBytes == 0 || !xml || !*xml ) { SetError( XML_ERROR_EMPTY_DOCUMENT, 0, 0 ); return _errorID; } if ( nBytes == static_cast(-1) ) { nBytes = strlen( xml ); } TIXMLASSERT( _charBuffer == 0 ); _charBuffer = new char[ nBytes+1 ]; memcpy( _charBuffer, xml, nBytes ); _charBuffer[nBytes] = 0; Parse(); if ( Error() ) { DeleteChildren(); _elementPool.Clear(); _attributePool.Clear(); _textPool.Clear(); _commentPool.Clear(); } return _errorID; } void XMLDocument::Parse() { TIXMLASSERT( NoChildren() ); TIXMLASSERT( _charBuffer ); _parseCurLineNum = 1; _parseLineNum = 1; char* p = _charBuffer; p = XMLUtil::SkipWhiteSpace( p, &_parseCurLineNum ); p = const_cast( XMLUtil::ReadBOM( p, &_writeBOM ) ); if ( !*p ) { SetError( XML_ERROR_EMPTY_DOCUMENT, 0, 0 ); return; } ParseDeep(p, 0, &_parseCurLineNum ); } ``` -------------------------------- ### Copy Paragraphs Between Documents Source: https://github.com/eiceblue/spire.doc-for-c/blob/main/C++ Examples/doc_c.md Demonstrates how to copy paragraphs from one Spire.Doc document to another using C++. It involves getting existing paragraphs and cloning them into a new section of the target document. ```cpp using namespace Spire::Doc; //Create Word document1. intrusive_ptr document1 = new Document(); //Create a new document. intrusive_ptr document2 = new Document(); //Get paragraph 1 and paragraph 2 in document1. intrusive_ptr
s = document1->GetSections()->GetItemInSectionCollection(0); intrusive_ptr p1 = s->GetParagraphs()->GetItemInParagraphCollection(0); intrusive_ptr p2 = s->GetParagraphs()->GetItemInParagraphCollection(1); //Copy p1 and p2 to document2. intrusive_ptr
s2 = document2->AddSection(); intrusive_ptr NewPara1 = Object::Dynamic_cast(p1->Clone()); s2->GetParagraphs()->Add(NewPara1); intrusive_ptr NewPara2 = Object::Dynamic_cast(p2->Clone()); s2->GetParagraphs()->Add(NewPara2); ``` -------------------------------- ### Replace Bookmark Content with Table Source: https://github.com/eiceblue/spire.doc-for-c/blob/main/C++ Examples/doc_c.md Shows how to replace bookmark content with a table in a Spire.Doc document. This involves creating a table, populating it with data, and then inserting it into the bookmark. ```cpp //Create a table intrusive_ptr
table = new Table(doc, true); //Create data const int rowsCount = 4; const int colsCount = 5; std::wstring data[rowsCount][colsCount] = { {L"Name", L"Capital", L"Continent", L"Area", L"Population"}, {L"Argentina", L"Buenos Aires", L"South America", L"2777815", L"32300003"}, {L"Bolivia", L"La Paz", L"South America", L"1098575", L"7300000"}, {L"Brazil", L"Brasilia", L"South America", L"8511196", L"150400000"} }; table->ResetCells(rowsCount, colsCount); //Fill the table with the data for (int i = 0; i < rowsCount; i++) { for (int j = 0; j < colsCount; j++) { table->GetRows()->GetItemInRowCollection(i)->GetCells()->GetItemInCellCollection(j)->AddParagraph()->AppendText(data[i][j].c_str()); } } //Get the specific bookmark by its name intrusive_ptr navigator = new BookmarksNavigator(doc); navigator->MoveToBookmark(L"Test"); //Create a TextBodyPart instance and add the table to it intrusive_ptr part = new TextBodyPart(doc); part->GetBodyItems()->Add(table); //Replace the current bookmark content with the TextBodyPart object navigator->ReplaceBookmarkContent(part); ``` -------------------------------- ### Insert Section Break in Word Document (C++) Source: https://github.com/eiceblue/spire.doc-for-c/blob/main/C++ Examples/doc_c.md Demonstrates how to create a new Word document and insert a section break of type 'NewPage'. This is useful for starting new sections on a fresh page. ```cpp //Create word document intrusive_ptr document = new Document(); intrusive_ptr
section = document->AddSection(); //insert a break code section = document->AddSection(); section->AddParagraph()->InsertSectionBreak(SectionBreakType::NewPage); ``` -------------------------------- ### C++ Class for Document Structure Tags Source: https://github.com/eiceblue/spire.doc-for-c/blob/main/C++ Examples/doc_c.md Defines a C++ class `StructureTagsInternal` to hold collections of `StructureDocumentTag` and `StructureDocumentTagInline` objects. It includes methods to get and set these collections, ensuring they are initialized if empty. ```cpp class StructureTagsInternal : public ReferenceCounter { private: std::vector> m_tagInlines; std::vector> m_tags; public: std::vector>& GetTagInlines() { if (m_tagInlines.empty()) { m_tagInlines = std::vector>(); } return m_tagInlines; } void SetTagInlines(std::vector> value) { m_tagInlines = value; } std::vector>& GetTags() { if (m_tags.empty()) { m_tags = std::vector>(); } return m_tags; } void SetTags(std::vector> value) { m_tags = value; } }; ``` -------------------------------- ### Create and Format Table in Word Document (C++) Source: https://github.com/eiceblue/spire.doc-for-c/blob/main/C++ Examples/doc_c.md This C++ code snippet demonstrates how to create a table in a Word document using Spire.Doc. It includes steps for adding a table, defining rows and cells, setting header formatting with bold text and centered alignment, populating data rows, and applying alternating row background colors for better readability. ```cpp void addTable(intrusive_ptr
section) { intrusive_ptr
table = section->AddTable(true); table->ResetCells(data.size() + 1, header.size()); // ***************** First Row ************************* intrusive_ptr row = table->GetRows()->GetItemInRowCollection(0); row->SetIsHeader(true); row->SetHeight(20); //unit: point, 1point = 0.3528 mm row->SetHeightType(TableRowHeightType::Exactly); for (int i = 0; i < row->GetCells()->GetCount(); i++) { row->GetCells()->GetItemInCellCollection(i)->GetCellFormat()->GetShading()->SetBackgroundPatternColor(Color::GetGray()); } for (size_t i = 0; i < header.size(); i++) { row->GetCells()->GetItemInCellCollection(i)->GetCellFormat()->SetVerticalAlignment(VerticalAlignment::Middle); intrusive_ptr p = row->GetCells()->GetItemInCellCollection(i)->AddParagraph(); p->GetFormat()->SetHorizontalAlignment(HorizontalAlignment::Center); intrusive_ptr txtRange = p->AppendText(header[i].c_str()); txtRange->GetCharacterFormat()->SetBold(true); } for (size_t r = 0; r < data.size(); r++) { intrusive_ptr dataRow = table->GetRows()->GetItemInRowCollection(r + 1); dataRow->SetHeight(20); dataRow->SetHeightType(TableRowHeightType::Exactly); for (int i = 0; i < dataRow->GetCells()->GetCount(); i++) { dataRow->GetCells()->GetItemInCellCollection(i)->GetCellFormat()->GetShading()->SetBackgroundPatternColor(Color::Empty()); } for (size_t c = 0; c < data[r].size(); c++) { dataRow->GetCells()->GetItemInCellCollection(c)->GetCellFormat()->SetVerticalAlignment(VerticalAlignment::Middle); dataRow->GetCells()->GetItemInCellCollection(c)->AddParagraph()->AppendText(data[r][c].c_str()); } } for (int j = 1; j < table->GetRows()->GetCount(); j++) { if (j % 2 == 0) { intrusive_ptr row2 = table->GetRows()->GetItemInRowCollection(j); for (int f = 0; f < row2->GetCells()->GetCount(); f++) { row2->GetCells()->GetItemInCellCollection(f)->GetCellFormat()->GetShading()->SetBackgroundPatternColor(Color::GetLightBlue()); } } } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.