| |
 |
Adding CheckBox - Aspose.Cells
|
 |
This demo shows how to add checkbox control in your worksheet
using
Aspose.Cells for .NET.
CheckBoxes 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 checkboxes in your worksheets,
if desired. Aspose.Cells provides CheckBoxes class, which is used to add a new checkbox
to the collection. There is another class CheckBox, which represents a checkbox
used to define all types of settings. The
demo creates an excel file. Then by using simple Aspose.Cells APIs it adds a checkbox
and apply different setting to it.
Click Process to see how example adds a CheckBox control to the workbook by setting different options.
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
42
43
|
<%@ Page Language="C#" MasterPageFile="~/tpl/Demo.Master" AutoEventWireup="true"
CodeBehind="adding-checkbox.aspx.cs" Inherits="Workbooks_Controls_AddCheckbox" Title="Adding CheckBox - 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 CheckBox - 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 checkbox 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">CheckBoxes</font><font size="2"> 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 checkboxes in your worksheets,
if desired. Aspose.Cells provides CheckBoxes class, which is used to add a new checkbox
to the collection. There is another class CheckBox, which represents a checkbox
used to define all types of settings.</font></span><font face="Arial" size="2"> The
demo creates an excel file. Then by using simple Aspose.Cells APIs it adds a checkbox
and apply different setting to it.</font></SPAN></p>
<p class="componentDescriptionTxt">
<span style="font-size: 10pt; font-family: Arial"><font face="Arial" size="2"></font>
Click <b>Process </b> to see how example adds a CheckBox control to the workbook by setting different options.
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
|
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_AddCheckbox : 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()
{
//Instantiate a new Workbook.
Workbook workbook = new Workbook();
//Add a checkbox to the first worksheet in the workbook.
int index = workbook.Worksheets[0].CheckBoxes.Add(5, 5, 20, 120);
//Get the checkbox object.
Aspose.Cells.Drawing.CheckBox checkbox = workbook.Worksheets[0].CheckBoxes[index];
//Set its text string.
checkbox.Text = "Click it!";
//Put a value into B1 cell.
workbook.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;
if (ddlFileVersion.SelectedItem.Value == "XLS")
{
////Save file and send to client browser using selected format
workbook.Save(HttpContext.Current.Response, "CheckBox.xls", ContentDisposition.Attachment, new XlsSaveOptions(SaveFormat.Excel97To2003));
}
else
{
workbook.Save(HttpContext.Current.Response, "CheckBox.xlsx", ContentDisposition.Attachment, new OoxmlSaveOptions(SaveFormat.Xlsx));
}
//end response to avoid unneeded html
HttpContext.Current.Response.End();
}
}
|
|
|
|