Disabling column header

Posted by: ajaysingal on 8 September 2017, 1:22 pm EST

  • Posted 8 September 2017, 1:22 pm EST

    In my code, I am creating a dataset and then binding it to a sheet.  By default, the table field names are inserted as the column header in the spreadsheet.  How can I disable that?  I would like to show the table field name in regular cell.


     I want to do so because once the data is displayed on the sheet, I have to insert multiple rows at the beginning so that I can manually put in some text as the report header.


     Thanks for your help.


     

  • Replied 8 September 2017, 1:22 pm EST

    Bob,


    I am not able to specify the field names.  Here is what I did:


    1)  Turn off the column heading --> sheet.DataAutoHeadings = False 


    2)  Did the binding by doing the following: -->  sheet.DataSource = lmtDataset


     


    3)  Now I inserted a row in the spreadsheet at the top by doing -->  sheet.Rows.Add(0, 1)


    4)  I am iterating through all my columns and specifying the names of each column by doing this:


                            For i = 0 To lmtDataset.Tables(0).Columns.Count - 1


                                 sheet.SetText(0, i, lmtDataset.Tables(0).Columns(i).ColumnName)


                            Next


    It seems like the column names are set correctly for columns which are of type String.  If a column is of type integer or double, the cell is left blank.  Please help.


     

  • Replied 8 September 2017, 1:22 pm EST

    Ajay -

    Try setting the cell type for all the cells in that row to be a GeneralCellType.  Do this after you add the new row.

  • Replied 8 September 2017, 1:22 pm EST

    You can use the DataAutoHeadings and set it to false.
  • Replied 8 September 2017, 1:22 pm EST

    Hi Bob,


     Thanks a lot for responding so quickly.  If I do use DataAutoHeadings set to false, yes it does not put the table field names in the column heading but how do I get the table field names to appear on regular cell?  Is there an easy way to do that or will I have to manually write text to the cells?

  • Replied 8 September 2017, 1:22 pm EST

    Ajay -

    You will have to add a new row at the top AFTER you are done binding and then add the field names to those cells.

  • Replied 8 September 2017, 1:22 pm EST

    Bob, no luck.


    I added a new row and set the cell type of each cell of that row to General.


    Now when I am trying to put text in a cell (column that was of type integer), it gives me an exception: "Input string was not in a correct format."

  • Replied 8 September 2017, 1:22 pm EST

    Did you use the AddRows method or the AddUnboundRows method?  If the former then switch to the latter so the new row won't pick up the constraints of the data table.
  • Replied 8 September 2017, 1:22 pm EST

    Thanks Bob!!!


    Using AddUnboundRows worked!

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels