Excel object plays an important role when we operate Excel in .Net for we often need to use Excel object in .Net to realize Excel automation. There are four Excel object classes frequently used, Application, Workbook, Worksheet and Range. I want to discuss something about Worksheet of Excel object.

As one class of Excel object, Worksheet offers a great deal of members. However, most of members’ properties, methods and events are similar to Application and Workbook members. In Excel, we can’t find Sheet class even though Excel provides a sheets assembly as Workbook object’s property. On the contrary, each member of sheets assembly is Worksheet and chart object.

We can use protection in Excel to prevent users or code from changing objects in Worksheet. Once we open the protection, users can’t edit or change worksheet unless we arrange forward. Select Protection in Tools menu and then select Protect Sheet to start this function. We can set password or allow users to executing specified operation. By default, all the cells will be locked once the protection is started. Also, we can use Protect method to controlling protection of worksheet by programming. But it is not a good idea to set password in code for the password will not be saved and you can’t see it in source code.

Besides, Excel provides other two objects: Protection and AllowEditRange. Protection packages information specified by Protect method and unprotected range information. We often invoke Protect method to set shared Protection object property. Protection provides AllowEditRange property too and allows us to specifying the range which can be edited in worksheet.

Besides method, worksheet class provides several properties to return object, comment, outline and so on. The Comments property can return on Comments object which allow us to visiting all the Comments object related to Worksheet repeatedly. We can use Visible to display or hide comments or use Delete method to delete comments. Outline property is an Outline object too. Outline doesn’t provide many objects. We often use Group method to create group and invoke Ungroup to cancel grouping.

Of course, other classes of Excel object offer many members, methods and events to complete requirements so that all the Excel object classes are useful in Excel automation in .Net.