Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
Developers can add different drawing objects such as text boxes, check boxes, radio buttons, combo boxes, labels, buttons, lines, rectangles, arcs, ovals, spinners, scroll bars, group boxes etc. Aspose.Cells provides the Aspose::Cells::Drawing namespace which contains all the drawing objects. However, there are a few drawing objects or shapes that are not supported yet. Create these drawing objects in a designer spreadsheet using Microsoft Excel and then import the designer spreadsheet to Aspose.Cells. Aspose.Cells allows you to load these drawing objects from a designer spreadsheet and write them to a generated file.
One way to stress important information in a report is to use a text box. For example, add text to highlight the company name or to indicate the geographic region with the highest sales etc. Aspose.Cells provides the TextBoxCollection class, used to add a new text box to the collection. There is another class, TextBox, which represents a text box used to define all types of settings. It has some important members:
The following example creates two textboxes in the first worksheet of the workbook. The first text box is well-furnished with different format settings. The second is a simple one.
#include <iostream>
#include "Aspose.Cells.h"
using namespace Aspose::Cells;
int main()
{
Aspose::Cells::Startup();
// The path to the documents directory.
U16String dataDir(u"..\\Data\\01_SourceDirectory\\");
// Instantiate a new Workbook.
Workbook workbook;
// Get the first worksheet in the book.
Worksheet worksheet = workbook.GetWorksheets().Get(0);
// Add a new textbox to the collection.
int32_t textboxIndex = worksheet.GetTextBoxes().Add(2, 1, 160, 200);
// Get the textbox object.
TextBox textbox0 = worksheet.GetTextBoxes().Get(textboxIndex);
// Fill the text.
textbox0.SetText(u"ASPOSE______The .NET & JAVA Component Publisher!");
// Set the placement.
textbox0.SetPlacement(PlacementType::FreeFloating);
// Set the font color.
textbox0.GetFont().SetColor(Color::Blue());
// Set the font to bold.
textbox0.GetFont().SetIsBold(true);
// Set the font size.
textbox0.GetFont().SetSize(14);
// Set font attribute to italic.
textbox0.GetFont().SetIsItalic(true);
// Add a hyperlink to the textbox.
textbox0.AddHyperlink(u"http://www.aspose.com/");
// Get the fill format of the textbox.
FillFormat fillFormat = textbox0.GetFill();
// Get the line format type of the textbox.
LineFormat lineFormat = textbox0.GetLine();
// Set the line weight.
lineFormat.SetWeight(6.0);
// Set the dash style to squaredot.
lineFormat.SetDashStyle(MsoLineDashStyle::SquareDot);
// Add another textbox.
textboxIndex = worksheet.GetTextBoxes().Add(15, 4, 85, 120);
// Get the second textbox.
TextBox textbox1 = worksheet.GetTextBoxes().Get(textboxIndex);
// Input some text to it.
textbox1.SetText(u"This is another simple text box");
// Set the placement type as the textbox will move and resize with cells.
textbox1.SetPlacement(PlacementType::MoveAndSize);
// Save the excel file.
workbook.Save(dataDir + u"book1.out.xls");
Aspose::Cells::Cleanup();
}
Aspose.Cells also lets you access textboxes in the designer worksheets and manipulate them. Use the Worksheet.GetTextBoxes() property to get the textboxes collection in the sheet.
The following example uses the Microsoft Excel file that we created in the above example. It gets the text strings of the two textboxes and changes the text of the second textbox to save the file.
#include <iostream>
#include "Aspose.Cells.h"
using namespace Aspose::Cells;
int main()
{
Aspose::Cells::Startup();
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-C
// The path to the documents directory.
U16String srcDir(u"..\\Data\\01_SourceDirectory\\");
// Open the existing excel file.
Workbook workbook(srcDir + u"book1.xls");
// Get the first worksheet in the workbook.
Worksheet worksheet = workbook.GetWorksheets().Get(0);
// Get the first textbox object.
TextBox textbox0 = worksheet.GetTextBoxes().Get(0);
// Obtain the text in the first textbox.
U16String text0 = textbox0.GetText();
// Get the second textbox object.
TextBox textbox1 = worksheet.GetTextBoxes().Get(1);
// Obtain the text in the second textbox.
U16String text1 = textbox1.GetText();
// Change the text of the second textbox.
textbox1.SetText(u"This is an alternative text");
// Save the excel file.
workbook.Save(srcDir + u"output.out.xls");
Aspose::Cells::Cleanup();
}
Check boxes are handy if you want to provide a way for a user to choose between two options, such as true or false; yes or no. Aspose.Cells allows you to use check boxes in worksheets. For instance, you may have developed a financial projection worksheet in which you can either account for a particular acquisition or not. In this case, you might want to place a check box at the top of the worksheet. You can then link the status of this check box to another cell, so that if the check box is selected, the value of the cell is True; if it is not selected, the value of the cell is False.
To place a check box control in your worksheet, follow these steps:
Aspose.Cells provides the CheckBoxCollection class, which is used to add a new check box to the collection. There is another class, Aspose::Cells::Drawing::CheckBox, which represents a check box. It has some important members:
The following example shows how to add a checkbox to the worksheet.
#include <iostream>
#include <Aspose.Cells.h>
using namespace Aspose::Cells;
int main()
{
Aspose::Cells::Startup();
// Creating a new Workbook instance
Workbook excelbook = Workbook();
// Get the first worksheet
Worksheet worksheet = excelbook.GetWorksheets().Get(0);
// Add a checkbox to the first worksheet in the workbook
int32_t index = worksheet.GetCheckBoxes().Add(5, 5, 100, 120);
// Get the checkbox object
Drawing::CheckBox checkbox = worksheet.GetCheckBoxes().Get(index);
// Set its text string
checkbox.SetText(u"Click it!");
// Get cells collection and set B1 cell value
Cells cells = worksheet.GetCells();
Cell cellB1 = cells.Get(u"B1");
cellB1.PutValue(u"LnkCell");
// Set B1 cell as a linked cell for the checkbox
checkbox.SetLinkedCell(u"B1");
// Check the checkbox by default
checkbox.SetValue(true);
// Save the excel file
excelbook.Save(u"book1.out.xls");
Aspose::Cells::Cleanup();
}
A radio button, or an option button, is a control made of a round box. The user makes his or her decision by selecting the round box. A radio button is usually, if not always, accompanied by others. Such radio buttons appear and behave as a group. The user decides which button is valid by selecting only one of them. When the user clicks one button, it is filled. When one button in the group is selected, buttons of the same group are empty.
To place a Radio Button control in your worksheet, follow these steps:
Aspose::Cells::Drawing::ShapeCollection class provides a method named AddRadioButton, which is used to add a radio button control to a worksheet. The method returns an Aspose::Cells::Drawing::RadioButton object. The class Aspose::Cells::Drawing::RadioButton represents an option button. It has some important members:
The following example shows how to add radio buttons to a worksheet. The example adds three radio buttons representing age groups.
#include <iostream>
#include "Aspose.Cells.h"
using namespace Aspose::Cells;
int main()
{
Aspose::Cells::Startup();
// Path to the documents directory.
U16String srcDir(u"..\\Data\\01_SourceDirectory\\");
// Instantiate a new Workbook.
Workbook excelbook;
// Get the first worksheet
Worksheet sheet = excelbook.GetWorksheets().Get(0);
// Get cells collection
Cells cells = sheet.GetCells();
// Insert a value in C2
Cell cellC2 = cells.Get(u"C2");
cellC2.PutValue(u"Age Groups");
// Set the font text bold.
Style style = cellC2.GetStyle();
Font font = style.GetFont();
font.SetIsBold(true);
// Apply the style back
cellC2.SetStyle(style);
// Add radio buttons to the first sheet.
ShapeCollection shapes = sheet.GetShapes();
// Create first radio button
RadioButton radio1= shapes.AddRadioButton(3, 0, 2, 0, 30, 110);
// Set its text string.
radio1.SetText(u"20-29");
// Set A1 cell as a linked cell for the radio button.
radio1.SetLinkedCell(u"A1");
// Make the radio button 3-D.
radio1.SetShadow(true);
// Set the weight of the radio button.
LineFormat line1 = radio1.GetLine();
line1.SetWeight(4);
// Set the dash style of the radio button.
line1.SetDashStyle(MsoLineDashStyle::Solid);
// Create second radio button
RadioButton radio2 = shapes.AddRadioButton(6, 0, 2, 0, 30, 110);
// Set its text string.
radio2.SetText(u"30-39");
// Set A1 cell as a linked cell for the radio button.
radio2.SetLinkedCell(u"A1");
// Make the radio button 3-D.
radio2.SetShadow(true);
// Set the weight of the radio button.
LineFormat line2 = radio2.GetLine();
line2.SetWeight(4);
// Set the dash style of the radio button.
line2.SetDashStyle(MsoLineDashStyle::Solid);
// Create third radio button
RadioButton radio3=shapes.AddRadioButton(9, 0, 2, 0, 30, 110);
// Set its text string.
radio3.SetText(u"40-49");
// Set A1 cell as a linked cell for the radio button.
radio3.SetLinkedCell(u"A1");
// Make the radio button 3-D.
radio3.SetShadow(true);
// Set the weight of the radio button.
LineFormat line3 = radio3.GetLine();
line3.SetWeight(4);
// Set the dash style of the radio button.
line3.SetDashStyle(MsoLineDashStyle::Solid);
// Save the excel file.
excelbook.Save(srcDir + u"book1.out.xls");
Aspose::Cells::Cleanup();
}
To make data entry easier, or to limit entries to certain items that you define, you can create a combo box, or drop-down list of valid entries that is compiled from cells elsewhere on the worksheet. When you create a drop-down list for a cell, it displays an arrow next to that cell. To enter information in that cell, click the arrow, and then click the entry that you want.
To place a combo box control in your worksheet, follow these steps:
The Aspose::Cells::Drawing::ShapeCollection class provides a method named AddComboBox, which is used to add a combo box control to a worksheet. The method returns an Aspose::Cells::Drawing::ComboBox object. The class Aspose::Cells::Drawing::ComboBox represents a combo box. It has some important members:
The following example shows how to add a combo box to the worksheet.
#include <iostream>
#include "Aspose.Cells.h"
using namespace Aspose::Cells;
int main()
{
Aspose::Cells::Startup();
// Path to the documents directory.
U16String srcDir(u"..\\Data\\01_SourceDirectory\\");
// Create a new Workbook.
Workbook workbook;
// Get the first worksheet.
Worksheet sheet = workbook.GetWorksheets().Get(0);
// Get the worksheet cells collection.
Cells cells = sheet.GetCells();
// Input a value.
Cell cellB3 = cells.Get(u"B3");
cellB3.PutValue(u"Employee:");
// Set it bold.
Style style = cellB3.GetStyle();
style.SetIsBorderApplied(true);
cellB3.SetStyle(style);
// Input some values that denote the input range for the combo box.
cells.Get(u"A2").PutValue(u"Emp001");
cells.Get(u"A3").PutValue(u"Emp002");
cells.Get(u"A4").PutValue(u"Emp003");
cells.Get(u"A5").PutValue(u"Emp004");
cells.Get(u"A6").PutValue(u"Emp005");
cells.Get(u"A7").PutValue(u"Emp006");
// Add a new combo box.
ComboBox comboBox = sheet.GetShapes().AddComboBox(2, 0, 2, 0, 22, 100);
// Cleanup Aspose resources
Aspose::Cells::Cleanup();
return 0;
}
Labels are a means of give users information about a speadsheet’s contents. Aspose.Cells makes it possible to add and manipulate labels in a worksheet. The ShapeCollection class provides a method named AddLabel, used to add a label control to the worksheet. The method returns a Label object. The class Label represents a label in the worksheet. It has some important members:
The following example shows how to add a label to the worksheet.
#include <iostream>
#include "Aspose.Cells.h"
using namespace Aspose::Cells;
using namespace Aspose::Cells::Drawing;
int main()
{
Aspose::Cells::Startup();
// Source directory path
U16String srcDir(u"..\\Data\\01_SourceDirectory\\");
// Output directory path
U16String outDir(u"..\\Data\\02_OutputDirectory\\");
// Create a new Workbook
Workbook workbook;
// Get the first worksheet in the workbook
Worksheet sheet = workbook.GetWorksheets().Get(0);
// Add a new label to the worksheet
Label label = sheet.GetShapes().AddLabel(2, 0, 2, 0, 60, 120);
// Set the caption of the label
label.SetText(u"This is a Label");
// Set the Placement Type, the way the Label is attached to the cells
label.SetPlacement(PlacementType::FreeFloating);
// Save the file
workbook.Save(outDir + u"book1.out.xls");
std::cout << "Label added successfully!" << std::endl;
Aspose::Cells::Cleanup();
}
A list box control creates a list control that allows single or multiple item selection.
To place a list box control in a worksheet:
The ShapeCollection class provides a method named AddListBox, which is used to add a list box control to a worksheet. The method returns a Aspose::Cells::Drawing::ListBox object. The class ListBox represents a list box. It has some important members:
The following example shows how to add a list box to the worksheet.
#include <iostream>
#include "Aspose.Cells.h"
using namespace Aspose::Cells;
using namespace Aspose::Cells::Drawing;
int main()
{
Aspose::Cells::Startup();
// Source directory path
U16String outDir(u"..\\Data\\02_OutputDirectory\\");
// Create a new Workbook
Workbook workbook;
// Get the first worksheet
Worksheet sheet = workbook.GetWorksheets().Get(0);
// Get the worksheet cells collection
Cells cells = sheet.GetCells();
// Input a value
cells.Get(U16String(u"B3")).PutValue(U16String(u"Choose Dept:"));
// Set it bold
Style style = cells.Get(U16String(u"B3")).GetStyle();
Font font = style.GetFont();
font.SetIsBold(true);
cells.Get(U16String(u"B3")).SetStyle(style);
// Input some values that denote the input range for the list box
cells.Get(U16String(u"A2")).PutValue(U16String(u"Sales"));
cells.Get(U16String(u"A3")).PutValue(U16String(u"Finance"));
cells.Get(U16String(u"A4")).PutValue(U16String(u"MIS"));
cells.Get(U16String(u"A5")).PutValue(U16String(u"R&D"));
cells.Get(U16String(u"A6")).PutValue(U16String(u"Marketing"));
cells.Get(U16String(u"A7")).PutValue(U16String(u"HRA"));
// Add a new list box
ListBox listBox = sheet.GetShapes().AddListBox(2, 0, 3, 0, 122, 100);
// Set the placement type
listBox.SetPlacement(PlacementType::FreeFloating);
// Set the linked cell
listBox.SetLinkedCell(U16String(u"A1"));
// Set the input range
listBox.SetInputRange(U16String(u"A2:A7"));
// Set the selection type
listBox.SetSelectionType(SelectionType::Single);
// Set the list box with 3-D shading
listBox.SetShadow(true);
// Save the file
workbook.Save(outDir + u"book1.out.xls");
Aspose::Cells::Cleanup();
}
Buttons are useful to perform some actions. Sometimes, it is useful to assign a VBA Macro to the button or assign a hyperlink to open a web page.
To place a button control in your worksheet:
The ShapeCollection class provides a method named AddButton, used to add a button control to the worksheet. The method returns an Aspose::Cells::Drawing::Button object. The class Aspose::Cells::Drawing::Button represents a button. It has some important members:
The following example shows how to add a button to the worksheet.
#include <iostream>
#include "Aspose.Cells.h"
using namespace Aspose::Cells;
int main()
{
Aspose::Cells::Startup();
// Source directory path
U16String srcDir(u"..\\Data\\01_SourceDirectory\\");
// Create a new Workbook
Workbook workbook;
// Get the first worksheet in the workbook
Worksheet sheet = workbook.GetWorksheets().Get(0);
// Add a new button to the worksheet
Drawing::Button button = sheet.GetShapes().AddButton(2, 0, 2, 0, 28, 80);
// Set the caption of the button
button.SetText(u"Aspose");
// Set the Placement Type, the way the Button is attached to the cells
button.SetPlacement(PlacementType::FreeFloating);
// Set the font name
Font font = button.GetFont();
font.SetName(u"Tahoma");
// Set the caption string bold
font.SetIsBold(true);
// Set the color to blue
font.SetColor(Color::Blue());
// Set the hyperlink for the button
button.AddHyperlink(u"http://www.aspose.com/");
// Save the file
workbook.Save(srcDir + u"book1.out.xls");
std::cout << "Button added successfully!" << std::endl;
Aspose::Cells::Cleanup();
}
The ShapeCollection class provides a method named AddLine, which is used to add a line shape to the worksheet. The method returns a LineShape object. The class LineShape represents a line. It has some important members:
The following example shows how to add lines to the worksheet. It creates three lines with different styles.
#include <iostream>
#include "Aspose.Cells.h"
using namespace Aspose::Cells;
using namespace Aspose::Cells::Drawing;
int main()
{
Aspose::Cells::Startup();
// Source directory path
U16String srcDir(u"..\\Data\\01_SourceDirectory\\");
// Output directory path
U16String outDir(u"..\\Data\\02_OutputDirectory\\");
// Instantiate a new Workbook
Workbook workbook;
// Get the first worksheet in the book
Worksheet worksheet = workbook.GetWorksheets().Get(0);
// Add a new line to the worksheet
LineShape line1 = worksheet.GetShapes().AddLine(5, 0, 1, 0, 0, 250);
// Set the line dash style
line1.GetLine().SetDashStyle(MsoLineDashStyle::Solid);
// Set the placement
line1.SetPlacement(PlacementType::FreeFloating);
// Add another line to the worksheet
LineShape line2 = worksheet.GetShapes().AddLine(7, 0, 1, 0, 85, 250);
// Set the line dash style
line2.GetLine().SetDashStyle(MsoLineDashStyle::DashLongDash);
// Set the weight of the line
line2.GetLine().SetWeight(4);
// Set the placement
line2.SetPlacement(PlacementType::FreeFloating);
// Add the third line to the worksheet
LineShape line3 = worksheet.GetShapes().AddLine(13, 0, 1, 0, 0, 250);
// Set the line dash style
line3.GetLine().SetDashStyle(MsoLineDashStyle::Solid);
// Set the placement
line3.SetPlacement(PlacementType::FreeFloating);
// Make the gridlines invisible in the first worksheet
worksheet.SetIsGridlinesVisible(false);
// Save the excel file
workbook.Save(outDir + u"book1.out.xls");
std::cout << "Lines added successfully to the worksheet!" << std::endl;
Aspose::Cells::Cleanup();
}
Aspose.Cells also allows you to draw arrow lines. It is possible to add an arrowhead to a line, and to format the line. For example, you can change the color of the line, or specify the weight and style of the line.
The following example shows how to add an arrowhead to a line.
#include <iostream>
#include "Aspose.Cells.h"
using namespace Aspose::Cells;
using namespace Aspose::Cells::Drawing;
int main()
{
Aspose::Cells::Startup();
// Source directory path
U16String srcDir(u"..\\Data\\01_SourceDirectory\\");
// Output directory path
U16String outDir(u"..\\Data\\02_OutputDirectory\\");
// Instantiate a new Workbook
Workbook workbook;
// Get the first worksheet in the book
Worksheet worksheet = workbook.GetWorksheets().Get(0);
// Add a line to the worksheet
LineShape line2 = worksheet.GetShapes().AddLine(7, 0, 1, 0, 85, 250);
// Set the line color
line2.GetLine().SetFillType(FillType::Solid);
line2.GetLine().GetSolidFill().SetColor(Color::Blue());
// Set the weight of the line
line2.GetLine().SetWeight(3);
// Set the placement
line2.SetPlacement(PlacementType::FreeFloating);
// Set the line arrows
line2.GetLine().SetEndArrowheadWidth(MsoArrowheadWidth::Medium);
line2.GetLine().SetEndArrowheadStyle(MsoArrowheadStyle::Arrow);
line2.GetLine().SetEndArrowheadLength(MsoArrowheadLength::Medium);
line2.GetLine().SetBeginArrowheadStyle(MsoArrowheadStyle::ArrowDiamond);
line2.GetLine().SetBeginArrowheadLength(MsoArrowheadLength::Medium);
// Make the gridlines invisible in the first worksheet
workbook.GetWorksheets().Get(0).SetIsGridlinesVisible(false);
// Save the excel file
workbook.Save(outDir + u"book1.out.xlsx");
Aspose::Cells::Cleanup();
}
Aspose.Cells allows you to draw rectangle shapes in your worksheets. You may create a rectangle, square etc. You are also allowed to format the filling color and border line color of the control. For example, you can change the color of the rectangle, set the shading color, specify the weight and style of the rectangle for your need.
The ShapeCollection class provides a method named AddRectangle, which is used to add a rectangle shape to a worksheet. The method returns Aspose.Cells.Drawing.RectangleShape object. The class Aspose.Cells.Drawing.RectangleShape represents a rectangle. It has some important members:
The following example shows how to add a rectangle to the worksheet.
#include <iostream>
#include "Aspose.Cells.h"
using namespace Aspose::Cells;
using namespace Aspose::Cells::Drawing;
int main()
{
Aspose::Cells::Startup();
// Source directory path
U16String outDir(u"..\\Data\\02_OutputDirectory\\");
// Instantiate a new Workbook
Workbook excelbook;
// Add a rectangle control to the first worksheet
RectangleShape rectangle = excelbook.GetWorksheets().Get(0).GetShapes().AddRectangle(3, 0, 2, 0, 70, 130);
// Set the placement of the rectangle
rectangle.SetPlacement(PlacementType::FreeFloating);
// Set the line weight
rectangle.GetLine().SetWeight(4);
// Set the dash style of the rectangle
rectangle.GetLine().SetDashStyle(MsoLineDashStyle::Solid);
// Save the Excel file
excelbook.Save(outDir + u"book1.out.xls");
std::cout << "Rectangle shape added and file saved successfully!" << std::endl;
Aspose::Cells::Cleanup();
}
Aspose.Cells allows you to draw arc shapes in your worksheets. You may create simple and filled arcs. You are allowed to format the filling color and border line color of the control. For example, you can specify / change the color of the arc, set the shading color, specify the weight and style of the shape for your need.
The ShapeCollection class provides a method named AddArc, which is used to add an arc shape to a worksheet. The method returns an Aspose.Cells.Drawing.ArcShape object. The class Aspose.Cells.Drawing.ArcShape represents an arc. It has some important members:
The following example shows how to add arc shapes to the worksheet. The example creates two arc shapes: one is filled and other is simple.
#include <iostream>
#include "Aspose.Cells.h"
using namespace Aspose::Cells;
using namespace Aspose::Cells::Drawing;
int main()
{
Aspose::Cells::Startup();
// Source directory path
U16String srcDir(u"..\\Data\\01_SourceDirectory\\");
// Output directory path
U16String outDir(u"..\\Data\\02_OutputDirectory\\");
// Instantiate a new Workbook
Workbook excelbook;
// Get the first worksheet
Worksheet worksheet = excelbook.GetWorksheets().Get(0);
// Add an arc shape
ArcShape arc1 = worksheet.GetShapes().AddArc(2, 0, 2, 0, 130, 130);
// Set the fill shape color
arc1.GetFill().SetFillType(FillType::Solid);
arc1.GetFill().GetSolidFill().SetColor(Color::Blue());
// Set the placement of the arc
arc1.SetPlacement(PlacementType::FreeFloating);
// Set the line weight
arc1.GetLine().SetWeight(1);
// Set the dash style of the arc
arc1.GetLine().SetDashStyle(MsoLineDashStyle::Solid);
// Add another arc shape
ArcShape arc2 = worksheet.GetShapes().AddArc(9, 0, 2, 0, 130, 130);
// Set the line color
arc2.GetLine().SetFillType(FillType::Solid);
arc2.GetLine().GetSolidFill().SetColor(Color::Blue());
// Set the placement of the arc
arc2.SetPlacement(PlacementType::FreeFloating);
// Set the line weight
arc2.GetLine().SetWeight(1);
// Set the dash style of the arc
arc2.GetLine().SetDashStyle(MsoLineDashStyle::Solid);
// Save the excel file
U16String outputPath = outDir + u"book1.out.xls";
excelbook.Save(outputPath);
std::cout << "Excel file saved successfully!" << std::endl;
Aspose::Cells::Cleanup();
}
Aspose.Cells allows you to draw oval shapes in worksheets. Create simple and filled oval shapes and format the filling color and border line color of the control. For example, you can specify / change the color of the oval, set the shading color, specify the weight and style of the shape.
The ShapeCollection class provides a method named AddOval, which is used to add an oval shape to a worksheet. The method returns an Aspose.Cells.Drawing.Oval object. The class Aspose.Cells.Drawing.Oval represents an oval shape. It has some important members:
The following example shows how to add oval shapes to the worksheet. The example creates two oval shapes: one is filled oval other is a simple circle.
#include <iostream>
#include "Aspose.Cells.h"
using namespace Aspose::Cells;
using namespace Aspose::Cells::Drawing;
int main()
{
Aspose::Cells::Startup();
// Source directory path
U16String srcDir(u"..\\Data\\01_SourceDirectory\\");
// Output directory path
U16String outDir(u"..\\Data\\02_OutputDirectory\\");
// Instantiate a new Workbook
Workbook excelbook;
// Add an oval shape
Oval oval1 = excelbook.GetWorksheets().Get(0).GetShapes().AddOval(2, 0, 2, 0, 130, 160);
// Set the placement of the oval
oval1.SetPlacement(PlacementType::FreeFloating);
// Set the line weight
oval1.GetLine().SetWeight(1);
// Set the dash style of the oval
oval1.GetLine().SetDashStyle(MsoLineDashStyle::Solid);
// Add another oval (circle) shape
Oval oval2 = excelbook.GetWorksheets().Get(0).GetShapes().AddOval(9, 0, 2, 15, 130, 130);
// Set the placement of the oval
oval2.SetPlacement(PlacementType::FreeFloating);
// Set the line weight
oval2.GetLine().SetWeight(1);
// Set the dash style of the oval
oval2.GetLine().SetDashStyle(MsoLineDashStyle::Solid);
// Save the excel file
excelbook.Save(outDir + u"book1.out.xls");
Aspose::Cells::Cleanup();
}
A spin box is a text box attached to a button (called a spin button) consisting of an up arrow and down arrow that you click to incrementally change the value in the text box. By using spin boxes, you can see how input changes to your financial model will alter the model outputs. You can attach a spin button to a specific input cell. While you click the up arrow or down arrow on the spin button, the integer value in the targeted input cell increases or decreases. Aspose.Cells allows you to create spinners in your worksheets.
To place a spin box control in your worksheet:
The ShapeCollection class provides a method named AddSpinner, which is used to add a spin box control to a worksheet. The method returns an Aspose.Cells.Drawing.Spinner object. The class Aspose.Cells.Drawing.Spinner represents a spin box. It has some important members:
The following example shows how to add a spin box to the worksheet.
#include <iostream>
#include "Aspose.Cells.h"
using namespace Aspose::Cells;
using namespace Aspose::Cells::Drawing;
int main()
{
Aspose::Cells::Startup();
// Source directory path
U16String srcDir(u"..\\Data\\01_SourceDirectory\\");
// Output directory path
U16String outDir(u"..\\Data\\02_OutputDirectory\\");
// Instantiate a new Workbook
Workbook excelbook;
// Get the first worksheet
Worksheet worksheet = excelbook.GetWorksheets().Get(0);
// Get the worksheet cells
Cells cells = worksheet.GetCells();
// Input a string value into A1 cell
cells.Get(u"A1").PutValue(u"Select Value:");
// Set the font color of the cell
Style styleA1 = cells.Get(u"A1").GetStyle();
styleA1.GetFont().SetColor(Color::Red());
// Set the font text bold
styleA1.GetFont().SetIsBold(true);
// Input value into A2 cell
cells.Get(u"A2").PutValue(0);
// Set the shading color to black with solid background
Style styleA2 = cells.Get(u"A2").GetStyle();
styleA2.SetForegroundColor(Color::Black());
styleA2.SetPattern(BackgroundType::Solid);
// Set the font color of the cell
styleA2.GetFont().SetColor(Color::White());
// Set the font text bold
styleA2.GetFont().SetIsBold(true);
// Add a spinner control
Spinner spinner = worksheet.GetShapes().AddSpinner(1, 0, 1, 0, 20, 18);
// Set the placement type of the spinner
spinner.SetPlacement(PlacementType::FreeFloating);
// Set the linked cell for the control
spinner.SetLinkedCell(u"A2");
// Set the maximum value
spinner.SetMax(10);
// Set the minimum value
spinner.SetMin(0);
// Set the incremental change for the control
spinner.SetIncrementalChange(2);
// Set it 3-D shading
spinner.SetShadow(true);
// Save the excel file
excelbook.Save(outDir + u"book1.out.xls");
std::cout << "File saved successfully." << std::endl;
Aspose::Cells::Cleanup();
}
A scroll bar control is used to help select data on a worksheet in a similar way to a spin box control. By adding the control to a worksheet and linking it to a cell, it is possible to return a numeric value for the current position of the control.
When you click the up or down control on the scroll bar, cell G1 is updated to a number that indicates the current value of the scroll bar plus or minus the incremental change of the scroll bar.
The ShapeCollection class provides a method named AddScrollBar, which is used to add a scroll bar control to the worksheet. The method returns an Aspose.Cells.Drawing.ScrollBar object. The class Aspose.Cells.Drawing.ScrollBar represents a scroll bar. It has some important members:
The following example shows how to add a scroll bar to the worksheet.
#include <iostream>
#include "Aspose.Cells.h"
using namespace Aspose::Cells;
using namespace Aspose::Cells::Drawing;
int main()
{
Aspose::Cells::Startup();
// Source directory path
U16String srcDir(u"..\\Data\\01_SourceDirectory\\");
// Output directory path
U16String outDir(u"..\\Data\\02_OutputDirectory\\");
// Instantiate a new Workbook
Workbook excelbook;
// Get the first worksheet
Worksheet worksheet = excelbook.GetWorksheets().Get(0);
// Invisible the gridlines of the worksheet
worksheet.SetIsGridlinesVisible(false);
// Get the worksheet cells
Cells cells = worksheet.GetCells();
// Input a value into A1 cell
cells.Get(u"A1").PutValue(1);
// Set the font color of the cell
cells.Get(u"A1").GetStyle().GetFont().SetColor(Color::Maroon());
// Set the font text bold
cells.Get(u"A1").GetStyle().GetFont().SetIsBold(true);
// Set the number format
cells.Get(u"A1").GetStyle().SetNumber(1);
// Add a scrollbar control
ScrollBar scrollbar = worksheet.GetShapes().AddScrollBar(0, 0, 1, 0, 125, 20);
// Set the placement type of the scrollbar
scrollbar.SetPlacement(PlacementType::FreeFloating);
// Set the linked cell for the control
scrollbar.SetLinkedCell(u"A1");
// Set the maximum value
scrollbar.SetMax(20);
// Set the minimum value
scrollbar.SetMin(1);
// Set the incr. change for the control
scrollbar.SetIncrementalChange(1);
// Set the page change attribute
scrollbar.SetPageChange(5);
// Set it 3-D shading
scrollbar.SetShadow(true);
// Save the excel file
excelbook.Save(outDir + u"book1.out.xls");
std::cout << "Scrollbar added successfully!" << std::endl;
Aspose::Cells::Cleanup();
}
Sometimes you do need to implement radio buttons or other controls which belong to a certain group, you can implement by including either a group box or rectangle control. Any of these two objects would serve as the delimiter of the group. After adding one of these shapes, you can then add two or more radio buttons or other group objects.
To place a group box control in your worksheet and place controls in it:
The ShapeCollection class provides a method named AddGroupBox, which is used to add a group box control to the worksheet. The method returns an Aspose.Cells.Drawing.GroupBox object. Moreover, the Group method of the ShapeCollection class groups the shapes, it takes a Shape array as parameter and returns a GroupShape object. The class Aspose.Cells.Drawing.GroupBox represents a group box. It has some important members:
The following example shows how to add a group box and group the controls in the worksheet.
#include <iostream>
#include "Aspose.Cells.h"
using namespace Aspose::Cells;
using namespace Aspose::Cells::Drawing;
int main()
{
Aspose::Cells::Startup();
// Source directory path
U16String srcDir(u"..\\Data\\01_SourceDirectory\\");
// Output directory path
U16String outDir(u"..\\Data\\02_OutputDirectory\\");
// Instantiate a new Workbook
Workbook excelbook;
// Add a group box to the first worksheet
Worksheet worksheet = excelbook.GetWorksheets().Get(0);
GroupBox box = worksheet.GetShapes().AddGroupBox(1, 0, 1, 0, 300, 250);
// Set the caption of the group box
box.SetText(u"Age Groups");
box.SetPlacement(PlacementType::FreeFloating);
// Make it 2-D box
box.SetShadow(false);
// Add a radio button
RadioButton radio1 = worksheet.GetShapes().AddRadioButton(3, 0, 2, 0, 30, 110);
// Set its text string
radio1.SetText(u"20-29");
// Set A1 cell as a linked cell for the radio button
radio1.SetLinkedCell(u"A1");
// Make the radio button 3-D
radio1.SetShadow(true);
// Set the weight of the radio button
radio1.GetLine().SetWeight(4);
// Set the dash style of the radio button
radio1.GetLine().SetDashStyle(MsoLineDashStyle::Solid);
// Add another radio button
RadioButton radio2 = worksheet.GetShapes().AddRadioButton(6, 0, 2, 0, 30, 110);
// Set its text string
radio2.SetText(u"30-39");
// Set A1 cell as a linked cell for the radio button
radio2.SetLinkedCell(u"A1");
// Make the radio button 3-D
radio2.SetShadow(true);
// Set the weight of the radio button
radio2.GetLine().SetWeight(4);
// Set the dash style of the radio button
radio2.GetLine().SetDashStyle(MsoLineDashStyle::Solid);
// Add another radio button
RadioButton radio3 = worksheet.GetShapes().AddRadioButton(9, 0, 2, 0, 30, 110);
// Set its text string
radio3.SetText(u"40-49");
// Set A1 cell as a linked cell for the radio button
radio3.SetLinkedCell(u"A1");
// Make the radio button 3-D
radio3.SetShadow(true);
// Set the weight of the radio button
radio3.GetLine().SetWeight(4);
// Set the dash style of the radio button
radio3.GetLine().SetDashStyle(MsoLineDashStyle::Solid);
// Get the shapes
Vector<Shape> shapeobjects{ box, radio1, radio2, radio3 };
// Group the shapes
GroupShape group = worksheet.GetShapes().Group(shapeobjects);
// Save the excel file
excelbook.Save(outDir + u"book1.out.xls");
std::cout << "File saved successfully!" << std::endl;
Aspose::Cells::Cleanup();
}
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.