Hi, I'm having problems opening up excel thru my code. It will write and
saveas an excel file, but the application won't open on the user's computer,
excel seems to be hidden, because it shows up on the task manager. The
problem is, if this user tries to download the data more than once, it gets
stuck because the file already exists, so I want it to overwrite the old
file...but the user can't overwrite when the excel app won't work! Any
suggestions? This is my code below:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim oDS As New DataSet
Dim oConn As New SqlClient.SqlConnection("workstation
id=CTR3_252A;packet size=4096;user id=sa;data source=CRI;persist security
info=True;initial catalog=gfdgfd;password=gfdgfd")
Dim oSqlCmd As New SqlClient.SqlCommand("SELECT * from
dbo.MRI_HEATHERSTAT_VIEW")
Dim oDA As New SqlClient.SqlDataAdapter(oSqlCmd)
oSqlCmd.Connection = oConn
oConn.Open()
oDA.Fill(oDS)
oConn.Close()
Dim oRow As DataRow
For Each oRow In oDS.Tables(0).Rows
Next
Dim oDSLocal As New DataSet
Dim oSqlCmdlocal As New SqlClient.SqlCommand("SELECT * from
dbo.MRI_HEATHERSTAT_VIEW")
Dim oDAlocal As New SqlClient.SqlDataAdapter(oSqlCmdlocal)
Dim oConnLocal As New SqlClient.SqlConnection("workstation
id=CTR3_252A;packet size=4096;user id=sa;data source=CRI;persist security
info=True;initial catalog=gfdgfd;password=gfdgfd")
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlAELBook As Excel.Workbook
Dim xlAELSheet As Excel.Worksheet
Dim xlSheet As Excel.Worksheet
xlApp = CType(CreateObject("Excel.Application"), Excel.Application)
xlBook = CType(xlApp.Workbooks.Add, Excel.Workbook)
xlSheet = CType(xlBook.Worksheets(1), Excel.Worksheet)
xlApp.Visible = True
xlSheet.Visible = True
xlSheet.Application.Visible = True
oSqlCmdlocal.Connection = oConnLocal
oConnLocal.Open()
oDAlocal.Fill(oDSLocal)
Dim oRowLocal As DataRow
Dim x As Integer = 2
'Set header
xlSheet.Cells(1, 1) = "SUBJECT_ID"
xlSheet.Cells(1, 2) = "RESERVED"
xlSheet.Cells(1, 3) = "SLICE1_WHOLEARM_CSA"
xlSheet.Cells(1, 4) = "SLICE2_WHOLEARM_CSA"
xlSheet.Cells(1, 5) = "SLICE3_WHOLEARM_CSA"
xlSheet.Cells(1, 6) = "SLICE4_WHOLEARM_CSA"
xlSheet.Cells(1, 7) = "SLICE5_WHOLEARM_CSA"
xlSheet.Cells(1, 8) = "SLICE6_WHOLEARM_CSA"
xlSheet.Cells(1, 9) = "AVG_WHOLEARM_CSA"
xlSheet.Cells(1, 10) = "SLICE1_MARROW_CSA"
xlSheet.Cells(1, 11) = "SLICE2_MARROW_CSA"
xlSheet.Cells(1, 12) = "SLICE3_MARROW_CSA"
xlSheet.Cells(1, 13) = "SLICE4_MARROW_CSA"
xlSheet.Cells(1, 14) = "SLICE5_MARROW_CSA"
xlSheet.Cells(1, 15) = "SLICE6_MARROW_CSA"
xlSheet.Cells(1, 16) = "AVG_MARROW_CSA"
xlSheet.Cells(1, 17) = "SLICE1_BONE_MARROW_CSA"
xlSheet.Cells(1, 18) = "SLICE2_BONE_MARROW_CSA"
xlSheet.Cells(1, 19) = "SLICE3_BONE_MARROW_CSA"
xlSheet.Cells(1, 20) = "SLICE4_BONE_MARROW_CSA"
xlSheet.Cells(1, 21) = "SLICE5_BONE_MARROW_CSA"
xlSheet.Cells(1, 22) = "SLICE6_BONE_MARROW_CSA"
xlSheet.Cells(1, 23) = "AVG_BONE_MARROW_CSA"
xlSheet.Cells(1, 24) = "SLICE1_FAT_CSA"
xlSheet.Cells(1, 25) = "SLICE2_FAT_CSA"
xlSheet.Cells(1, 26) = "SLICE3_FAT_CSA"
xlSheet.Cells(1, 27) = "SLICE4_FAT_CSA"
xlSheet.Cells(1, 28) = "SLICE5_FAT_CSA"
xlSheet.Cells(1, 29) = "SLICE6_FAT_CSA"
xlSheet.Cells(1, 30) = "AVG_FAT_CSA"
xlSheet.Cells(1, 31) = "AVG_WHOLEMUSCLE_CSA"
xlSheet.Cells(1, 32) = "WHOLEARM_VOL"
xlSheet.Cells(1, 33) = "MARROW_VOL"
xlSheet.Cells(1, 34) = "BONE_MARROW_VOL"
xlSheet.Cells(1, 35) = "FAT_VOL"
xlSheet.Cells(1, 36) = "WHOLEMUSCLE_VOL"
For Each oRowLocal In oDSLocal.Tables(0).Rows
xlSheet.Cells(x, 1) = oRowLocal("SUBJECT_ID")
xlSheet.Cells(x, 2) = oRowLocal("RESERVED")
xlSheet.Cells(x, 3) = oRowLocal("SLICE1_WHOLEARM_CSA")
xlSheet.Cells(x, 4) = oRowLocal("SLICE2_WHOLEARM_CSA")
xlSheet.Cells(x, 5) = oRowLocal("SLICE3_WHOLEARM_CSA")
xlSheet.Cells(x, 6) = oRowLocal("SLICE4_WHOLEARM_CSA")
xlSheet.Cells(x, 7) = oRowLocal("SLICE5_WHOLEARM_CSA")
xlSheet.Cells(x, 8) = oRowLocal("SLICE6_WHOLEARM_CSA")
xlSheet.Cells(x, 9) = oRowLocal("AVG_WHOLEARM_CSA")
xlSheet.Cells(x, 10) = oRowLocal("SLICE1_MARROW_CSA")
xlSheet.Cells(x, 11) = oRowLocal("SLICE2_MARROW_CSA")
xlSheet.Cells(x, 12) = oRowLocal("SLICE3_MARROW_CSA")
xlSheet.Cells(x, 13) = oRowLocal("SLICE4_MARROW_CSA")
xlSheet.Cells(x, 14) = oRowLocal("SLICE5_MARROW_CSA")
xlSheet.Cells(x, 15) = oRowLocal("SLICE6_MARROW_CSA")
xlSheet.Cells(x, 16) = oRowLocal("AVG_MARROW_CSA")
xlSheet.Cells(x, 17) = oRowLocal("SLICE1_BONE_MARROW_CSA")
xlSheet.Cells(x, 18) = oRowLocal("SLICE2_BONE_MARROW_CSA")
xlSheet.Cells(x, 19) = oRowLocal("SLICE3_BONE_MARROW_CSA")
xlSheet.Cells(x, 20) = oRowLocal("SLICE4_BONE_MARROW_CSA")
xlSheet.Cells(x, 21) = oRowLocal("SLICE5_BONE_MARROW_CSA")
xlSheet.Cells(x, 22) = oRowLocal("SLICE6_BONE_MARROW_CSA")
xlSheet.Cells(x, 23) = oRowLocal("AVG_BONE_MARROW_CSA")
xlSheet.Cells(x, 24) = oRowLocal("SLICE1_FAT_CSA")
xlSheet.Cells(x, 25) = oRowLocal("SLICE2_FAT_CSA")
xlSheet.Cells(x, 26) = oRowLocal("SLICE3_FAT_CSA")
xlSheet.Cells(x, 27) = oRowLocal("SLICE4_FAT_CSA")
xlSheet.Cells(x, 28) = oRowLocal("SLICE5_FAT_CSA")
xlSheet.Cells(x, 29) = oRowLocal("SLICE6_FAT_CSA")
xlSheet.Cells(x, 30) = oRowLocal("AVG_FAT_CSA")
xlSheet.Cells(x, 31) = oRowLocal("AVG_WHOLEMUSCLE_CSA")
xlSheet.Cells(x, 32) = oRowLocal("WHOLEARM_VOL")
xlSheet.Cells(x, 33) = oRowLocal("MARROW_VOL")
xlSheet.Cells(x, 34) = oRowLocal("BONE_MARROW_VOL")
xlSheet.Cells(x, 35) = oRowLocal("FAT_VOL")
xlSheet.Cells(x, 36) = oRowLocal("WHOLEMUSCLE_VOL")
x = x + 1
Next
xlSheet.Name = "Rapidia Dataset"
xlSheet.SaveAs("C:\MyFile3.xls")
xlSheet.Application.Quit()
xlSheet = Nothing
oDSLocal = Nothing
oSqlCmdlocal = Nothing
Label3.Visible = True 1 3094
if anyone could help me, i'd really appreciate it! I've tried all the
suggestions that were similar to my problem, and nothing seems to be working.
I can't figure out why
1) My excel app is hidden even when I try to make it visible
2) When redownloading the data, I'm assuming that it's trying to overwrite
the old data, but giving an "are you sure" message. (My internet explorer
makes a "ching" sound, which I assume is the msg popping up, then it just
sits there and doesn't move fwd, however I can't see any of it because excel
is hidden) I would like to make it so that this msg does not popup, and it
automatically overwrites the old data. thanks!
"ST" wrote: Hi, I'm having problems opening up excel thru my code. It will write and saveas an excel file, but the application won't open on the user's computer, excel seems to be hidden, because it shows up on the task manager. The problem is, if this user tries to download the data more than once, it gets stuck because the file already exists, so I want it to overwrite the old file...but the user can't overwrite when the excel app won't work! Any suggestions? This is my code below:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim oDS As New DataSet Dim oConn As New SqlClient.SqlConnection("workstation id=CTR3_252A;packet size=4096;user id=sa;data source=CRI;persist security info=True;initial catalog=gfdgfd;password=gfdgfd") Dim oSqlCmd As New SqlClient.SqlCommand("SELECT * from dbo.MRI_HEATHERSTAT_VIEW") Dim oDA As New SqlClient.SqlDataAdapter(oSqlCmd)
oSqlCmd.Connection = oConn
oConn.Open()
oDA.Fill(oDS) oConn.Close()
Dim oRow As DataRow
For Each oRow In oDS.Tables(0).Rows Next Dim oDSLocal As New DataSet Dim oSqlCmdlocal As New SqlClient.SqlCommand("SELECT * from dbo.MRI_HEATHERSTAT_VIEW") Dim oDAlocal As New SqlClient.SqlDataAdapter(oSqlCmdlocal) Dim oConnLocal As New SqlClient.SqlConnection("workstation id=CTR3_252A;packet size=4096;user id=sa;data source=CRI;persist security info=True;initial catalog=gfdgfd;password=gfdgfd")
Dim xlApp As Excel.Application Dim xlBook As Excel.Workbook Dim xlAELBook As Excel.Workbook Dim xlAELSheet As Excel.Worksheet Dim xlSheet As Excel.Worksheet xlApp = CType(CreateObject("Excel.Application"), Excel.Application) xlBook = CType(xlApp.Workbooks.Add, Excel.Workbook) xlSheet = CType(xlBook.Worksheets(1), Excel.Worksheet)
xlApp.Visible = True xlSheet.Visible = True
xlSheet.Application.Visible = True oSqlCmdlocal.Connection = oConnLocal
oConnLocal.Open()
oDAlocal.Fill(oDSLocal)
Dim oRowLocal As DataRow Dim x As Integer = 2
'Set header xlSheet.Cells(1, 1) = "SUBJECT_ID" xlSheet.Cells(1, 2) = "RESERVED" xlSheet.Cells(1, 3) = "SLICE1_WHOLEARM_CSA" xlSheet.Cells(1, 4) = "SLICE2_WHOLEARM_CSA" xlSheet.Cells(1, 5) = "SLICE3_WHOLEARM_CSA" xlSheet.Cells(1, 6) = "SLICE4_WHOLEARM_CSA" xlSheet.Cells(1, 7) = "SLICE5_WHOLEARM_CSA" xlSheet.Cells(1, 8) = "SLICE6_WHOLEARM_CSA" xlSheet.Cells(1, 9) = "AVG_WHOLEARM_CSA" xlSheet.Cells(1, 10) = "SLICE1_MARROW_CSA" xlSheet.Cells(1, 11) = "SLICE2_MARROW_CSA" xlSheet.Cells(1, 12) = "SLICE3_MARROW_CSA" xlSheet.Cells(1, 13) = "SLICE4_MARROW_CSA" xlSheet.Cells(1, 14) = "SLICE5_MARROW_CSA" xlSheet.Cells(1, 15) = "SLICE6_MARROW_CSA" xlSheet.Cells(1, 16) = "AVG_MARROW_CSA" xlSheet.Cells(1, 17) = "SLICE1_BONE_MARROW_CSA" xlSheet.Cells(1, 18) = "SLICE2_BONE_MARROW_CSA" xlSheet.Cells(1, 19) = "SLICE3_BONE_MARROW_CSA" xlSheet.Cells(1, 20) = "SLICE4_BONE_MARROW_CSA" xlSheet.Cells(1, 21) = "SLICE5_BONE_MARROW_CSA" xlSheet.Cells(1, 22) = "SLICE6_BONE_MARROW_CSA" xlSheet.Cells(1, 23) = "AVG_BONE_MARROW_CSA" xlSheet.Cells(1, 24) = "SLICE1_FAT_CSA" xlSheet.Cells(1, 25) = "SLICE2_FAT_CSA" xlSheet.Cells(1, 26) = "SLICE3_FAT_CSA" xlSheet.Cells(1, 27) = "SLICE4_FAT_CSA" xlSheet.Cells(1, 28) = "SLICE5_FAT_CSA" xlSheet.Cells(1, 29) = "SLICE6_FAT_CSA" xlSheet.Cells(1, 30) = "AVG_FAT_CSA" xlSheet.Cells(1, 31) = "AVG_WHOLEMUSCLE_CSA" xlSheet.Cells(1, 32) = "WHOLEARM_VOL" xlSheet.Cells(1, 33) = "MARROW_VOL" xlSheet.Cells(1, 34) = "BONE_MARROW_VOL" xlSheet.Cells(1, 35) = "FAT_VOL" xlSheet.Cells(1, 36) = "WHOLEMUSCLE_VOL"
For Each oRowLocal In oDSLocal.Tables(0).Rows
xlSheet.Cells(x, 1) = oRowLocal("SUBJECT_ID") xlSheet.Cells(x, 2) = oRowLocal("RESERVED") xlSheet.Cells(x, 3) = oRowLocal("SLICE1_WHOLEARM_CSA") xlSheet.Cells(x, 4) = oRowLocal("SLICE2_WHOLEARM_CSA") xlSheet.Cells(x, 5) = oRowLocal("SLICE3_WHOLEARM_CSA") xlSheet.Cells(x, 6) = oRowLocal("SLICE4_WHOLEARM_CSA") xlSheet.Cells(x, 7) = oRowLocal("SLICE5_WHOLEARM_CSA") xlSheet.Cells(x, 8) = oRowLocal("SLICE6_WHOLEARM_CSA") xlSheet.Cells(x, 9) = oRowLocal("AVG_WHOLEARM_CSA") xlSheet.Cells(x, 10) = oRowLocal("SLICE1_MARROW_CSA") xlSheet.Cells(x, 11) = oRowLocal("SLICE2_MARROW_CSA") xlSheet.Cells(x, 12) = oRowLocal("SLICE3_MARROW_CSA") xlSheet.Cells(x, 13) = oRowLocal("SLICE4_MARROW_CSA") xlSheet.Cells(x, 14) = oRowLocal("SLICE5_MARROW_CSA") xlSheet.Cells(x, 15) = oRowLocal("SLICE6_MARROW_CSA") xlSheet.Cells(x, 16) = oRowLocal("AVG_MARROW_CSA") xlSheet.Cells(x, 17) = oRowLocal("SLICE1_BONE_MARROW_CSA") xlSheet.Cells(x, 18) = oRowLocal("SLICE2_BONE_MARROW_CSA") xlSheet.Cells(x, 19) = oRowLocal("SLICE3_BONE_MARROW_CSA") xlSheet.Cells(x, 20) = oRowLocal("SLICE4_BONE_MARROW_CSA") xlSheet.Cells(x, 21) = oRowLocal("SLICE5_BONE_MARROW_CSA") xlSheet.Cells(x, 22) = oRowLocal("SLICE6_BONE_MARROW_CSA") xlSheet.Cells(x, 23) = oRowLocal("AVG_BONE_MARROW_CSA") xlSheet.Cells(x, 24) = oRowLocal("SLICE1_FAT_CSA") xlSheet.Cells(x, 25) = oRowLocal("SLICE2_FAT_CSA") xlSheet.Cells(x, 26) = oRowLocal("SLICE3_FAT_CSA") xlSheet.Cells(x, 27) = oRowLocal("SLICE4_FAT_CSA") xlSheet.Cells(x, 28) = oRowLocal("SLICE5_FAT_CSA") xlSheet.Cells(x, 29) = oRowLocal("SLICE6_FAT_CSA") xlSheet.Cells(x, 30) = oRowLocal("AVG_FAT_CSA") xlSheet.Cells(x, 31) = oRowLocal("AVG_WHOLEMUSCLE_CSA") xlSheet.Cells(x, 32) = oRowLocal("WHOLEARM_VOL") xlSheet.Cells(x, 33) = oRowLocal("MARROW_VOL") xlSheet.Cells(x, 34) = oRowLocal("BONE_MARROW_VOL") xlSheet.Cells(x, 35) = oRowLocal("FAT_VOL") xlSheet.Cells(x, 36) = oRowLocal("WHOLEMUSCLE_VOL")
x = x + 1
Next
xlSheet.Name = "Rapidia Dataset" xlSheet.SaveAs("C:\MyFile3.xls") xlSheet.Application.Quit() xlSheet = Nothing oDSLocal = Nothing oSqlCmdlocal = Nothing
Label3.Visible = True This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: |
last post by:
I have a web page written in asp.net that has multiple datagrids on it that
would need to be exported to Excel. Each of the datagrids would be a subset
of what the datagrid above it was.
Thus...
|
by: hari krishna |
last post by:
hi,
I want to send the data from dataset information to Excel through ASP.Net.
there will be no XL installed on web server. web server is win 2000 server
machine. I am using visual basic code in...
|
by: Ken Hall |
last post by:
Is it possible to create an Excel spreadsheet using VB.NET without
opening the Excel application or having to have the Excel application
on the operating computer?
KH
|
by: Anthony |
last post by:
To me, creating Excel 2003 spreadsheets programmatically via VB.NET hasn't
really changed since the days of VB6.
That is, I'd do something similar to this
Code:
Dim ExcelApp As...
|
by: ST |
last post by:
Hi, I'm having problems opening up excel thru my code. It will write and
saveas an excel file, but the application won't open on the user's computer,
excel seems to be hidden, because it shows up...
|
by: Jacob.Bruxer |
last post by:
Hi everyone,
I'm having trouble opening space delimited textfiles in Excel from
Visual Basic.net. I'm able to control, open and modify Excel files
from Visual Basic, so my Excel reference seems...
|
by: Gorgo |
last post by:
Hello
I'm sorry if this is not the right group to post this post, but
unfortunetly this one is one of the best i know.
I'm doing and asp.net application with need to create excel file thru...
|
by: Mad Scientist Jr |
last post by:
>From an asp.net web page I want the user to open the results of a SQL
query in Excel, as automatically as possible (ie not having to loop
through columns, rows, in code).
For this,...
|
by: Phil Stanton |
last post by:
I have a form with a button which is supposed to open an Excel file (With
lots of Macros /VBA) in it. The Excel file gets it's data from the Access
program
Here is the code
Private Sub...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
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...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
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...
| |