管理控制

介绍

开发人员可以添加不同的绘图对象,例如文本框、复选框、单选按钮、组合框、标签、按钮、线条、矩形、圆弧、椭圆、旋转器、滚动条、组框等。Aspose.Cells 提供 Aspose.Cells.Drawing 命名空间,其中包含所有绘图对象。但是,尚不支持一些绘图对象或形状。使用 Microsoft Excel 在设计器电子表格中创建这些绘图对象,然后将设计器电子表格导入 Aspose.Cells。Aspose.Cells 允许您从设计器电子表格加载这些绘图对象并将它们写入生成的文件。

将文本框控件添加到工作表

在报告中强调重要信息的一种方法是使用文本框。例如,添加文本以突出显示公司名称或指示销售额最高的地理区域等。Aspose.Cells 提供文本框集合类,用于向集合中添加新的文本框。还有一个类,文本框表示用于定义所有类型设置的文本框。它有一些重要的成员:

下面的示例在工作簿的第一个工作表中创建两个文本框。第一个文本框配备了不同的格式设置。第二个是简单的。

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
// Create directory if it is not already present.
bool IsExists = System.IO.Directory.Exists(dataDir);
if (!IsExists)
System.IO.Directory.CreateDirectory(dataDir);
// Instantiate a new Workbook.
Workbook workbook = new Workbook();
// Get the first worksheet in the book.
Worksheet worksheet = workbook.Worksheets[0];
// Add a new textbox to the collection.
int textboxIndex = worksheet.TextBoxes.Add(2, 1, 160, 200);
// Get the textbox object.
Aspose.Cells.Drawing.TextBox textbox0 = worksheet.TextBoxes[textboxIndex];
// Fill the text.
textbox0.Text = "ASPOSE______The .NET & JAVA Component Publisher!";
// Get the textbox text frame.
//MsoTextFrame textframe0 = textbox0.TextFrame;
// Set the textbox to adjust it according to its contents.
//textframe0.AutoSize = true;
// Set the placement.
textbox0.Placement = PlacementType.FreeFloating;
// Set the font color.
textbox0.Font.Color = Color.Blue;
// Set the font to bold.
textbox0.Font.IsBold = true;
// Set the font size.
textbox0.Font.Size = 14;
// Set font attribute to italic.
textbox0.Font.IsItalic = true;
// Add a hyperlink to the textbox.
textbox0.AddHyperlink("http:// Www.aspose.com/");
// Get the filformat of the textbox.
Aspose.Cells.Drawing.FillFormat fillformat = textbox0.Fill;
// Get the lineformat type of the textbox.
Aspose.Cells.Drawing.LineFormat lineformat = textbox0.Line;
// Set the line weight.
lineformat.Weight = 6;
// Set the dash style to squaredot.
lineformat.DashStyle = MsoLineDashStyle.SquareDot;
// Add another textbox.
textboxIndex = worksheet.TextBoxes.Add(15, 4, 85, 120);
// Get the second textbox.
Aspose.Cells.Drawing.TextBox textbox1 = worksheet.TextBoxes[textboxIndex];
// Input some text to it.
textbox1.Text = "This is another simple text box";
// Set the placement type as the textbox will move and
// Resize with cells.
textbox1.Placement = PlacementType.MoveAndSize;
// Save the excel file.
workbook.Save(dataDir + "book1.out.xls");

在 Designer 电子表格中操作文本框控件

Aspose.Cells 还允许您访问设计器工作表中的文本框并对其进行操作。使用工作表.文本框属性以获取工作表中的文本框集合。

以下示例使用我们在上例中创建的 Microsoft Excel 文件。它获取两个文本框的文本字符串并更改第二个文本框的文本以保存文件。

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
// Instantiate a new Workbook.
// Open the existing excel file.
Workbook workbook = new Workbook(dataDir + "book1.xls");
// Get the first worksheet in the book.
Worksheet worksheet = workbook.Worksheets[0];
// Get the first textbox object.
Aspose.Cells.Drawing.TextBox textbox0 = worksheet.TextBoxes[0];
// Obtain the text in the first textbox.
string text0 = textbox0.Text;
// Get the second textbox object.
Aspose.Cells.Drawing.TextBox textbox1 = worksheet.TextBoxes[1];
// Obtain the text in the second textbox.
string text1 = textbox1.Text;
// Change the text of the second textbox.
textbox1.Text = "This is an alternative text";
// Save the excel file.
workbook.Save(dataDir + "output.out.xls");

将复选框控件添加到工作表

如果您想为用户提供一种在两个选项(例如 true 或 false)之间进行选择的方式,则复选框很方便;是还是不是。 Aspose.Cells 允许您在工作表中使用复选框。例如,您可能已经开发了一个财务预测工作表,您可以在其中考虑或不考虑特定的收购。在这种情况下,您可能希望在工作表顶部放置一个复选框。然后,您可以将此复选框的状态链接到另一个单元格,这样,如果复选框被选中,则该单元格的值为 True;如果未选中,则单元格的值为 False。

使用 Microsoft Excel

要在工作表中放置复选框控件,请执行以下步骤:

  1. 确保显示窗体工具栏。
  2. 点击复选框窗体工具栏上的工具。
  3. 在您的工作表区域中,单击并拖动以定义将容纳复选框和复选框旁边标签的矩形。
  4. 放置复选框后,将鼠标光标移动到标签区域并更改标签。
  5. 在里面Cell 链接字段,指定此复选框应链接到的单元格的地址。
  6. 点击好的.

使用 Aspose.Cells

Aspose.Cells 提供了复选框集合类,用于向集合中添加新的复选框。还有一个类,Aspose.Cells.Drawing.CheckBox,代表一个复选框。它有一些重要的成员:

  • 链接单元格属性指定链接到复选框的单元格。
  • 文本属性指定与复选框关联的文本字符串。它是复选框的标签。
  • 价值属性指定复选框是否被选中。

以下示例显示如何向工作表添加复选框。

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
// Create directory if it is not already present.
bool IsExists = System.IO.Directory.Exists(dataDir);
if (!IsExists)
System.IO.Directory.CreateDirectory(dataDir);
// Instantiate a new Workbook.
Workbook excelbook = new Workbook();
// Add a checkbox to the first worksheet in the workbook.
int index = excelbook.Worksheets[0].CheckBoxes.Add(5, 5, 100, 120);
// Get the checkbox object.
Aspose.Cells.Drawing.CheckBox checkbox = excelbook.Worksheets[0].CheckBoxes[index];
// Set its text string.
checkbox.Text = "Click it!";
// Put a value into B1 cell.
excelbook.Worksheets[0].Cells["B1"].PutValue("LnkCell");
// Set B1 cell as a linked cell for the checkbox.
checkbox.LinkedCell = "B1";
// Check the checkbox by default.
checkbox.Value = true;
// Save the excel file.
excelbook.Save(dataDir + "book1.out.xls");

将单选按钮控件添加到工作表

单选按钮或选项按钮是由圆形框组成的控件。用户通过选择圆形框来做出他或她的决定。单选按钮通常(如果不是总是)伴随其他按钮。这样的单选按钮作为一个组出现和运行。用户通过仅选择其中一个按钮来决定哪个按钮有效。当用户单击一个按钮时,它就会被填充。当组中的一个按钮被选中时,同一组按钮为空。

使用 Microsoft Excel

要在工作表中放置单选按钮控件,请按照下列步骤操作:

  1. 确保形式显示工具栏。
  2. 点击选项按钮工具。
  3. 在工作表中,单击并拖动以定义将容纳选项按钮和选项按钮旁边标签的矩形。
  4. 将单选按钮放置在工作表中后,将鼠标光标移动到标签区域并更改标签。
  5. 在里面Cell 链接字段,指定此单选按钮应链接到的单元格的地址。
  6. 点击好的.

使用 Aspose.Cells

Aspose.Cells.Drawing.ShapeCollection类提供了一个名为添加单选按钮,用于将单选按钮控件添加到工作表。该方法返回一个Aspose.Cells.Drawing.RadioButton目的。班级Aspose.Cells.Drawing.RadioButton代表一个选项按钮。它有一些重要的成员:

  • 链接单元格属性指定链接到单选按钮的单元格。
  • 文本属性指定与单选按钮关联的文本字符串。它是单选按钮的标签。
  • 已检查属性指定单选按钮是否被选中。
  • 填充格式属性指定单选按钮的填充格式。
  • 行格式属性指定选项按钮的行格式样式。

以下示例显示如何将单选按钮添加到工作表。该示例添加了三个代表年龄组的单选按钮。

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
// Create directory if it is not already present.
bool IsExists = System.IO.Directory.Exists(dataDir);
if (!IsExists)
System.IO.Directory.CreateDirectory(dataDir);
// Instantiate a new Workbook.
Workbook excelbook = new Workbook();
// Insert a value.
excelbook.Worksheets[0].Cells["C2"].PutValue("Age Groups");
// Set the font text bold.
excelbook.Worksheets[0].Cells["C2"].GetStyle().Font.IsBold = true;
// Add a radio button to the first sheet.
Aspose.Cells.Drawing.RadioButton radio1 = excelbook.Worksheets[0].Shapes.AddRadioButton(3, 0, 2, 0, 30, 110);
// Set its text string.
radio1.Text = "20-29";
// Set A1 cell as a linked cell for the radio button.
radio1.LinkedCell = "A1";
// Make the radio button 3-D.
radio1.Shadow = true;
// Set the weight of the radio button.
radio1.Line.Weight = 4;
// Set the dash style of the radio button.
radio1.Line.DashStyle = MsoLineDashStyle.Solid;
// Add another radio button to the first sheet.
Aspose.Cells.Drawing.RadioButton radio2 = excelbook.Worksheets[0].Shapes.AddRadioButton(6, 0, 2, 0, 30, 110);
// Set its text string.
radio2.Text = "30-39";
// Set A1 cell as a linked cell for the radio button.
radio2.LinkedCell = "A1";
// Make the radio button 3-D.
radio2.Shadow = true;
// Set the weight of the radio button.
radio2.Line.Weight = 4;
// Set the dash style of the radio button.
radio2.Line.DashStyle = MsoLineDashStyle.Solid;
// Add another radio button to the first sheet.
Aspose.Cells.Drawing.RadioButton radio3 = excelbook.Worksheets[0].Shapes.AddRadioButton(9, 0, 2, 0, 30, 110);
// Set its text string.
radio3.Text = "40-49";
// Set A1 cell as a linked cell for the radio button.
radio3.LinkedCell = "A1";
// Make the radio button 3-D.
radio3.Shadow = true;
// Set the weight of the radio button.
radio3.Line.Weight = 4;
// Set the dash style of the radio button.
radio3.Line.DashStyle = MsoLineDashStyle.Solid;
// Save the excel file.
excelbook.Save(dataDir + "book1.out.xls");

将组合框控件添加到工作表

为了使数据输入更容易,或将条目限制为您定义的某些项目,您可以创建一个组合框,或从工作表其他地方的单元格编译的有效条目的下拉列表。当您为单元格创建下拉列表时,它会在该单元格旁边显示一个箭头。要在该单元格中输入信息,请单击箭头,然后单击所需的条目。

使用 Microsoft Excel

要在工作表中放置组合框控件,请执行以下步骤:

  1. 确保形式显示工具栏。
  2. 点击组合框工具。
  3. 在您的工作表区域中,单击并拖动以定义将容纳组合框的矩形。
  4. 将组合框放入工作表后,右键单击控件以单击格式控制并指定输入范围。
  5. 在里面Cell 链接字段,指定此组合框应链接到的单元格的地址。
  6. 点击好的.

使用 Aspose.Cells

Aspose.Cells.Drawing.ShapeCollection类提供了一个名为添加组合框 用于将组合框控件添加到工作表。该方法返回一个Aspose.Cells.Drawing.ComboBox目的。班级Aspose.Cells.Drawing.ComboBox代表一个组合框。它有一些重要的成员:

  • 链接单元格属性指定链接到组合框的单元格。
  • 输入范围属性指定用于填充组合框的工作表单元格范围。
  • 下拉线属性指定组合框下拉部分中显示的列表行数。
  • 阴影属性指示组合框是否具有 3D 阴影。

以下示例显示如何将组合框添加到工作表。

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
// Create directory if it is not already present.
bool IsExists = System.IO.Directory.Exists(dataDir);
if (!IsExists)
System.IO.Directory.CreateDirectory(dataDir);
// Create a new Workbook.
Workbook workbook = new Workbook();
// Get the first worksheet.
Worksheet sheet = workbook.Worksheets[0];
// Get the worksheet cells collection.
Cells cells = sheet.Cells;
// Input a value.
cells["B3"].PutValue("Employee:");
// Set it bold.
cells["B3"].GetStyle().Font.IsBold = true;
// Input some values that denote the input range
// For the combo box.
cells["A2"].PutValue("Emp001");
cells["A3"].PutValue("Emp002");
cells["A4"].PutValue("Emp003");
cells["A5"].PutValue("Emp004");
cells["A6"].PutValue("Emp005");
cells["A7"].PutValue("Emp006");
// Add a new combo box.
Aspose.Cells.Drawing.ComboBox comboBox = sheet.Shapes.AddComboBox(2, 0, 2, 0, 22, 100);

向工作表添加标签控件

标签是向用户提供有关电子表格内容的信息的一种方式。 Aspose.Cells 可以在工作表中添加和操作标签。这形状集合类提供了一个名为添加标签 用于向工作表添加标签控件。该方法返回一个标签目的。班级标签代表工作表中的标签。它有一些重要的成员:

  • 文本方法指定标签的标题字符串。
  • 放置方法指定放置类型,标签附加到工作表中的单元格的方式。

以下示例显示如何向工作表添加标签。

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
// Create directory if it is not already present.
bool IsExists = System.IO.Directory.Exists(dataDir);
if (!IsExists)
System.IO.Directory.CreateDirectory(dataDir);
// Create a new Workbook.
Workbook workbook = new Workbook();
// Get the first worksheet in the workbook.
Worksheet sheet = workbook.Worksheets[0];
// Add a new label to the worksheet.
Aspose.Cells.Drawing.Label label = sheet.Shapes.AddLabel(2, 0, 2, 0, 60, 120);
// Set the caption of the label.
label.Text = "This is a Label";
// Set the Placement Type, the way the
// Label is attached to the cells.
label.Placement = PlacementType.FreeFloating;
// Saves the file.
workbook.Save(dataDir + "book1.out.xls");

将列表框控件添加到工作表

列表框控件创建一个允许选择单个或多个项目的列表控件。

使用 Microsoft Excel

要在工作表中放置列表框控件:

  1. 确保形式显示工具栏。
  2. 点击列表框工具。
  3. 在您的工作表区域中,单击并拖动以定义将容纳列表框的矩形。
  4. 将列表框放入工作表后,右键单击控件以单击格式控制并指定输入范围。
  5. 在里面Cell 链接字段,指定此列表框应链接到的单元格的地址并设置选择类型(单、多、扩展)属性
  6. 点击好的.

使用 Aspose.Cells

形状集合类提供了一个名为添加列表框,用于将列表框控件添加到工作表。该方法返回一个Aspose.Cells.Drawing.ListBox目的。班级列表框代表一个列表框。它有一些重要的成员:

  • 链接单元格方法指定链接到列表框的单元格。
  • 输入范围方法指定用于填充列表框的工作表单元格区域。
  • 选择类型method 指定列表框的选择模式。
  • 阴影方法指示列表框是否具有 3D 阴影。

下面的示例演示如何将列表框添加到工作表。

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
// Create directory if it is not already present.
bool IsExists = System.IO.Directory.Exists(dataDir);
if (!IsExists)
System.IO.Directory.CreateDirectory(dataDir);
// Create a new Workbook.
Workbook workbook = new Workbook();
// Get the first worksheet.
Worksheet sheet = workbook.Worksheets[0];
// Get the worksheet cells collection.
Cells cells = sheet.Cells;
// Input a value.
cells["B3"].PutValue("Choose Dept:");
// Set it bold.
cells["B3"].GetStyle().Font.IsBold = true;
// Input some values that denote the input range
// For the list box.
cells["A2"].PutValue("Sales");
cells["A3"].PutValue("Finance");
cells["A4"].PutValue("MIS");
cells["A5"].PutValue("R&D");
cells["A6"].PutValue("Marketing");
cells["A7"].PutValue("HRA");
// Add a new list box.
Aspose.Cells.Drawing.ListBox listBox = sheet.Shapes.AddListBox(2, 0, 3, 0, 122, 100);
// Set the placement type.
listBox.Placement = PlacementType.FreeFloating;
// Set the linked cell.
listBox.LinkedCell = "A1";
// Set the input range.
listBox.InputRange = "A2:A7";
// Set the selection tyle.
listBox.SelectionType = SelectionType.Single;
// Set the list box with 3-D shading.
listBox.Shadow = true;
// Saves the file.
workbook.Save(dataDir + "book1.out.xls");

将按钮控件添加到工作表

按钮对于执行某些操作很有用。有时,将 VBA 宏分配给按钮或分配超链接以打开网页很有用。

使用 Microsoft Excel

要在工作表中放置按钮控件:

  1. 确保形式显示工具栏。
  2. 点击按钮工具。
  3. 在您的工作表区域中,单击并拖动以定义将放置按钮的矩形。
  4. 将列表框放入工作表后,右键单击控件并选择格式控制,然后指定一个 VBA 宏和属性相关的字体、对齐方式、大小、边距等。
  5. 点击好的.

使用 Aspose.Cells

形状集合类提供了一个名为添加按钮 用于向工作表添加按钮控件。该方法返回一个Aspose.Cells.Drawing.Button目的。班级Aspose.Cells.Drawing.Button代表一个按钮。它有一些重要的成员:

  • 文本属性指定按钮的标题。
  • 字体属性指定按钮控件标签的字体属性。
  • 放置属性指定放置类型,按钮附加到工作表中单元格的方式。
  • 添加超链接属性为按钮控件添加超链接。单击该按钮将导航至相关 URL。

以下示例显示如何向工作表添加按钮。

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
// Create directory if it is not already present.
bool IsExists = System.IO.Directory.Exists(dataDir);
if (!IsExists)
System.IO.Directory.CreateDirectory(dataDir);
// Create a new Workbook.
Workbook workbook = new Workbook();
// Get the first worksheet in the workbook.
Worksheet sheet = workbook.Worksheets[0];
// Add a new button to the worksheet.
Aspose.Cells.Drawing.Button button = sheet.Shapes.AddButton(2, 0, 2, 0, 28, 80);
// Set the caption of the button.
button.Text = "Aspose";
// Set the Placement Type, the way the
// Button is attached to the cells.
button.Placement = PlacementType.FreeFloating;
// Set the font name.
button.Font.Name = "Tahoma";
// Set the caption string bold.
button.Font.IsBold = true;
// Set the color to blue.
button.Font.Color = Color.Blue;
// Set the hyperlink for the button.
button.AddHyperlink("http:// Www.aspose.com/");
// Saves the file.
workbook.Save(dataDir + "book1.out.xls");

向工作表添加行控件

使用 Microsoft Excel

  1. 画画工具栏,单击自选图形, 指向线条然后选择所需的线条样式。
  2. 拖动以绘制线条。
  3. 执行以下一项或两项操作:
  4. 要限制线条以与其起点成 15 度角绘制,请在拖动时按住 SHIFT。
  5. 要从第一个端点沿相反方向延长线,请在拖动时按住 CTRL。

使用 Aspose.Cells

形状集合类提供了一个名为添加行 用于向工作表添加线条形状。该方法返回一个线型目的。班级线型代表一条线。它有一些重要的成员:

以下示例显示如何向工作表添加行。它创建了具有不同样式的三行。

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
// Create directory if it is not already present.
bool IsExists = System.IO.Directory.Exists(dataDir);
if (!IsExists)
System.IO.Directory.CreateDirectory(dataDir);
// Instantiate a new Workbook.
Workbook workbook = new Workbook();
// Get the first worksheet in the book.
Worksheet worksheet = workbook.Worksheets[0];
// Add a new line to the worksheet.
Aspose.Cells.Drawing.LineShape line1 = worksheet.Shapes.AddLine(5, 0, 1, 0, 0, 250);
// Set the line dash style
line1.Line.DashStyle = MsoLineDashStyle.Solid;
// Set the placement.
line1.Placement = PlacementType.FreeFloating;
// Add another line to the worksheet.
Aspose.Cells.Drawing.LineShape line2 = worksheet.Shapes.AddLine(7, 0, 1, 0, 85, 250);
// Set the line dash style.
line2.Line.DashStyle = MsoLineDashStyle.DashLongDash;
// Set the weight of the line.
line2.Line.Weight = 4;
// Set the placement.
line2.Placement = PlacementType.FreeFloating;
// Add the third line to the worksheet.
Aspose.Cells.Drawing.LineShape line3 = worksheet.Shapes.AddLine(13, 0, 1, 0, 0, 250);
// Set the line dash style
line3.Line.DashStyle = MsoLineDashStyle.Solid;
// Set the placement.
line3.Placement = PlacementType.FreeFloating;
// Make the gridlines invisible in the first worksheet.
workbook.Worksheets[0].IsGridlinesVisible = false;
// Save the excel file.
workbook.Save(dataDir + "book1.out.xls");

向直线添加箭头

Aspose.Cells 还允许您绘制箭头线。可以将箭头添加到一行,并格式化该行。例如,您可以更改线条的颜色,或指定线条的粗细和样式。

以下示例显示如何向线条添加箭头。

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
// Create directory if it is not already present.
bool IsExists = System.IO.Directory.Exists(dataDir);
if (!IsExists)
System.IO.Directory.CreateDirectory(dataDir);
// Instantiate a new Workbook.
Workbook workbook = new Workbook();
// Get the first worksheet in the book.
Worksheet worksheet = workbook.Worksheets[0];
// Add a line to the worksheet
Aspose.Cells.Drawing.LineShape line2 = worksheet.Shapes.AddLine(7, 0, 1, 0, 85, 250);
// Set the line color
line2.Line.FillType = FillType.Solid;
line2.Line.SolidFill.Color = Color.Blue;
// Set the weight of the line.
line2.Line.Weight = 3;
// Set the placement.
line2.Placement = PlacementType.FreeFloating;
// Set the line arrows.
line2.Line.EndArrowheadWidth = MsoArrowheadWidth.Medium;
line2.Line.EndArrowheadStyle = MsoArrowheadStyle.Arrow;
line2.Line.EndArrowheadLength = MsoArrowheadLength.Medium;
line2.Line.BeginArrowheadStyle = MsoArrowheadStyle.ArrowDiamond;
line2.Line.BeginArrowheadLength = MsoArrowheadLength.Medium;
// Make the gridlines invisible in the first worksheet.
workbook.Worksheets[0].IsGridlinesVisible = false;
// Save the excel file.
workbook.Save(dataDir + "book1.out.xlsx");

向工作表添加矩形控件

Aspose.Cells 允许您在工作表中绘制矩形。您可以创建一个矩形、正方形等。您还可以设置控件的填充颜色和边框线颜色的格式。例如,您可以根据需要更改矩形的颜色、设置阴影颜色、指定矩形的粗细和样式。

使用 Microsoft Excel

  1. 画画工具栏,单击矩形.
  2. 拖动以绘制矩形。
  3. 执行以下一项或两项操作:
  4. 要限制矩形从其起点绘制正方形,请在拖动时按住 SHIFT。
  5. 要从中心点绘制矩形,请在拖动时按住 CTRL。

使用 Aspose.Cells

形状集合类提供了一个名为添加矩形 用于向工作表添加矩形形状。该方法返回Aspose.Cells.Drawing.RectangleShape目的。班级Aspose.Cells.Drawing.RectangleShape代表一个矩形。它有一些重要的成员:

  • 行格式 property 指定矩形的线条格式属性。
  • 放置属性指定放置类型,矩形附加到工作表中的单元格的方式。
  • 填充格式属性指定矩形的填充格式样式。

下面的示例演示如何将矩形添加到工作表。

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
// Create directory if it is not already present.
bool IsExists = System.IO.Directory.Exists(dataDir);
if (!IsExists)
System.IO.Directory.CreateDirectory(dataDir);
// Instantiate a new Workbook.
Workbook excelbook = new Workbook();
// Add a rectangle control.
Aspose.Cells.Drawing.RectangleShape rectangle = excelbook.Worksheets[0].Shapes.AddRectangle(3, 0, 2, 0, 70, 130);
// Set the placement of the rectangle.
rectangle.Placement = PlacementType.FreeFloating;
// Set the line weight.
rectangle.Line.Weight = 4;
// Set the dash style of the rectangle.
rectangle.Line.DashStyle = MsoLineDashStyle.Solid;
// Save the excel file.
excelbook.Save(dataDir + "book1.out.xls");

将圆弧控制添加到工作表

Aspose.Cells 允许您在工作表中绘制弧形。您可以创建简单的填充弧。您可以设置控件的填充颜色和边框线颜色的格式。例如,您可以指定/更改圆弧的颜色、设置阴影颜色、根据需要指定形状的权重和样式。

使用 Microsoft Excel

  1. 画画工具栏,单击在里面自选图形.
  2. 拖动以绘制圆弧。

使用 Aspose.Cells

形状集合类提供了一个名为添加圆弧 用于向工作表添加弧形。该方法返回一个Aspose.Cells.Drawing.ArcShape目的。班级Aspose.Cells.Drawing.ArcShape代表弧线。它有一些重要的成员:

  • 行格式属性指定弧形的线格式属性。
  • 放置属性指定放置类型,圆弧附加到工作表中单元格的方式。
  • 填充格式属性指定形状的填充格式样式。
  • 右下行属性指定右下角的行索引。
  • 右下栏属性指定右下角的列索引。

以下示例显示如何将圆弧形状添加到工作表。该示例创建了两个弧形:一个是填充的,另一个是简单的。

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
// Create directory if it is not already present.
bool IsExists = System.IO.Directory.Exists(dataDir);
if (!IsExists)
System.IO.Directory.CreateDirectory(dataDir);
// Instantiate a new Workbook.
Workbook excelbook = new Workbook();
// Add an arc shape.
Aspose.Cells.Drawing.ArcShape arc1 = excelbook.Worksheets[0].Shapes.AddArc(2, 0, 2, 0, 130, 130);
// Set the fill shape color
arc1.Fill.FillType = FillType.Solid;
arc1.Fill.SolidFill.Color = Color.Blue;
// Set the placement of the arc.
arc1.Placement = PlacementType.FreeFloating;
// Set the line weight.
arc1.Line.Weight = 1;
// Set the dash style of the arc.
arc1.Line.DashStyle = MsoLineDashStyle.Solid;
// Add another arc shape.
Aspose.Cells.Drawing.ArcShape arc2 = excelbook.Worksheets[0].Shapes.AddArc(9, 0, 2, 0, 130, 130);
// Set the line color
arc2.Line.FillType = FillType.Solid;
arc2.Line.SolidFill.Color = Color.Blue;
// Set the placement of the arc.
arc2.Placement = PlacementType.FreeFloating;
// Set the line weight.
arc2.Line.Weight = 1;
// Set the dash style of the arc.
arc2.Line.DashStyle = MsoLineDashStyle.Solid;
// Save the excel file.
excelbook.Save(dataDir + "book1.out.xls");

向工作表添加椭圆形控件

Aspose.Cells 允许您在工作表中绘制椭圆形。创建简单且填充的椭圆形并设置控件的填充颜色和边框线颜色的格式。例如,您可以指定/更改椭圆的颜色、设置阴影颜色、指定形状的权重和样式。

使用 Microsoft Excel

  • 画画工具栏,单击椭圆形.
  • 拖动以绘制椭圆。
  • 执行以下一项或两项操作:
  • 要限制椭圆从其起点绘制圆,请在拖动时按住 SHIFT。
  • 要从中心点绘制椭圆,请在拖动时按住 CTRL。

使用 Aspose.Cells

形状集合类提供了一个名为添加椭圆形 用于向工作表添加椭圆形。该方法返回一个Aspose.Cells.Drawing.Oval目的。班级Aspose.Cells.Drawing.Oval代表一个椭圆形。它有一些重要的成员:

  • 行格式 property 指定椭圆形的线条格式属性。
  • 放置属性指定放置类型,椭圆附加到工作表中的单元格的方式。
  • 填充格式属性指定形状的填充格式样式。
  • 右下行属性指定右下角的行索引。
  • 右下栏属性指定右下角的列索引。

以下示例显示如何将椭圆形添加到工作表。该示例创建了两个椭圆形:一个是实心椭圆,另一个是简单的圆形。

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
// Create directory if it is not already present.
bool IsExists = System.IO.Directory.Exists(dataDir);
if (!IsExists)
System.IO.Directory.CreateDirectory(dataDir);
// Instantiate a new Workbook.
Workbook excelbook = new Workbook();
// Add an oval shape.
Aspose.Cells.Drawing.Oval oval1 = excelbook.Worksheets[0].Shapes.AddOval(2, 0, 2, 0, 130, 160);
// Set the placement of the oval.
oval1.Placement = PlacementType.FreeFloating;
// Set the line weight.
oval1.Line.Weight = 1;
// Set the dash style of the oval.
oval1.Line.DashStyle = MsoLineDashStyle.Solid;
// Add another oval (circle) shape.
Aspose.Cells.Drawing.Oval oval2 = excelbook.Worksheets[0].Shapes.AddOval(9, 0, 2, 15, 130, 130);
// Set the placement of the oval.
oval2.Placement = PlacementType.FreeFloating;
// Set the line weight.
oval2.Line.Weight = 1;
// Set the dash style of the oval.
oval2.Line.DashStyle = MsoLineDashStyle.Solid;
// Save the excel file.
excelbook.Save(dataDir + "book1.out.xls");

将微调器控件添加到工作表

旋转框是附加到按钮(称为旋转按钮)的文本框,按钮由向上箭头和向下箭头组成,您单击它们可以逐渐更改文本框中的值。通过使用旋转框,您可以看到财务模型的输入变化将如何改变模型输出。您可以将旋转按钮附加到特定的输入单元格。当您单击微调按钮上的向上箭头或向下箭头时,目标输入单元格中的整数值会增加或减少。Aspose.Cells允许您在工作表中创建微调器。

使用 Microsoft Excel

要在工作表中放置旋转框控件:

  • 确保形式显示工具栏。
  • 点击微调器工具。
  • 在您的工作表区域中,单击并拖动以定义将容纳微调器的矩形。
  • 将微调器放置在工作表中后,右键单击控件并单击格式控制并指定最大值、最小值和增量值。
  • 在里面Cell 链接字段,指定此旋转框应链接到的单元格的地址。
  • 点击好的.

使用 Aspose.Cells

形状集合类提供了一个名为添加微调器 用于将旋转框控件添加到工作表。该方法返回一个Aspose.Cells.Drawing.Spinner目的。班级Aspose.Cells.Drawing.Spinner表示旋转框。它有一些重要的成员:

  • 链接单元格属性指定链接到旋转框的单元格。
  • 最大限度属性指定旋转框范围的最大值。
  • 最小值属性指定旋转框范围的最小值。
  • 增量变化属性指定微调器增加一行滚动的值量。
  • 阴影属性指示微调框是否具有 3D 阴影。
  • 当前值属性指定旋转框的当前值。

以下示例显示如何向工作表添加旋转框。

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
// Create directory if it is not already present.
bool IsExists = System.IO.Directory.Exists(dataDir);
if (!IsExists)
System.IO.Directory.CreateDirectory(dataDir);
// Instantiate a new Workbook.
Workbook excelbook = new Workbook();
// Get the first worksheet.
Worksheet worksheet = excelbook.Worksheets[0];
// Get the worksheet cells.
Cells cells = worksheet.Cells;
// Input a string value into A1 cell.
cells["A1"].PutValue("Select Value:");
// Set the font color of the cell.
cells["A1"].GetStyle().Font.Color = Color.Red;
// Set the font text bold.
cells["A1"].GetStyle().Font.IsBold = true;
// Input value into A2 cell.
cells["A2"].PutValue(0);
// Set the shading color to black with solid background.
cells["A2"].GetStyle().ForegroundColor = Color.Black;
cells["A2"].GetStyle().Pattern = BackgroundType.Solid;
// Set the font color of the cell.
cells["A2"].GetStyle().Font.Color = Color.White;
// Set the font text bold.
cells["A2"].GetStyle().Font.IsBold = true;
// Add a spinner control.
Aspose.Cells.Drawing.Spinner spinner = excelbook.Worksheets[0].Shapes.AddSpinner(1, 0, 1, 0, 20, 18);
// Set the placement type of the spinner.
spinner.Placement = PlacementType.FreeFloating;
// Set the linked cell for the control.
spinner.LinkedCell = "A2";
// Set the maximum value.
spinner.Max = 10;
// Set the minimum value.
spinner.Min = 0;
// Set the incr. change for the control.
spinner.IncrementalChange = 2;
// Set it 3-D shading.
spinner.Shadow = true;
// Save the excel file.
excelbook.Save(dataDir + "book1.out.xls");

将滚动条控件添加到工作表

滚动条控件用于以类似于旋转框控件的方式帮助选择工作表上的数据。通过将控件添加到工作表并将其链接到单元格,可以返回控件当前位置的数值。

使用 Microsoft Excel

  • 若要在 Excel 2003 和早期版本中添加滚动条,请单击滚动条上的按钮形式工具栏,然后创建一个滚动条,其高度覆盖单元格 B2:B6,并且约为列宽的四分之一。
  • 要在 Excel 2007 中添加滚动条,请单击开发商选项卡,单击插入 然后点击滚动条在表单控件部分。
  • 右键单击滚动条,然后单击格式控制.
  • 键入以下信息,然后单击好的: 在里面当前值框,类型 1。 在里面最小值框,键入 1。此值将滚动条的顶部限制为列表中的第一项。 在里面最大值框,键入 20。此数字指定列表中的最大条目数。 在里面增量变化框,键入 1。此值控制滚动条控件将当前值递增的数量。 在里面换页框,键入 5。如果您在滚动框任一侧的滚动条内单击,则此条目控制当前值将增加多少。 要将数字值放入单元格 G1(取决于列表中选择的项目),请在Cell 链接盒子。
  • 单击任何单元格,以便不选择滚动条。

单击滚动条上的向上或向下控件时,单元格 G1 将更新为一个数字,该数字指示滚动条的当前值加上或减去滚动条的增量变化。

使用 Aspose.Cells

形状集合类提供了一个名为添加滚动条,用于向工作表添加滚动条控件。该方法返回一个Aspose.Cells.Drawing.ScrollBar目的。班级Aspose.Cells.Drawing.ScrollBar代表一个滚动条。它有一些重要的成员:

  • 链接单元格属性指定链接到滚动条的单元格。
  • 最大限度属性指定滚动条范围的最大值。
  • 最小值属性指定滚动条范围的最小值。
  • 增量变化属性指定滚动条增加一行滚动的值量。
  • 阴影属性表示滚动条是否有 3D 底纹。
  • 当前值属性指定滚动条的当前值。
  • 换页属性指定如果您在滚动框任一侧的滚动条内单击,当前值将增加多少。

以下示例显示如何向工作表添加滚动条。

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
// Create directory if it is not already present.
bool IsExists = System.IO.Directory.Exists(dataDir);
if (!IsExists)
System.IO.Directory.CreateDirectory(dataDir);
// Instantiate a new Workbook.
Workbook excelbook = new Workbook();
// Get the first worksheet.
Worksheet worksheet = excelbook.Worksheets[0];
// Invisible the gridlines of the worksheet.
worksheet.IsGridlinesVisible = false;
// Get the worksheet cells.
Cells cells = worksheet.Cells;
// Input a value into A1 cell.
cells["A1"].PutValue(1);
// Set the font color of the cell.
cells["A1"].GetStyle().Font.Color = Color.Maroon;
// Set the font text bold.
cells["A1"].GetStyle().Font.IsBold = true;
// Set the number format.
cells["A1"].GetStyle().Number = 1;
// Add a scrollbar control.
Aspose.Cells.Drawing.ScrollBar scrollbar = worksheet.Shapes.AddScrollBar(0, 0, 1, 0, 125, 20);
// Set the placement type of the scrollbar.
scrollbar.Placement = PlacementType.FreeFloating;
// Set the linked cell for the control.
scrollbar.LinkedCell = "A1";
// Set the maximum value.
scrollbar.Max = 20;
// Set the minimum value.
scrollbar.Min = 1;
// Set the incr. change for the control.
scrollbar.IncrementalChange = 1;
// Set the page change attribute.
scrollbar.PageChange = 5;
// Set it 3-D shading.
scrollbar.Shadow = true;
// Save the excel file.
excelbook.Save(dataDir + "book1.out.xls");

将 GroupBox 控件添加到工作表中的组控件

有时您确实需要实现属于某个组的单选按钮或其他控件,您可以通过包含组框或矩形控件来实现。这两个对象中的任何一个都将作为组的分隔符。添加这些形状之一后,您可以添加两个或更多单选按钮或其他组对象。

使用 Microsoft Excel

要在工作表中放置组框控件并在其中放置控件:

  • 要启动表单,请在主菜单上单击看法, 其次是工具栏形式.
  • 形式工具栏,单击组框并在工作表上绘制一个矩形。
  • 为框键入标题字符串。
  • 形式工具栏,单击选项按钮然后点击组框就在标题字符串下面。
  • 来自形式工具栏再次单击选项按钮然后点击组框在第一个单选按钮下。
  • 再次上形式工具栏,单击选项按钮然后点击组框在上一个单选按钮下。

使用 Aspose.Cells

形状集合类提供了一个名为添加组框 用于向工作表添加分组框控件。该方法返回一个Aspose.Cells.Drawing.GroupBox目的。此外,团体的方法形状集合类对形状进行分组,需要一个形状数组作为参数并返回一个组形目的。班级Aspose.Cells.Drawing.GroupBox代表一个分组框。它有一些重要的成员:

  • 文本属性指定组框的标题字符串。
  • 阴影属性指示组框是否具有 3D 阴影。

下面的示例演示如何添加组合框并对工作表中的控件进行分组。

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
// Create directory if it is not already present.
bool IsExists = System.IO.Directory.Exists(dataDir);
if (!IsExists)
System.IO.Directory.CreateDirectory(dataDir);
// Instantiate a new Workbook.
Workbook excelbook = new Workbook();
// Add a group box to the first worksheet.
Aspose.Cells.Drawing.GroupBox box = excelbook.Worksheets[0].Shapes.AddGroupBox(1, 0, 1, 0, 300, 250);
// Set the caption of the group box.
box.Text = "Age Groups";
box.Placement = PlacementType.FreeFloating;
// Make it 2-D box.
box.Shadow = false;
// Add a radio button.
Aspose.Cells.Drawing.RadioButton radio1 = excelbook.Worksheets[0].Shapes.AddRadioButton(3, 0, 2, 0, 30, 110);
// Set its text string.
radio1.Text = "20-29";
// Set A1 cell as a linked cell for the radio button.
radio1.LinkedCell = "A1";
// Make the radio button 3-D.
radio1.Shadow = true;
// Set the weight of the radio button.
radio1.Line.Weight = 4;
// Set the dash style of the radio button.
radio1.Line.DashStyle = MsoLineDashStyle.Solid;
// Add another radio button.
Aspose.Cells.Drawing.RadioButton radio2 = excelbook.Worksheets[0].Shapes.AddRadioButton(6, 0, 2, 0, 30, 110);
// Set its text string.
radio2.Text = "30-39";
// Set A1 cell as a linked cell for the radio button.
radio2.LinkedCell = "A1";
// Make the radio button 3-D.
radio2.Shadow = true;
// Set the weight of the radio button.
radio2.Line.Weight = 4;
// Set the dash style of the radio button.
radio2.Line.DashStyle = MsoLineDashStyle.Solid;
// Add another radio button.
Aspose.Cells.Drawing.RadioButton radio3 = excelbook.Worksheets[0].Shapes.AddRadioButton(9, 0, 2, 0, 30, 110);
// Set its text string.
radio3.Text = "40-49";
// Set A1 cell as a linked cell for the radio button.
radio3.LinkedCell = "A1";
// Make the radio button 3-D.
radio3.Shadow = true;
// Set the weight of the radio button.
radio3.Line.Weight = 4;
// Set the dash style of the radio button.
radio3.Line.DashStyle = MsoLineDashStyle.Solid;
// Get the shapes.
Aspose.Cells.Drawing.Shape[] shapeobjects = new Aspose.Cells.Drawing.Shape[] { box, radio1, radio2, radio3 };
// Group the shapes.
Aspose.Cells.Drawing.GroupShape group = excelbook.Worksheets[0].Shapes.Group(shapeobjects);
// Save the excel file.
excelbook.Save(dataDir + "book1.out.xls");

推进主题