|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Excel problem: Cant hide column.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? The easiest way to find out code for excel is to fire up excel's Macro
recorder, do your task and then modify the generated code to your needs. Hope that helps, Seth Rowe sorcer***@gmail.com wrote: Show quoteHide quote > 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?
class library
Trouble with mouse click vb with odbc File handling in VB How to Load string into mshtml object? Detect WiFi Networks what method to use to add 1 day to a date (hotel reservation for one night by clicking on calender) How to reference Webform textbox controls in a for next loop PLEASE HELP - Executable properties - right click data binding and rejectchanges |
|||||||||||||||||||||||