Hide a column or set of columns in excel using OpenXml. RRS feed

  • Question

  • Hello,

    I need to export data from a DB into an excel spreadsheet, and based on certain conditions i need to hide a set of columns. Can anyone guide me in the direction which class(es) will help me in achieving this.

    Thanks in advance.

    Monday, August 23, 2010 7:27 AM


  • Hi Raj,

    I suggest to use Productivity Tool which is a part of the SDK. Create an empty Excel document and hide few columns and then open the document in tool to see how to generate a document like this.

    It seems whenever you hide a colum( or set of columns), it define as

    <x:col min="7" max="9" width="39.28515625" hidden="1" customWidth="1" />

    and here is the code

    Column column3 = new Column(){ Min = (UInt32Value)7U, Max = (UInt32Value)9U, Width = 39.28515625D, Hidden = true, CustomWidth = true };



    where hidden is an attribute. Please have a look : 

    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread. Regards, Ankush Microsoft Online Community Support
    Monday, August 23, 2010 8:34 PM