1

Hey any body know how to hide cell contains using spreadsheet gear.

tom redfern
  • 30,562
  • 14
  • 91
  • 126
Avinash
  • 173
  • 1
  • 4
  • 17

1 Answers1

2

You can set IRange.NumberFormat to ";;;" to cause the contents of a cell to be hidden. There are also IRange.FormulaHidden, IRange.Rows.Hidden, IRange.Columns.Hidden and probably other ways to approach it that I am not thinking about. Here is some code which demonstrates these approaches:

namespace Program
{
    class Program
    {
        static void Main(string[] args)
        {
            // Create a new workbook and get a reference to Sheet1!A1.
            var workbook = SpreadsheetGear.Factory.GetWorkbook();
            var sheet1 = workbook.Worksheets[0];
            var a1 = workbook.Worksheets[0].Cells["A1"];
            // Put some text in A1.
            a1.Value = "Hello World!";
            // Set a number format which causes nothing to be displayed.
            //
            // This is probably the best way to hide the contents of 
            // a single cell.
            a1.NumberFormat = ";;;";
            // Set FormulaHidden to true - must set IWorksheet.ProtectContents 
            // to true for this make any difference. This will not hide values
            // in cells.
            a1.FormulaHidden = true;
            // Hide the row containing A1.
            a1.Rows.Hidden = true;
            // Hide the column containing A1.
            a1.Columns.Hidden = true;
        }
    }
}
Joe Erickson
  • 7,077
  • 1
  • 31
  • 31
  • 1
    Hey Joe Thank for giving hint,i got solution of my problem with hint given in your code,previously i was using a1.NumberFormat = ";;;" but it was not serving my requirements ,it was hiding cells contains but,cells contains ware visible in formula bar,now i am using a1.NumberFormat = ";;;" and a1.FormulaHidden = true both and this is working fine for my requirements . – Avinash Apr 16 '10 at 06:49