| |
 |
Adding ComboBox - Aspose.Cells
|
 |
This demo shows how to add combobox control in your worksheet
using
Aspose.Cells for .NET.
To make data entry easier, or to limit
entries to certain items that you define, you can create a ComboBox or drop-down
list of valid entries that is compiled from cells elsewhere on the worksheet. The demo creates an excel file and by using simple Aspose.Cells
APIs it adds a combobox by using range of Cells from A2 to A7 as data source.
Click Process to see how example adds a ComboBox control to the worksheet by using cell range as data source.
You can either open the resulting excel file into MS Excel
or save directly to your disk.
| ASP.NET |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
<%@ Page Language="C#" MasterPageFile="~/tpl/Demo.Master" AutoEventWireup="true"
CodeBehind="adding-combobox.aspx.cs" Inherits="Workbooks_Controls_AddCombobox" Title="Adding ComboBox - Aspose.Cells Demos" %>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="Server">
<p class="componentDescriptionTxt">
<span style="font-size: 10pt; font-family: Arial"></span> </p>
<p class="componentDescriptionTxt">
<span style="font-size: 10pt; font-family: Arial"></span>
<table align="center" border="0" cellpadding="0" cellspacing="0" width="90%">
<tr>
<td valign="top" width="19">
<img alt="" height="41" src="/Common/images/heading_lft.jpg" width="19" /></td>
<td class="demos-heading-bg" width="100%">
<h2 class="demos-heading-bg">
<font face="Arial" size="4">Adding ComboBox - Aspose.Cells</font></h2>
</td>
<td valign="top" width="19">
<img alt="" height="41" src="/Common/images/heading_rt.jpg" width="19" /></td>
</tr>
</table>
</p>
<p class="componentDescriptionTxt">
<font face="Arial" size="2">This demo shows how to add combobox control in your worksheet
using <a href="http://www.aspose.com/categories/.net-components/aspose.cells-for-.net/default.aspx">
Aspose.Cells</a> for .NET.</font></p>
<p class="componentDescriptionTxt">
<span style="font-family: Arial"><font size="2">To make data entry easier, or to limit
entries to certain items that you define, you can create a ComboBox or drop-down
list of valid entries that is compiled from cells elsewhere on the worksheet.</font></span><font
face="Arial" size="2"> The demo creates an excel file and by using simple Aspose.Cells
APIs it adds a combobox by using range of Cells from A2 to A7 as data source.<br />
</font></SPAN><span style="font-size: 10pt; font-family: Arial"></span></p>
<p class="componentDescriptionTxt">
<span style="font-size: 10pt; font-family: Arial">
Click <b>Process </b> to see how example adds a ComboBox control to the worksheet by using cell range as data source.
You can either open the resulting excel file into MS Excel
or save directly to your disk. </span>
</p>
<asp:Button ID="btnExecute" runat="server" Text="Process" OnClick="btnExecute_Click" />
</asp:Content>
|
| C# |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Aspose.Cells;
public partial class Workbooks_Controls_AddCombobox : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DropDownList ddlFileVersion;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnExecute_Click(object sender, EventArgs e)
{
//Call Method to create report
CreateStaticReport();
}
protected void CreateStaticReport()
{
//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:");
Aspose.Cells.Style style = cells["B3"].GetStyle();
//Set it bold.
style.Font.IsBold = true;
cells["B3"].SetStyle(style);
//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);
//Set the linked cell;
comboBox.LinkedCell = "A1";
//Set the input range.
comboBox.InputRange = "A2:A7";
//Set no. of list lines displayed in the combo box's list portion.
comboBox.DropDownLines = 5;
//Set the combo box with 3-D shading.
comboBox.Shadow = true;
//AutoFit Columns
sheet.AutoFitColumns();
if (ddlFileVersion.SelectedItem.Value == "XLS")
{
////Save file and send to client browser using selected format
workbook.Save(HttpContext.Current.Response, "ComboBox.xls", ContentDisposition.Attachment, new XlsSaveOptions(SaveFormat.Excel97To2003));
}
else
{
workbook.Save(HttpContext.Current.Response, "ComboBox.xlsx", ContentDisposition.Attachment, new OoxmlSaveOptions(SaveFormat.Xlsx));
}
//end response to avoid unneeded html
HttpContext.Current.Response.End();
}
}
|
|
|
|