Disable checkbox in aspose cells v8.3

Hi,

I am using aspose cells v8.3
I want to disable the checkboxes which I added in worksheet.
below is my code, it is very easy.

namespace ConsoleApplication5
{
class Program
{
static void Main(string[] args)
{
Aspose.Cells.License license = new Aspose.Cells.License();
license.SetLicense(“Aspose.Cells.lic”);

Workbook wb = new Workbook();
wb.Worksheets.Add();

int index = wb.Worksheets[0].CheckBoxes.Add(0,0,21,100);
CheckBox cb = wb.Worksheets[0].CheckBoxes[index];
cb.Value = true;
cb.Text = “bac”;
cb.IsLocked = true;

wb.Worksheets[0].Protect(ProtectionType.All);
wb.Save(string.Format(“d:\abc{0}.XLS”,DateTime.Now.Ticks));
}
}
}

I think disable one checkbox in excel is basic requirement, but my output excel doesn’t work as expected.
Do you share some more idea for this?
Attached is my output report.

More information is that I found the checkbox IsChecked default property is true too.

Hi,

Thanks for your posting and using Aspose.Cells.

Do you want to check/uncheck check box? Because we do not know if enabling/disabling checkbox is possible with Microsoft Excel.

If it is possible, then please manually created your Excel file with a disable checkbox and attach here for our reference. We will look into your Excel file and provide you Aspose.Cells sample code to achieve the same disabled checkbox.

Thanks for your cooperation.

thank your reply.
I do more investigation about disable checkbox.
refer to below link, I found the right answer.
http://stackoverflow.com/questions/16056172/excel-2010-protect-sheet-does-not-lock-check-box

we still need one more action to setup its linkedCell

namespace ConsoleApplication5
{
class Program
{
static void Main(string[] args)
{
Aspose.Cells.License license = new Aspose.Cells.License();
license.SetLicense(“Aspose.Cells.lic”);

Workbook wb = new Workbook();
wb.Worksheets.Add();

int index = wb.Worksheets[0].CheckBoxes.Add(0,0,21,100);
CheckBox cb = wb.Worksheets[0].CheckBoxes[index];
cb.Value = true;
cb.Text = “bac”;
cb.IsLocked = true;
cb.LinkedCell = “A1”;//

wb.Worksheets[0].Protect(ProtectionType.All);
wb.Protect(ProtectionType.All,“ABC”);
wb.Save(string.Format(“d:\abc{0}.XLSX”,DateTime.Now.Ticks));
}
}
}

see my updated code.
so first we protected sheetview, then each cell in the sheetview is protected.
the added control(for example: checkbox) default islocked is true. but it don’t connected with any cell in sheetview. so we should setup its linkedCell to protect this control.

Hi,

Thanks for your posting and using Aspose.Cells.

Please see the following sample code. It links the check box with cell D4 and unlocks the cell D4 and protects all the worksheet and workbook. Now, when you will click the checkbox, D4 will be set to true and when you will click it again, D4 will set to false.

I have attach the output Excel file generated by this code and screenshots in the MS-Word document for your reference.

Let us know if you need something else. If your requirements are different, then please provide us your sample expected Excel file with your desired check box, which you can create manually using Microsoft Excel and attach it here for our investigation.

C#


Workbook wb = new Workbook();


int index = wb.Worksheets[0].CheckBoxes.Add(0, 0, 21, 100);

Aspose.Cells.Drawing.CheckBox cb = wb.Worksheets[0].CheckBoxes[index];

cb.Value = true;

cb.Text = “bac”;

cb.IsLocked = true;

cb.LinkedCell = “D4”;//


//Set D4 as unlocked

Cell d4 = wb.Worksheets[0].Cells[“D4”];

Style st = d4.GetStyle();

st.IsLocked = false;

d4.SetStyle(st);


wb.Worksheets[0].Protect(ProtectionType.All);

wb.Protect(ProtectionType.All, “ABC”);

wb.Save(“output.xlsx”);