How to implement sheets[0].Cells[iRow- iCol].Tag feature with your ASPOSE CELL?

Dear ASPOSE Team

I do a research about to implement your ASPOSE CELL product in a project. What I need it to mark the cells someway and later when I read the cell to be able to identify the Cell with this ID. In Visual Studio most controls support Tag feature.

To make more clear, I need: somethink like:

sheets[0].Cells[iRow, iCol].Tag=ID

and on read time to get back this tag.

ID = sheets[0].Cells[iRow, iCol].Tag

The Tag data should be invisible for user when open the file with MS Excel and it should not be able to change it. He/she should be able to change only the value in the cell.

Which feature I should use for this with your ASPOSE CELL? May be formula – with hard value (number) ? And to lock all formulas from user change? Or ?

v

Hi Damian,

Thanks for your posting and using Aspose.Cells.

As a workaround, you can assign Name to any Cell. For example, the following code have assigned the Name “SampleCell” to cell E1 of Sheet1.

Later you can retrieve the same cell by its Name with the following code. Please read the comments.

I have attached the output xlsx file generated by the code for your reference. Please also check the screenshot highlighting the relevant areas in the output file.

C#


Workbook workbook = new Workbook();


//You can assign Name to any cell

int idx = workbook.Worksheets.Names.Add(“SampleCell”);

Name name = workbook.Worksheets.Names[idx];

name.RefersTo = “=Sheet1!$E$1”;


//You can retrieve the Named cell using the following code

Range range = workbook.Worksheets.GetRangeByName(“SampleCell”);

Cell cell = range.Worksheet.Cells[range.FirstRow, range.FirstColumn];


//Save the workbook

workbook.Save(“output.xlsx”);

Thanks for your fast answer.

Well, may be I can use Name property. I see that I have access to it with:

Sh.Cells[2,2].Name

But how can I lock this so user can’t change it by mistake? This is one of the primary requirements.

I think formulas could be used, but they could be locked as well?v

Hi Damian,

Thanks for your posting and considering Aspose.Cells.

Actually, such a property (i.e Tag) is not available inside Xls/Xlsx format, therefore neither MS-Excel nor Aspose.Cells provide it.

The cell.Name property is actually the address of the cell. For example, Cell.Name will give you A1, B2, C3. It is not the name of the cell but the address of the cell.

The above code given by me is give the cell name and retrieve it by name, so as a workaround, you can assign name to cell and later retrieve that cell.

However, you can protect your worksheets and lock its cells. Please see the following documentation article how to achieve this.

( Protecting Worksheets|Documentation )