Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / October 2006

Tip: Looking for answers? Try searching our database.

Excel problem: Cant hide column.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Sorcerdon - 10 Oct 2006 17:39 GMT
Hello experts,

I am currently opening an excel file from a VB.net application.
The excel spreadsheet gets all its data from a Dataset.
I need to hide a column form the results.
I dont want the users to have access to that perticular column in the
excel spreadsheet.

Here is my current code:

Dim dt As DataTable = dsSql.Tables("TableName")
Dim col As DataColumn
Dim mrow As DataRow
Dim objxl As Excel.Application
Dim objwbs As Excel.Workbooks
Dim objwb As Excel.Workbook
Dim objws As Excel.Worksheet
Dim colindex As Integer
Dim rowindex As Integer

       objxl = New Excel.Application
       objwbs = objxl.Workbooks
       objwb = objwbs.Add
       objws = CType(objwb.Worksheets(1), Excel.Worksheet)

       If includeheader Then
           For Each col In dt.Columns
               colindex += 1
              objws.Cells(1, colindex) = col.ColumnName
          Next
           rowindex = 1
       Else
           rowindex = 0
       End If
       For Each mrow In dt.Rows
           rowindex += 1
           colindex = 0
           For Each col In dt.Columns
               colindex += 1
             objws.Cells(rowindex, colindex) =
mrow(col.ColumnName).ToString()
            Next
       Next

       objxl.DisplayAlerts = False 'Makes overwrites automatic so that
a prompt to overwrite  doesnt pop up
       objwb.SaveAs(sFileName)
       objwb.Close()
       objxl.DisplayAlerts = True 'Makes overwrites non-automatic so
that a prompt to overwrite does pop up
       objxl.Quit()
       objws = Nothing
       objwb = Nothing
       objwbs = Nothing
       objxl = Nothing

What is the code to delete ONE entire column and where do I place it?
Sachin Salgarkar - 11 Oct 2006 16:35 GMT
There are 2 ways to do it.
You can either remove the column from the table before you export it to the
Excel sheet.

dt.Columns.Remove("Columnname")
OR
dt.Columns.RemoveAt( column index) .

The other way is to ignore the column in the For Each loops.

-sachin salgarkar

> Hello experts,
>
[quoted text clipped - 53 lines]
>
> What is the code to delete ONE entire column and where do I place it?

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.