使用SpreadSheetGear隐藏单元格包含在MS Excel中?

时间:2010-04-11 09:28:49

标签: hide cell spreadsheet spreadsheetgear

嘿,任何人都知道如何使用电子表格装置隐藏单元格。

1 个答案:

答案 0 :(得分:2)

您可以将IRange.NumberFormat设置为“;;;”使单元格的内容被隐藏。还有IRange.FormulaHidden,IRange.Rows.Hidden,IRange.Columns.Hidden以及其他可能接近它的方式,我没有想到。以下是一些演示这些方法的代码:

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;
        }
    }
}