### Spire.XLS C++ Precompiled Header Setup Source: https://github.com/eiceblue/spire.xls-for-c/blob/main/C++ Examples/xls_c.md Configures the precompiled header for the Spire.XLS C++ library by including necessary directives and specifying the library path. ```cpp #pragma once #pragma comment(lib,"../lib/Spire.Xls.Cpp.lib") #define DATAPATH L"Data\" #define OUTPUTPATH L"Output\" ``` -------------------------------- ### Set First Page Number for Worksheet Source: https://github.com/eiceblue/spire.xls-for-c/blob/main/C++ Examples/xls_c.md Shows how to set the starting page number for a worksheet in Spire.XLS. ```cpp //Get the first worksheet intrusive_ptr sheet = dynamic_pointer_cast(workbook->GetWorksheets()->Get(0)); //Set the first page number of the worksheet pages. sheet->GetPageSetup()->SetFirstPageNumber(2); ``` -------------------------------- ### Set Excel Paper Size to A4 Source: https://github.com/eiceblue/spire.xls-for-c/blob/main/C++ Examples/xls_c.md Demonstrates how to create a workbook, get the first worksheet, and set its paper size to A4 using Spire.XLS. ```cpp //Create a workbook intrusive_ptr workbook = new Workbook(); //Get the first worksheet intrusive_ptr sheet = dynamic_pointer_cast(workbook->GetWorksheets()->Get(0)); //Set the paper size of the worksheet as A4 paper. sheet->GetPageSetup()->SetPaperSize(PaperSizeType::PaperA4); ``` -------------------------------- ### Set Cell Fill Pattern and Color Source: https://github.com/eiceblue/spire.xls-for-c/blob/main/C++ Examples/xls_c.md Demonstrates how to apply fill formatting to Excel cells, specifically setting the background color and the fill pattern. It shows how to get the cell style and use methods like `SetColor` and `SetFillPattern`. ```cpp //Set cell color dynamic_pointer_cast(sheet->GetRange(L"B7:F7"))->GetStyle()->SetColor(Spire::Xls::Color::GetYellow()); //Set cell fill pattern dynamic_pointer_cast(sheet->GetRange(L"B8:F8"))->GetStyle()->SetFillPattern(ExcelPatternType::Percent125Gray); ``` -------------------------------- ### Spire.XLS C++ Simple Excel File with Hello World Source: https://github.com/eiceblue/spire.xls-for-c/blob/main/C++ Examples/xls_c.md Provides a basic C++ example using Spire.XLS to create an Excel file, add 'Hello World' text to cell A1, and auto-fit the column. ```cpp //Create a workbook intrusive_ptr workbook = new Workbook(); //Get the first sheet intrusive_ptr sheet = dynamic_pointer_cast(workbook->GetWorksheets()->Get(0)); dynamic_pointer_cast(sheet->GetRange(L"A1"))->SetText(L"Hello World"); dynamic_pointer_cast(sheet->GetRange(L"A1"))->AutoFitColumns(); ``` -------------------------------- ### Get Default Row and Column Count of an Excel Worksheet Source: https://github.com/eiceblue/spire.xls-for-c/blob/main/C++ Examples/xls_c.md Retrieves the default number of rows and columns present in an Excel worksheet. This example shows how to create a workbook, clear existing sheets, create a new empty sheet, and then get its row and column counts. ```cpp //Create a workbook intrusive_ptr workbook = new Workbook(); //Clear all worksheets workbook->GetWorksheets()->Clear(); //Create a new worksheet intrusive_ptr sheet = workbook->CreateEmptySheet(); //Get row and column count int rowCount = sheet->GetRows()->GetCount(); int columnCount = sheet->GetColumns()->GetCount(); ``` -------------------------------- ### Disable Pivot Table Ribbon/Wizard Source: https://github.com/eiceblue/spire.xls-for-c/blob/main/C++ Examples/xls_c.md This example illustrates how to disable the ribbon or wizard interface for a specific pivot table in an Excel worksheet. It involves getting the pivot table and setting its EnableWizard property to false. ```cpp //Get the first worksheet intrusive_ptr sheet = dynamic_pointer_cast(workbook->GetWorksheets()->Get(L"PivotTable")); intrusive_ptr pt = dynamic_pointer_cast(sheet->GetPivotTables()->Get(0)); //Disable ribbon for this pivot table pt->SetEnableWizard(false); ``` -------------------------------- ### Get All Named Ranges from Workbook in C++ Source: https://github.com/eiceblue/spire.xls-for-c/blob/main/C++ Examples/xls_c.md This C++ code example shows how to retrieve all named ranges defined within an Excel workbook. It initializes a workbook and then iterates through the collection of named ranges, accessing each one. ```cpp using namespace Spire::Xls; //Create a workbook intrusive_ptr workbook = new Workbook(); //Get all named range intrusive_ptr ranges = workbook->GetNameRanges(); for (int i = 0; i < ranges->GetCount(); i++) { intrusive_ptr nameRange = ranges->Get(i); } ``` -------------------------------- ### Spire.XLS C++ Batch Creation of Excel Files Source: https://github.com/eiceblue/spire.xls-for-c/blob/main/C++ Examples/xls_c.md Illustrates how to programmatically create fifty Excel files in C++ using Spire.XLS, with each file containing five worksheets populated with data. ```cpp for (int n = 0; n < 50; n++) { intrusive_ptr workbook = new Workbook(); workbook->CreateEmptySheets(5); for (int i = 0; i < 5; i++) { intrusive_ptr sheet = dynamic_pointer_cast(workbook->GetWorksheets()->Get(i)); sheet->SetName((L"Sheet" + std::to_wstring(i)).c_str()); for (int row = 1; row <= 150; row++) { for (int col = 1; col <= 50; col++) { dynamic_pointer_cast(sheet->GetRange(row, col))->SetText((L"row" + std::to_wstring(row) + L" col" + std::to_wstring(col)).c_str()); } } } workbook->SaveToFile((output_path + L"Workbook" + std::to_wstring(n) + L".xlsx").c_str(), ExcelVersion::Version2010); workbook->Dispose(); } ``` -------------------------------- ### Get Displayed Cell Text with Formatting Source: https://github.com/eiceblue/spire.xls-for-c/blob/main/C++ Examples/xls_c.md Retrieves the displayed text of a cell after applying number formatting. It demonstrates setting a number value, applying a format like '0.00', and then getting both the raw value and the displayed text. ```cpp //Set value for B8 intrusive_ptr cell = dynamic_pointer_cast(sheet->GetRange(L"B8")); cell->SetNumberValue(0.012345); //Set the cell style intrusive_ptr style = dynamic_pointer_cast(cell->GetStyle()); style->SetNumberFormat(L"0.00"); //Get the cell value wstring cellValue = cell->GetValue(); //Get the displayed text of the cell wstring displayedText = cell->GetDisplayedText(); ``` -------------------------------- ### Spire.XLS C++ Create Excel File and Fill Data Source: https://github.com/eiceblue/spire.xls-for-c/blob/main/C++ Examples/xls_c.md Shows how to create an Excel file with a single sheet and populate it with a large amount of data (10000 rows, 30 columns) using Spire.XLS in C++. ```cpp //Create a workbook intrusive_ptr workbook = new Workbook(); workbook->CreateEmptySheets(1); intrusive_ptr sheet = dynamic_pointer_cast(workbook->GetWorksheets()->Get(0)); for (int row = 1; row <= 10000; row++) { for (int col = 1; col <= 30; col++) { dynamic_pointer_cast(sheet->GetRange(row, col))->SetText((L"row" + std::to_wstring(row) + L" col" + std::to_wstring(col)).c_str()); } } workbook->SaveToFile(outputFile.c_str(), ExcelVersion::Version2010); ``` -------------------------------- ### Get and Set Excel Textbox by Name Source: https://github.com/eiceblue/spire.xls-for-c/blob/main/C++ Examples/xls_c.md Illustrates how to add a textbox to an Excel worksheet, set its name and text content, and then retrieve the textbox by its name using Spire.XLS for C++. It also shows how to get the text from the retrieved textbox. ```cpp //Create a workbook intrusive_ptr workbook = new Workbook(); //Get the first worksheet intrusive_ptr sheet = dynamic_pointer_cast(workbook->GetWorksheets()->Get(0)); //Insert a TextBox dynamic_pointer_cast(sheet->GetRange(L"A2"))->SetText(L"Name:"); intrusive_ptr textBox = sheet->GetTextBoxes()->AddTextBox(2, 2, 18, 65); //Set the name textBox->SetName(L"FirstTextBox"); //Set string text for TextBox textBox->SetText(L"Spire.XLS for C++ is a professional Excel C++ API that can be used to create, read, write and convert Excel files in any type of C++ application.\n"); //Get the TextBox by the name intrusive_ptr FindTextBox = sheet->GetTextBoxes()->Get(L"FirstTextBox"); //Get the TextBox text wstring text = FindTextBox->GetText(); workbook->Dispose(); ``` -------------------------------- ### Load Excel Workbook from Stream Source: https://github.com/eiceblue/spire.xls-for-c/blob/main/C++ Examples/xls_c.md Demonstrates how to create a new workbook and load an Excel file from an input stream using Spire.XLS for C++. ```cpp //Create a workbook intrusive_ptr workbook = new Workbook(); //Open excel from a stream ifstream inputf(inputFile.c_str(), ios::in | ios::binary); intrusive_ptr stream = new Stream(inputf); workbook->LoadFromStream(stream); ``` -------------------------------- ### Demonstrate Different Ways to Open Excel Files Source: https://github.com/eiceblue/spire.xls-for-c/blob/main/C++ Examples/xls_c.md Illustrates various methods for opening Excel files in C++ using Spire.XLS, including by file path, file stream, and specific Excel versions (97-2003, XML, CSV). ```cpp //1. Load file by file path //Create a workbook intrusive_ptr workbook1 = new Workbook(); //Load the document from disk workbook1->LoadFromFile(inputFile.c_str()); //2. Load file by file stream ifstream inputf(inputFile.c_str(), ios::in | ios::binary); intrusive_ptr stream = new Stream(inputf); //Create a workbook intrusive_ptr workbook2 = new Workbook(); //Load the document from disk workbook2->LoadFromStream(stream); //3. Open Microsoft Excel 97 - 2003 file intrusive_ptr wbExcel97 = new Workbook(); wbExcel97->LoadFromFile(inputFile_97.c_str(), ExcelVersion::Version97to2003); //4. Open xml file intrusive_ptr wbXML = new Workbook(); wbXML->LoadFromXml(inputFile_xml.c_str()); //5. Open csv file intrusive_ptr wbCSV = new Workbook(); wbCSV->LoadFromFile(inputFile_csv.c_str(), L",", 1, 1); ``` -------------------------------- ### Create Pivot Chart from Pivot Table Source: https://github.com/eiceblue/spire.xls-for-c/blob/main/C++ Examples/xls_c.md This example shows how to create a clustered column chart based on an existing pivot table using Spire.XLS. It covers getting the pivot table, creating the chart, setting its position, and adding a title. ```cpp //get the first pivot table in the worksheet intrusive_ptr pivotTable = sheet->GetPivotTables()->Get(0); //create a clustered column chart based on the pivot table intrusive_ptr chart = sheet->GetCharts()->Add(ExcelChartType::ColumnClustered, pivotTable); //set chart position chart->SetTopRow(10); chart->SetLeftColumn(1); chart->SetRightColumn(7); chart->SetBottomRow(25); //set chart title chart->SetChartTitle(L"Pivot Chart"); ``` -------------------------------- ### Set Worksheet View Mode to Preview Source: https://github.com/eiceblue/spire.xls-for-c/blob/main/C++ Examples/xls_c.md A simple example demonstrating how to set the view mode of the first worksheet in an Excel workbook to Preview using Spire.XLS for C++. ```cpp //Create a workbook intrusive_ptr workbook = new Workbook(); //Set the view mode dynamic_pointer_cast(workbook->GetWorksheets()->Get(0))->SetViewMode(ViewMode::Preview); ``` -------------------------------- ### Access Chart's Worksheet Source: https://github.com/eiceblue/spire.xls-for-c/blob/main/C++ Examples/xls_c.md This example shows how to get the worksheet associated with a specific chart in an Excel file using Spire.XLS. It retrieves the first worksheet, then the first chart within that worksheet, and finally accesses the chart's parent worksheet. ```cpp //Get the first worksheet intrusive_ptr sheet = dynamic_pointer_cast(workbook->GetWorksheets()->Get(0)); //Access the first chart inside this worksheet intrusive_ptr chart = dynamic_pointer_cast(sheet->GetCharts()->Get(0)); //Get its worksheet intrusive_ptr wSheet = chart->GetWorksheet(); ``` -------------------------------- ### Create and Apply Predefined Styles to Cells Source: https://github.com/eiceblue/spire.xls-for-c/blob/main/C++ Examples/xls_c.md Shows how to create a new style with custom font settings (name, bold, size, color) and apply it to an Excel cell using Spire.XLS for C++. ```cpp //Create a workbook intrusive_ptr workbook = new Workbook(); //Get the first worksheet intrusive_ptr sheet = dynamic_pointer_cast(workbook->GetWorksheets()->Get(0)); //Create a new style intrusive_ptr style = workbook->GetStyles()->Add(L"newStyle"); style->GetFont()->SetFontName(L"Calibri"); style->GetFont()->SetIsBold(true); style->GetFont()->SetSize(15); style->GetFont()->SetColor(Spire::Xls::Color::GetCornflowerBlue()); //Get "B5" cell intrusive_ptr range = dynamic_pointer_cast(sheet->GetRange(L"B5")); range->SetText(L"Welcome to use Spire.XLS"); range->SetCellStyleName(style->GetName()); range->AutoFitColumns(); ``` -------------------------------- ### Convert Office Open XML to Excel Format Source: https://github.com/eiceblue/spire.xls-for-c/blob/main/C++ Examples/xls_c.md This C++ code demonstrates how to create a workbook, load an XML file in Office Open XML format, and save it to an Excel file using Spire.XLS. ```cpp //Create a workbook intrusive_ptr workbook = new Workbook(); //Load XML file ifstream fs(inputFile.c_str(), ios::in | ios::binary); intrusive_ptr fileStream = new Stream(fs); workbook->LoadFromXml(fileStream); //Save to Excel file workbook->SaveToFile(outputFile.c_str(), ExcelVersion::Version2010); workbook->Dispose(); ``` -------------------------------- ### Get Cell Range Linked to Shapes Source: https://github.com/eiceblue/spire.xls-for-c/blob/main/C++ Examples/xls_c.md Explains how to retrieve the cell address that is linked to a shape in an Excel worksheet using Spire.XLS for C++. ```cpp // Get the first worksheet from the workbook intrusive_ptrsheet = dynamic_pointer_cast(workbook->GetWorksheets()->Get(0)); // Get the collection of preset geometric shapes from the worksheet intrusive_ptrprstGeomShapeCollection = sheet->GetPrstGeomShapes(); // Get the shape with the name "Yesterday" from the collection auto shape = prstGeomShapeCollection->Get(L"Yesterday"); // Get the cell address linked to the shape std::wstring cellAddress = shape->GetLinkedCell()->GetRangeAddress(); // Get the shape with the name "NewShapes" from the collection shape = prstGeomShapeCollection->Get(L"NewShapes"); // Get the cell address linked to the shape cellAddress = shape->GetLinkedCell()->GetRangeAddress(); ``` -------------------------------- ### Get Freeze Pane Range Information Source: https://github.com/eiceblue/spire.xls-for-c/blob/main/C++ Examples/xls_c.md Retrieves the row and column indices of the freeze pane in an Excel worksheet. Returns 0 for both if no pane is frozen. ```cpp //Create a workbook intrusive_ptr workbook = new Workbook(); //Get the first worksheet intrusive_ptr sheet = dynamic_pointer_cast(workbook->GetWorksheets()->Get(0)); //The row and column index of the frozen pane is passed through the out parameter. //If it returns to 0, it means that it is not frozen int rowIndex = sheet->GetFreezePanes()[0]; int colIndex = sheet->GetFreezePanes()[1]; wstring range = L"Row index: " + to_wstring(rowIndex) + L", column index: " + to_wstring(colIndex); ``` -------------------------------- ### Spire.XLS C++ Create Workbook with Multiple Sheets Source: https://github.com/eiceblue/spire.xls-for-c/blob/main/C++ Examples/xls_c.md Demonstrates how to create a new Excel workbook using Spire.XLS in C++ and add multiple empty worksheets, setting a name for each. ```cpp //Create a workbook intrusive_ptr workbook = new Workbook(); workbook->CreateEmptySheets(5); for (int i = 0; i < 5; i++) { intrusive_ptr sheet = dynamic_pointer_cast(workbook->GetWorksheets()->Get(i)); sheet->SetName((L"Sheet" + std::to_wstring(i)).c_str()); } ``` -------------------------------- ### Spire.XLS C++ Open Existing Excel File and Operate Source: https://github.com/eiceblue/spire.xls-for-c/blob/main/C++ Examples/xls_c.md Demonstrates how to open an existing Excel file in C++ using Spire.XLS, add a new sheet named 'MySheet', and write 'Hello World' to cell A1. ```cpp //Create a workbook intrusive_ptr workbook = new Workbook(); workbook->LoadFromFile(inputFile.c_str()); //Add a new sheet, named MySheet intrusive_ptr sheet = workbook->GetWorksheets()->Add(L"MySheet"); //Get the reference of L"A1" cell from the cells collection of a worksheet dynamic_pointer_cast(sheet->GetRange(L"A1"))->SetText(L"Hello World"); workbook->Dispose(); ``` -------------------------------- ### Get List of Fonts Used in Excel Workbook Source: https://github.com/eiceblue/spire.xls-for-c/blob/main/C++ Examples/xls_c.md Iterates through all cells in all worksheets of an Excel workbook to collect a list of all fonts used. It then formats this information into a string. ```cpp //Create a workbook intrusive_ptr workbook = new Workbook(); std::vector> fonts; //Loop all sheets of workbook for (int i = 0; i < workbook->GetWorksheets()->GetCount(); i++) { intrusive_ptr sheet = dynamic_pointer_cast(workbook->GetWorksheets()->Get(i)); for (int r = 0; r < sheet->GetRows()->GetCount(); r++) { for (int c = 0; c < sheet->GetRows()->GetItem(r)->GetCells()->GetCount(); c++) { //Get the font of cell and add it to list fonts.push_back(dynamic_pointer_cast(sheet->GetRows()->GetItem(r)->GetCells()->GetItem(c)->GetStyle()->GetFont())); } } } wstring* strB = new wstring(); for (auto font : fonts) { strB->append(L"FontName:"); strB->append(font->GetFontName()); strB->append(L"; FontSize:{1}"); strB->append(to_wstring(font->GetSize())); } ``` -------------------------------- ### Set Header and Footer Margins Source: https://github.com/eiceblue/spire.xls-for-c/blob/main/C++ Examples/xls_c.md Illustrates how to set the header and footer margins for a worksheet using Spire.XLS. ```cpp //Get the PageSetup object of the first worksheet. intrusive_ptr pageSetup = dynamic_pointer_cast(sheet->GetPageSetup()); //Set the margins of header and footer. pageSetup->SetHeaderMarginInch(2); pageSetup->SetFooterMarginInch(2); ``` -------------------------------- ### Get Address of Named Range Source: https://github.com/eiceblue/spire.xls-for-c/blob/main/C++ Examples/xls_c.md Retrieves the address of a named range from an Excel workbook. It requires creating a workbook object and accessing the named range by its index. ```cpp //Create a workbook intrusive_ptr workbook = new Workbook(); //Get specific named range by index intrusive_ptr NamedRange = workbook->GetNameRanges()->Get(0); //Get the address of the named range wstring address = NamedRange->GetRefersToRange()->GetRangeAddress(); ``` -------------------------------- ### Set Various Printing Options for Excel Worksheet Source: https://github.com/eiceblue/spire.xls-for-c/blob/main/C++ Examples/xls_c.md Demonstrates setting multiple printing options including gridlines, headings, black and white printing, comments, draft quality, and error display for an Excel worksheet with Spire.XLS. ```cpp //Get the reference of the PageSetup of the worksheet. intrusive_ptr pageSetup = dynamic_pointer_cast(sheet->GetPageSetup()); //Allow to print gridlines. pageSetup->SetIsPrintGridlines(true); //Allow to print row/column headings. pageSetup->SetIsPrintHeadings(true); //Allow to print worksheet in black & white mode. pageSetup->SetBlackAndWhite(true); //Allow to print comments as displayed on worksheet. pageSetup->SetPrintComments(PrintCommentType::InPlace); //Allow to print worksheet with draft quality. pageSetup->SetDraft(true); //Allow to print cell errors as N/A. pageSetup->SetPrintErrors(PrintErrorsType::NA); ``` -------------------------------- ### Get Crop Position of an Image in Excel Worksheet Source: https://github.com/eiceblue/spire.xls-for-c/blob/main/C++ Examples/xls_c.md Retrieves the crop position (left, top, width, height) of the first image in the first worksheet of an Excel file. ```cpp //Get the first worksheet intrusive_ptr sheet = dynamic_pointer_cast(workbook->GetWorksheets()->Get(0)); //Get the image from the first sheet intrusive_ptr picture = sheet->GetPictures()->Get(0); //Get the cropped position int left = picture->GetLeft(); int top = picture->GetTop(); int width = picture->GetWidth(); int height = picture->GetHeight(); //Set string format for displaying wstring displayString = L"Crop position: Left " + std::to_wstring(left) + L"\r\nCrop position: Top " + std::to_wstring(top) + L"\r\nCrop position: Width " + std::to_wstring(width) + L"\r\nCrop position: Height " + std::to_wstring(height); ``` -------------------------------- ### Get Named Range by Index and Name Source: https://github.com/eiceblue/spire.xls-for-c/blob/main/C++ Examples/xls_c.md Demonstrates how to retrieve a named range from an Excel workbook either by its index or by its name. This involves loading the workbook and then accessing the named ranges collection. ```cpp //Create a workbook intrusive_ptr workbook = new Workbook(); //Load the Excel document from disk workbook->LoadFromFile(inputFile.c_str()); //Get specific named range by index wstring name1 = workbook->GetNameRanges()->Get(1)->GetName(); //Get specific named range by name wstring name2 = workbook->GetNameRanges()->Get(L"NameRange3")->GetName(); ``` -------------------------------- ### Apply Style to Worksheet Source: https://github.com/eiceblue/spire.xls-for-c/blob/main/C++ Examples/xls_c.md Demonstrates how to create a custom cell style with font and color properties and apply it to an entire worksheet using Spire.XLS for C++. ```cpp //Create a cell style intrusive_ptr style = workbook->GetStyles()->Add(L"newStyle"); style->SetColor(Spire::Xls::Color::GetLightBlue()); style->GetFont()->SetColor(Spire::Xls::Color::GetWhite()); style->GetFont()->SetSize(15); style->GetFont()->SetIsBold(true); //Apply the style to the first worksheet sheet->ApplyStyle(style); ``` -------------------------------- ### Load and Save Excel File with Macro Source: https://github.com/eiceblue/spire.xls-for-c/blob/main/C++ Examples/xls_c.md Illustrates the process of loading an Excel file containing macros, modifying its content, and saving it back to a new file using Spire.XLS for C++. ```cpp //Create a workbook intrusive_ptr workbook = new Workbook(); //Load the Excel document from disk workbook->LoadFromFile(L"MacroSample.xls"); //Get the first worksheet intrusive_ptr sheet = dynamic_pointer_cast(workbook->GetWorksheets()->Get(0)); dynamic_pointer_cast(sheet->GetRange(L"A5"))->SetText(L"This is a simple test!"); //Save to file. workbook->SaveToFile(L"LoadAndSaveFileWithMacro.xls", ExcelVersion::Version97to2003); workbook->Dispose(); ``` -------------------------------- ### Set Default Style for Rows and Columns Source: https://github.com/eiceblue/spire.xls-for-c/blob/main/C++ Examples/xls_c.md Demonstrates how to create a workbook, get a worksheet, create a cell style with a yellow color, and apply this style as the default for a specific row and column. ```cpp //Create a workbook intrusive_ptr workbook = new Workbook(); //Get the first worksheet intrusive_ptr sheet = dynamic_pointer_cast(workbook->GetWorksheets()->Get(0)); //Create a cell style and set the color intrusive_ptr style = workbook->GetStyles()->Add(L"Mystyle"); style->SetColor(Spire::Xls::Color::GetYellow()); //Set the default style for the first row and column sheet->SetDefaultRowStyle(1, style); sheet->SetDefaultColumnStyle(1, style); ``` -------------------------------- ### Delete Multiple Rows and Columns from Excel Worksheet Source: https://github.com/eiceblue/spire.xls-for-c/blob/main/C++ Examples/xls_c.md Demonstrates how to delete a specified number of rows starting from a particular row index, and similarly for columns. This is useful for removing contiguous blocks of data. ```cpp //Delete 4 rows from the fifth row sheet->DeleteRow(5, 4); //Delete 2 columns from the second column sheet->DeleteColumn(2, 2); ``` -------------------------------- ### Create Radar Chart Source: https://github.com/eiceblue/spire.xls-for-c/blob/main/C++ Examples/xls_c.md Provides C++ code for creating a radar chart with Spire.XLS. The example includes adding a chart, setting its position, data range, type, title, and formatting the plot area and legend. ```cpp //Add a new chart worsheet to workbook intrusive_ptr chart = sheet->GetCharts()->Add(); //Set position of chart chart->SetLeftColumn(1); chart->SetTopRow(6); chart->SetRightColumn(11); chart->SetBottomRow(29); //Set region of chart data chart->SetDataRange(dynamic_pointer_cast(sheet->GetRange(L"A1:C5"))); chart->SetSeriesDataFromRange(false); chart->SetChartType(ExcelChartType::Radar); //Chart title chart->SetChartTitle(L"Sale market by region"); chart->GetChartTitleArea()->SetIsBold(true); chart->GetChartTitleArea()->SetSize(12); dynamic_pointer_cast(chart->GetPlotArea())->GetFill()->SetVisible(false); chart->GetLegend()->SetPosition(LegendPositionType::Corner); ``` -------------------------------- ### Copy Worksheet within Workbook (C++) Source: https://github.com/eiceblue/spire.xls-for-c/blob/main/C++ Examples/xls_c.md Demonstrates how to copy a worksheet to another worksheet within the same workbook using Spire.XLS for C++. It involves getting source and destination worksheets and using the Copy method. ```cpp //Get the first and the second worksheets. intrusive_ptr sheet = dynamic_pointer_cast(workbook->GetWorksheets()->Get(0)); intrusive_ptr sheet1 = dynamic_pointer_cast(workbook->GetWorksheets()->Add(L"MySheet")); intrusive_ptr sourceRange = dynamic_pointer_cast(sheet->GetAllocatedRange()); //Copy the first worksheet to the second one. sheet->Copy(sourceRange, sheet1, sheet->GetFirstRow(), sheet->GetFirstColumn(), true); ``` -------------------------------- ### Create Sunburst Chart Source: https://github.com/eiceblue/spire.xls-for-c/blob/main/C++ Examples/xls_c.md This C++ example demonstrates creating a Sunburst chart using Spire.XLS. It covers setting the chart type, data range, display area, title, data label size, and disabling the legend. ```cpp // Add a new chart to the worksheet. auto officeChart = sheet->GetCharts()->Add(); // Set the chart type to Sunburst. officeChart->SetChartType(ExcelChartType::SunBurst); // Set the data range for the chart to range A1:D16. officeChart->SetDataRange(dynamic_pointer_cast(sheet->GetRange(L"A1:D16"))); // Set the top row, bottom row, left column, and right column of the chart's display area. officeChart->SetTopRow(1); officeChart->SetBottomRow(17); officeChart->SetLeftColumn(6); officeChart->SetRightColumn(14); // Set the title of the chart. officeChart->SetChartTitle(L"Sales by quarter"); // Set the size of the data labels for the default data point of the first series to 8 points. officeChart->GetSeries()->Get(0)->GetDataPoints()->GetDefaultDataPoint()->GetDataLabels()->SetSize(8); // Disable the legend in the chart. officeChart->SetHasLegend(false); ``` -------------------------------- ### Extract Text from Excel Textbox Source: https://github.com/eiceblue/spire.xls-for-c/blob/main/C++ Examples/xls_c.md Demonstrates how to extract text content from a textbox shape within an Excel worksheet using Spire.XLS for C++. It involves getting the worksheet, accessing the first textbox, and retrieving its text. ```cpp //Get the first worksheet intrusive_ptr sheet = dynamic_pointer_cast(workbook->GetWorksheets()->Get(0)); //Get the first textbox. intrusive_ptr shape = dynamic_pointer_cast(sheet->GetTextBoxes()->Get(0)); //Extract text from the text box. wstring* content = new wstring(); content->append(L"The text extracted from the TextBox is: \n"); content->append(shape->GetText()); ``` -------------------------------- ### Create a Gauge Chart using Doughnut and Pie Charts Source: https://github.com/eiceblue/spire.xls-for-c/blob/main/C++ Examples/xls_c.md This C++ code illustrates how to create a gauge chart by combining a doughnut chart for the main gauge and a pie chart for the pointer. It covers setting chart types, data ranges, legend, position, doughnut hole size, slice angles, and data point colors. ```cpp //Add a Doughnut chart intrusive_ptr chart = sheet->GetCharts()->Add(ExcelChartType::Doughnut); chart->SetDataRange(dynamic_pointer_cast(sheet->GetRange(L"A1:A5"))); chart->SetSeriesDataFromRange(false); chart->SetHasLegend(true); //Set the position of chart chart->SetLeftColumn(2); chart->SetTopRow(7); chart->SetRightColumn(9); chart->SetBottomRow(25); //Get the series 1 intrusive_ptr cs1 = static_cast>(chart->GetSeries()->Get(L"Value")); cs1->GetFormat()->GetOptions()->SetDoughnutHoleSize(60); cs1->GetDataFormat()->GetOptions()->SetFirstSliceAngle(270); //Set the fill color cs1->GetDataPoints()->Get(0)->GetDataFormat()->GetFill()->SetForeColor(Spire::Xls::Color::GetYellow()); cs1->GetDataPoints()->Get(1)->GetDataFormat()->GetFill()->SetForeColor(Spire::Xls::Color::GetPaleVioletRed()); cs1->GetDataPoints()->Get(2)->GetDataFormat()->GetFill()->SetForeColor(Spire::Xls::Color::GetDarkViolet()); cs1->GetDataPoints()->Get(3)->GetDataFormat()->GetFill()->SetVisible(false); //Add a series with pie chart intrusive_ptr cs2 = static_cast>(chart->GetSeries()->Add(L"Pointer", ExcelChartType::Pie)); //Set the value cs2->SetValues(dynamic_pointer_cast(sheet->GetRange(L"D2:D4"))); cs2->SetUsePrimaryAxis(false); cs2->GetDataPoints()->Get(0)->GetDataLabels()->SetHasValue(true); cs2->GetDataFormat()->GetOptions()->SetFirstSliceAngle(270); cs2->GetDataPoints()->Get(0)->GetDataFormat()->GetFill()->SetVisible(false); cs2->GetDataPoints()->Get(1)->GetDataFormat()->GetFill()->SetFillType(ShapeFillType::SolidColor); cs2->GetDataPoints()->Get(1)->GetDataFormat()->GetFill()->SetForeColor(Spire::Xls::Color::GetBlack()); cs2->GetDataPoints()->Get(2)->GetDataFormat()->GetFill()->SetVisible(false); ``` -------------------------------- ### Get Category Labels from Chart Source: https://github.com/eiceblue/spire.xls-for-c/blob/main/C++ Examples/xls_c.md This C++ code snippet shows how to retrieve the category labels from a chart's primary category axis. It iterates through the cells of the category labels range and appends their values to a string. ```cpp //Get the cell range of the category labels std::wstring* content = new std::wstring(); intrusive_ptr cr = dynamic_pointer_cast(chart->GetPrimaryCategoryAxis())->GetCategoryLabels(); for (int i = 0; i < cr->GetCells()->GetCount(); i++) { auto cell = cr->GetCells()->GetItem(i); wstring value = cell->GetValue(); content->append(value + L"\r\n"); } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.