|
Using VWD2008 and Office 2010 - I am trying to create an excel object.
When run through VWD, a spreadsheet is created, formatted and saved fine. When the code is compiled (and run on the same machine), the create object or new Excel.Application falls over.
1) as object using Microsoft.Office.Core dll:
Dim xlApp As Object = CreateObject("Excel.Application")
2) As Excel application using Microsoft.Office.Interop.Excel dll
Dim xlApp As Application = New Application
|
|
|
|
|
Are we supposed to guess the exception that's thrown when the code "falls over"?
Provide the full details of the exception, the line of code where it's thrown, and any relevant parts of the surrounding code.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
The exception message was 'Cannot create ActiveX component.' I have updated the DCOM config permissions for Excel Application and restarted IIS, but still no joy
The following is all of the code behind (this page is cut down from a page that gets mountains of data - just to test the create & save excel part )
Imports CommonFunctions
Imports Microsoft.VisualBasic
Imports Microsoft.Office.Core
Imports System.Data
Imports System.Data.SqlClient
Imports System.IO
Partial Class FEMain_ContractAdmin_TestExcel2
Inherits System.Web.UI.Page
Dim objCF As New CommonFunctions
Protected Sub btnKPI_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnKPI.Click
Dim xlApp As Object
Try
xlApp = CreateObject("Excel.Application")
Catch ex As Exception
objCF.logError(System.IO.Path.GetFileName(System.Web.HttpContext.Current.Request.Url.AbsolutePath) & " :: " & System.Reflection.MethodBase.GetCurrentMethod().Name, ex.Message)
Exit Sub
End Try
Dim xlWorkBook As Object
Dim xlWorksheet As Object
Dim misValue As Object = System.Reflection.Missing.Value
xlWorkBook = xlApp.Workbooks.Add(misValue)
xlWorksheet = xlWorkBook.Sheets("Sheet1")
xlWorksheet.Cells(1, 1) = "Test 123456"
Dim strSavePath As String
Dim strFilename As String
Dim strFullPath As String
strSavePath = AppDomain.CurrentDomain.BaseDirectory & "Documents\KPI\Concerns\"
'create kpi concern directory
If (Not Directory.Exists(strSavePath)) Then
Directory.CreateDirectory(strSavePath)
End If
strFilename = "Test_" & CStr(Date.Now.Year) & objCF.addZeros(CStr(Date.Now.Month), 2) & objCF.addZeros(CStr(Date.Now.Day), 2) & "_" & objCF.addZeros(CStr(Date.Now.Hour), 2) & objCF.addZeros(CStr(Date.Now.Minute), 2) & objCF.addZeros(CStr(Date.Now.Second), 2) & objCF.addZeros(CStr(Date.Now.Millisecond), 3) & ".xlsx"
strFullPath = strSavePath & strFilename
'save and close
xlWorkBook.SaveAs(strSavePath & strFilename)
xlWorkBook.Close(True, misValue, misValue)
xlApp.Quit()
'release COM objects
Call objCF.releaseObject(xlWorksheet)
Call objCF.releaseObject(xlWorkBook)
Call objCF.releaseObject(xlApp)
'show the hyperlink to the excel file
hypKPI.Visible = True
hypKPI.NavigateUrl = "~\Documents\KPI\Concerns\" & strFilename
End Sub
End Class
|
|
|
|
|
You should read the following Microsoft knowledgebase article:
Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.
It documents the various hoops that you'll have to jump through to stand any chance of getting Office Interop working in ASP.NET; however, there is no guarantee that you'll be able to get it working, or that it won't stop working at some random point in the future.
There are various ways to read and create Excel spreadsheets on the server without using Office interop. For example:
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Also, if you're on a 64-bit OS, check your AppPool settings to make sure you've selected "Enable 32-bit Applications". A 64-bit AppPool won't be able to create and use an instance of a 32-bit COM component.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Why are you defining everything as Object? That's actually going to hurt you, not help you. You loe all type safety when you do that.
|
|
|
|
|
DAH_bham wrote: strFilename = "Test_" & CStr(Date.Now.Year) & objCF.addZeros(CStr(Date.Now.Month), 2) & objCF.addZeros(CStr(Date.Now.Day), 2) & "_" & objCF.addZeros(CStr(Date.Now.Hour), 2) & objCF.addZeros(CStr(Date.Now.Minute), 2) & objCF.addZeros(CStr(Date.Now.Second), 2) & objCF.addZeros(CStr(Date.Now.Millisecond), 3) & ".xlsx"
You really need to look at Custom Date and Time Format Strings[^] and the String.Format method[^]:
strFilename = String.Format("Test_{0:yyyyMMdd_HHmmssfff}.xlsx", Date.Now)
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I tried Excel Package (OpenOfficeXML) instead of Office COM dlls and it worked fine for my needs -
thanks for your help.
|
|
|
|
|
Oh, and one more thing. The code is never interpreted when running in the debugger. It's always compiled into an .executable and launched.
|
|
|
|
|
I am using the progress bar supplied with VB 2013 - everything works as it should except that the "flying left to right highlight animation" does not work - the moving bar is just the flat solid colour. On the designer I see the "highlight flying" effect but not when I run or test the .exe file! I have searched everywhere for any clues and so far hit a blank wall. Is there some property I should be setting on the progress bar to achieve this? Any clue would be appreciated.
All the best and TIA.
HotBlue
|
|
|
|
|
What operating system?
What do you get when you cross a joke with a rhetorical question?
The metaphorical solid rear-end expulsions have impacted the metaphorical motorized bladed rotating air movement mechanism.
Do questions with multiple question marks annoy you???
|
|
|
|
|
Sorry - I should have included this. I used Win 7, 8.1 and 10 with Framework 4.0 - all gave the same results, flat colour and no highlight fly by.
|
|
|
|
|
How are you updating the progress bar?
|
|
|
|
|
The bar updates when an action has completed within a loop thus:
; Initialise
frm_Splash.bar_Loading.Width = 390
ffrm_Splash.bar_Loading.Maximum = 39
rm_Splash.bar_Loading.Style = ProgressBarStyle.Continuous
frm_Splash.bar_Loading.Enabled = True
frm_Splash.bar_Loading.Visible = True
frm_Splash.bar_Loading.Value = 0
ActionLevel = 0
; Working loop.
For I = 0 to 39
; ... working code here.
ActionLevel += 1 ; Advance Progress Bar.
frm_Splash.bar_Loading.Value = ActionLevel
Application.DoEvents()
Next
The bar progresses normally but no highlight "flyby" animation.
|
|
|
|
|
|
Thanks - tried both - still no "fly-across"!
|
|
|
|
|
I do not think you will see any changes since your progress bar is most likely not being updated as you expect. You need to create a background thread that updates the control as your application progresses or processes some data.
|
|
|
|
|
Did you set the "marquis" style?
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
I set the marquis to De Sade but that just hurt the program!
My .style setting is "continuous" which only gives a solid colour with no "fly by".
|
|
|
|
|
i'm trying to locate a file inside a textbox (full path i.e. "I:\movie collections\Gigantic - 2008 - Zooey Dechanel.mp4" = MovieURLTextbox.text) and display it in windows explorer. below code works fine with short filenames but would go to the default mydocuments with long filenames. please help... thnx!
Dim fileToFind As String
fileToFind = MovieURLTextBox.Text
Call Shell("explorer /select," & fileToFind, AppWinStyle.NormalFocus)
modified 4-Oct-15 2:58am.
|
|
|
|
|
What does this mean, exactly?
Member 12029698 wrote: but would go to the default mydocuments with long filenames
Did you try putting quotes around the long filename?
fileToFind = """" & fileToFind & """"
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
thnx...
I meant with long filenames, the code would take me to "my computer" (not "my documents", my bad);
e.g.
I:\movie collections\Me and Earl and the Dying Girl - 2015 - Thomas Mann, RJ Cyler, Olivia Cooke.mkv
while, "I:\movie collections\Gigantic - 2008 - Zooey Dechanel.mp4" will do as the code is intended
|
|
|
|
|
I think it's the presence of the "comma" in the path... I tried removing the "comma" and the code works fine.
|
|
|
|
|
finally made it worked with code below;
Dim filePath As String = MovieURLTextBox.Text
Try
Process.Start("Explorer.exe", "/n,/e,/select, """ & filePath & """")
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
looks like process.start and the double quotes on the file path was the solution to my problem.
hope this can help others too...
|
|
|
|
|
Good day friends! I need your help in this issue. I know vb6 is outdated but this has to be done in vb6. I add ms access database to a resource file in my vb6 app but am finding it difficult to add new record, search the database, delete record from it etc. How can I achieved this in vb6 resource file. Thanks in advance!
|
|
|
|