Home > Net >  Everyone a great god, the trouble to help me look at the Windows services cannot export Excel docume
Everyone a great god, the trouble to help me look at the Windows services cannot export Excel docume

Time:04-13

Everyone a great god, I want to be a Windows service, you can export Excel documents regularly, but now I met can't save the bottleneck,
Load service on my own laptop, export Excel document don't have any problem, my notebook system is Windows 7 Pro, using VS2008 (written in vb language code, and install MS Office 2013 Chinese version, but the service of the files in other machines, with Windows 7 Pro, Windows Server 2008 R2, Windows Server 2012 R2, error
I put in the Dcom Excel Application in accordance with my notebook set the same Settings, also on the Internet to find some solution, but now code execution to save the worksheet times wrong,
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
unable to start the service, System.Runtime.InteropServices.COM Exception (0 x800a03ec) : abnormal from HRESULT: 0 x800a03ec
In Microsoft. Office. Interop. Excel. _Worksheet. SaveAs (String Filename, Object FileFormat and Object Password, Object WriteResPassword, Object ReadOnlyRecommended, Object CreateBackup, Object AddToMru, Object TextCodepage, Object TextVisualLayout, Object Local)
In ServiceTest) ServiceTest) ExcelTest (position) E: \ \ software ServiceTest \ ServiceTest \ ServiceTest vb: line number 50
In ServiceTest. ServiceTest. OnStart (String [] args) location E: \ \ software ServiceTest \ ServiceTest \ ServiceTest vb: line number 66
In the System. ServiceProcess. ServiceBase. ServiceQueuedMainCallback (Object state)

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
This code on my first, trouble you help me to look at the great god, if the code has a problem,
 Option Explicit On 

Imports Microsoft. Office. Interop

Public Class ServiceTest

Private Sub ExcelTest ()
Dim xlApp As Excel. Application
Dim xlWorkBook As Excel. The Workbook
Dim xlWorkSheet As Excel. The Worksheet

XlApp=New Microsoft. Office. Interop. Excel. Application
XlApp. DisplayAlerts=False
XlApp. SheetsInNewWorkbook=1
XlApp=CreateObject (" Excel. Application ") 'note 1: if you don't join the sentence and the sentence code is
XlApp. DefaultSaveFormat=Excel. XlFileFormat. XlExcel8 'note 1: in xlWorkBook=xlApp. Workbooks. Add error
XlWorkBook=xlApp. Workbooks. Add 'note 1: the later I send an error message attached behind,
XlWorkSheet=xlWorkBook. Sheets. The Item (1)

With xlWorkSheet
Activate ()
Materials into the factory. The Name="general ledger"

. Cells. The Select ()
. Cells. NumberFormatLocal="@"
. Cells. VerticalAlignment=Excel. The xlCenter
. Cells. HorizontalAlignment=Excel. The xlCenter
. Cells. WrapText=True
11.. Cells. The Font Size=
. Cells. The Font. The Name="tahoma"

. The PageSetup. Orientation=Excel. XlPageOrientation. XlLandscape
. PageSetup. LeftMargin=xlApp. InchesToPoints (0.31496062992126)
. PageSetup. RightMargin=xlApp. InchesToPoints (0.31496062992126)
. The PageSetup. CenterHorizontally=True
. The PageSetup. Zoom=96
. The PageSetup. PrintTitleRows="$1: $5"

Range (" A2: N2 "). The Merge ()
Range (" A2 "). RowHeight=26.25
Range (" A2 "). The Font. The Size=16
Range (" A2 "). The Font. Bold=True
Cells (2, 1)="materials into the factory general ledger
"
Range (A3: "C3"). The Merge ()
Range (" A3 "). RowHeight=12.75
Range (" A3 "). The HorizontalAlignment=Excel. The xlLeft
Cells (3, 1)=", "annual & amp; Year (DateTime. Now). ToString. Trim & amp; "Year"

SaveAs (" C: \ 1. XLSX ") 'note 2: if the program execution to normal after the code also complains,
'also tried in subsequent face should join parameters is the same fault error
'I also tried to put this code in the execution is no error in Windows forms, direct export data,
'don't need behind the SaveAs join parameters, only need to save the path and filename can
'SaveAs (Filename:="c: \ \ 1 ST. XLS", FileFormat:=Excel. XlFileFormat. XlOpenXMLWorkbook, CreateBackup:=False)
End With

'xlWorkBook. SaveAs (" C: \ 1. XLSX, Excel. XlFileFormat. XlWorkbookNormal, the Missing, the Missing, False, False, Excel. XlSaveAsAccessMode. XlNoChange, the Missing, the Missing, the Missing, the Missing, the Missing)

XlWorkBook=Nothing
XlApp. Application. Workbooks. The Close ()
XlApp. SheetsInNewWorkbook=3
XlApp. Quit ()
XlApp=Nothing
End Sub

Protected Overrides Sub OnStart (ByVal args () As String)
ExcelTest ()
End Sub
The End of the Class


[] note 1 error message (without xlApp=CreateObject (" Excel. Application ") and xlApp DefaultSaveFormat=Excel. XlFileFormat. XlExcel8 this two code in xlWorkBook=xlApp Workbooks. Add error) :
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
System.Runtime.IneropServices.CoM "Exception" type of untreated abnormalities in ServicesTest. Exe, in
Other information: out of memory or disk space is insufficient, Microsoft Excel is unable to open or save any documents again,

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

(note 2) error message (if have add xlApp=CreateObject (" Excel. Application ") and xlApp DefaultSaveFormat=Excel. XlFileFormat. That xlExcel8 code, in xlWorkSheet. SaveAs (" C: \ 1. XLSX) error)
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
unable to start the service, System.Runtime.InteropServices.COM Exception (0 x800a03ec) : abnormal from HRESULT: 0 x800a03ec
nullnullnullnullnullnullnullnullnullnull
  • Related