473,884 Members | 2,296 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Excel problem: Cant hide column.

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("T ableName")
Dim col As DataColumn
Dim mrow As DataRow
Dim objxl As Excel.Applicati on
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.Applicati on
objwbs = objxl.Workbooks
objwb = objwbs.Add
objws = CType(objwb.Wor ksheets(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(row index, colindex) =
mrow(col.Column Name).ToString( )
Next
Next

objxl.DisplayAl erts = False 'Makes overwrites automatic so that
a prompt to overwrite doesnt pop up
objwb.SaveAs(sF ileName)
objwb.Close()
objxl.DisplayAl erts = 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?

Oct 10 '06 #1
1 6167
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
so*******@gmail .com wrote:
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("T ableName")
Dim col As DataColumn
Dim mrow As DataRow
Dim objxl As Excel.Applicati on
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.Applicati on
objwbs = objxl.Workbooks
objwb = objwbs.Add
objws = CType(objwb.Wor ksheets(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(row index, colindex) =
mrow(col.Column Name).ToString( )
Next
Next

objxl.DisplayAl erts = False 'Makes overwrites automatic so that
a prompt to overwrite doesnt pop up
objwb.SaveAs(sF ileName)
objwb.Close()
objxl.DisplayAl erts = 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?
Oct 10 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
35579
by: Allison Bailey | last post by:
Hi Folks, I'm a brand new Python programmer, so please point me in the right direction if this is not the best forum for this question.... I would like to open an existing MS Excel spreadsheet and extract information from specific worksheets and cells. I'm not really sure how to get started with this process. I ran the COM Makepy utility from my PythonWin (IDE from ActiveSTate),
3
9535
by: Jeremy | last post by:
Hi, I have a webpage that is taking input from a form and using it as criteria to select data out of an sql database. The page displays an html table with the results. The user can then click a button "excel" to open or save the file as an excel document. This works, and everything in the excel document is formatted fine except for the first column which in this case is "Part Number". The problem is that this part number: 883100105100...
9
8905
by: Paul | last post by:
Hi all Arggghhh........... The problem.....I want the user to be able to create an excel document and name particular cells in the document where they want the data to be placed and then save this out of an XML file or Excel Template file. Next I need to convert a dataset to xml and try and transform this data into the users xml file..........i've seen a few things on this but havent had much success...
3
9937
by: | last post by:
I wrote a class in VB.NET to export the contents of a datagrid to Excel. It works perfectly on my machine, but it fails on my customers' PCs that have identical versions of Win XP (SP1) and Excel (SP1) installed. The error is: System.Runtime.InteropServices.COMException(0x800A03EC): Exception from HRESULT: 0x800A03EC. at Microsoft.Office.Interop.Excel._Worksheet.Paste(Object Destination, Object Link) at...
1
1533
by: Sorcerdon | last post by:
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:
4
2133
by: indrajith_varma1 | last post by:
Hi I am working on an application to retrieve data from excel and insert into SQL Server database. Yesterday, I faced a strange problem. In a column in the excel, if 1st 8 rows are number, then as soon as an alphanumeric or string value is encountered, the string becomes null and put into the data set. IMEX property of the excel connection object is set as 1. Is there any solution in the .NET code to fix this issue? In anticipation...
10
3131
by: Esmael | last post by:
Hi to all, /*****************************/ OS-WIn XP SP2 VB6 SP6 /*****************************/ Is their anyone who can help me with this: Source code written on VB6.
4
9359
by: =?Utf-8?B?Um9iZXJ0?= | last post by:
I am opening an Excel Workbook from C# (VS2005) and I need to get a value from a Spreadsheet before closing the C# application. Does anyone know if this can be done? Here is the code to open the Workbook: //Open the Excel Spreadsheet Microsoft.Office.Interop.Excel.Application excelApp = new Microsoft.Office.Interop.Excel.ApplicationClass(); excelApp.Visible = true; string workbookPath = @"\\server\path$\AssignmentTest.xls";...
7
12086
by: TG | last post by:
hi! I am trying to create a sql server table from an excel sheet. Here is the code I have: 'This procedure the xlsx file and dumps it to a table in SQL Server
0
2214
by: dutsnekcirf | last post by:
Okay, I think this one is a really hard one for yous geniuses out there. I'm going to try my best to explain in as much detail as I can. And for the most part I just want to know if I'm doing this the right way of it there's an easier way to do it. Background/Platform: Windows XP Office Excel 2007 Visual Studio Tools for Office 2008 Document level customization VB.Net I have a spreadsheet that is used to project which site(s) a...
0
9799
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10869
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7985
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7137
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5808
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6009
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4623
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4231
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3242
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.