データを保存する.netアプリケーションをExcelに構築しました。アプリケーションを手動で実行すると、プログラムはデータテーブルのデータをExcelに保存します。問題は、自分のWindows 10 PCで実行するタスクをスケジュールすると、以下のエラーが発生することです。vb.net - excel - windowsタスクの問題
:System.Runtime.InteropServices.COMException(0x800A03EC):HRESULTからの例外:Microsoft.Office.Interop.Excel.WorkbookClass.SaveAsで0x800A03EC は(ReadOnlyRecommendedオブジェクト、WriteResPasswordオブジェクト、FileFormatは、オブジェクトパスワードオブジェクト、ファイル名をオブジェクトCreateBackup、XlSaveAsAccessMode ACCESSMODEは、ConflictResolutionオブジェクトオブジェクト、AddToMruオブジェクト、TextCodepageオブジェクト、TextVisualLayoutオブジェクト、ローカルオブジェクト)
Public Shared Function CreateExcel() As Microsoft.Office.Interop.Excel.ApplicationClass
For retry As Integer = 1 To 5
Try
clsScrape.SendMail(" Return New Microsoft.Office.Interop.Excel.ApplicationClass")
Return New Microsoft.Office.Interop.Excel.ApplicationClass
Exit For
Catch ex As Exception
If ex.HResult <> &H80080005 Then Throw ex
End Try
Next
Return Nothing
End Function
Public Shared Sub ExportExceltest(ByVal excel As Microsoft.Office.Interop.Excel.ApplicationClass)
Try
Dim dt As New DataTable
dt.Columns.Add("ID")
dt.Columns.Add("Name")
Dim R As DataRow = dt.NewRow
R("Name") = "MY Name"
dt.Rows.Add(R)
Dim strFile As String = "C:\Users\CodeMonger\Documents\Development\Test" & DateTime.Now.ToString("yyyy_MM_dd HH_mm_ss") & ".xlsx"
' Dim excel As New Microsoft.Office.Interop.Excel.ApplicationClass
Dim wBook As Microsoft.Office.Interop.Excel.Workbook
Dim wSheet As Microsoft.Office.Interop.Excel.Worksheet
wBook = excel.Workbooks.Add()
wSheet = wBook.ActiveSheet()
Dim dc As System.Data.DataColumn
Dim dr As System.Data.DataRow
Dim colIndex As Integer = 0
Dim rowIndex As Integer = 0
For Each dc In dt.Columns
colIndex = colIndex + 1
excel.Cells(1, colIndex) = dc.ColumnName
Next
For Each dr In dt.Rows
rowIndex = rowIndex + 1
colIndex = 0
For Each dc In dt.Columns
colIndex = colIndex + 1
excel.Cells(rowIndex + 1, colIndex) = dr(dc.ColumnName)
Next
Next
clsScrape.SendMail("The datatable was built and this is Right before save")
wSheet.Columns.AutoFit()
wBook.SaveAs(strFile)
wBook.Close()
Catch ex As Exception
clsScrape.SendMail("Here is the Issue :" & ex.ToString)
End Try
End Sub
オーケー)あなたの 特定の構成のための再検証この情報を示唆しているだから私はあなたの提案を試してみましたが、それが問題 – CodeMonger
を修正するために現れなかった私は、どのようにあなたの答えを組み込むために上記のコードを変更コンストラクタを使ってeを構築していますxcel。 – CodeMonger
@CodeMongerは、元の質問/回答が今後誰かを助けたかもしれないので、答えを受け入れて新しい質問をすることを検討しています。 新しい問題は、この[質問](http://stackoverflow.com/questions/15597490/exception-from-hresult-0x800a03ec-error-while-saving-excel-file)と重複している可能性があります。ファイルパスをダブルチェックし、プログラムがパスに読み書きできることを確認します。 – RamblinRose