もともと DTS パッケージに基づいたレポート システムを自動化するアプリケーションがあります。Web ベースのアプリは現在、出力 xls ファイルをネットワーク上の別のサーバーに書き込んでいます。Web サイトを閉じた後も、書き込み中のサーバー上で Excel のインスタンスが実行されたままになっていることがわかりました。終了ルーチンを xls ファイルではなく csv ファイルを出力するように変更するか、ネットワーク接続されたマシン全体で EXCEL.exe プロセスを強制終了できるようにしたいと考えています。助けてください!
編集:ファイル拡張子を変更してcsvとして保存すると、ファイルは次のようになります
その図が小さすぎる場合、基本的には行が分離されていることを示していますが、列は分離されていません。列を区切るためにコンマがあるべき場所には、代わりに疑問符の付いた小さなボックスがあります
これが.xlsファイルを書くための私の現在のルーチンです
Public Sub DisplayandConvertToXLS()
Dim i As Integer
Dim ds As New DataSet
Dim da As SqlDataAdapter
Dim objFileStream As FileStream
Dim objStreamWriter As StreamWriter
Dim fs As Object, myFile As Object
Dim cnn As SqlConnection = New SqlConnection("DataSource=dpsdb;InitialCatalog=productionservicereminder;User Id=id;Password=pass;")
Dim strLine, filePath, fileExcel As String
'Create a file name.
fileExcel = FileNameTxt.Text & ".xls"
'Set a virtual folder to save the file.
'Make sure that you change the application name to match your folder.
filePath = "\\10.1.2.4\SRS Shortcuts\Export\SQL Output\CSV Reports\"
fileName = filePath & FolderNameTXT.Text & "/" & fileExcel
'Use FileStream to create the .xls file.
objFileStream = New FileStream(fileName, FileMode.OpenOrCreate, FileAccess.Write)
objStreamWriter = New StreamWriter(objFileStream)
'Use a DataReader to connect to the database.
cnn.Open()
Dim sql3 As String = DisplayQTXT.Text
Dim cmd As SqlCommand = New SqlCommand(sql3, cnn)
cmd.Parameters.Add(New SqlParameter("@ProgramGroupID", PgidTXT.Text))
Dim drr As SqlDataReader
drr = cmd.ExecuteReader()
'Enumerate the field names and records that are used to build the file.
For i = 0 To drr.FieldCount - 1
strLine = strLine & drr.GetName(i).ToString & Chr(9)
Next
'Write the field name information to file.
objStreamWriter.WriteLine(strLine)
'Reinitialize the string for data.
strLine = ""
'Enumerate the database that is used to populate the file.
While drr.Read()
For i = 0 To drr.FieldCount - 1
strLine = strLine & drr.GetValue(i) & Chr(9)
Next
objStreamWriter.WriteLine(strLine)
strLine = ""
End While
'Clean up.
drr.Close()
cnn.Close()
ds.Clear()
objStreamWriter.Close()
objFileStream.Close()
objStreamWriter.Dispose()
objFileStream.Dispose()
End Sub