Principale utente con più risposte
compattazione di file .rtf in un unico file

Domanda
-
ho recuperato la seguente routine che opera correttamente, ma come scrito in calce ad essa dovrei anziché visualizzare il file rtf compattato, scriverlo in una cartella con un nome.rtf a discrezione.
grazie per l'aiuto.
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
Dim fileArray As New ArrayList
Dim intCount As Integer = 0
DirLav = TextBox2.Text
Dim dirInfo As DirectoryInfo = New DirectoryInfo(DirLav) ' mancano nel codice
Dim fiArr As New Microsoft.VisualBasic.Collection() ' mancano del codice
'== Create an object of WORD.
Dim objWord As New Microsoft.Office.Interop.Word.Application
Dim str As String = ""
'== Loop through the collection of documents and add to main word document
For Each fi As System.IO.FileInfo In dirInfo.GetFiles("*.rtf") ' dirInfo : is the directory where all the separate docs are saved
If Not fileArray.Contains(fi.FullName) Then ' Check if document is not already added.
If intCount = 0 Then
objWord.Documents.Add(fi.FullName) ' for the first document to be added use Documents.Add method
Else
objWord.Selection.InsertBreak()
objWord.Selection.InsertFile(FileName:=fi.FullName, Range:="", ConfirmConversions:=False, Link:=False, Attachment:=False) ' next time onwards use InsertFile method
End If
objWord.Selection.EndKey(Unit:=6) ' set the control \ cursor to the end of the document to insert next in the new page
intCount += 1 ' increment count by 1
fiArr.Add(fi.FullName) ' add the merged document to the collection
End If
Next
'== Delete all separate documents from folder after merge
For Each fi As System.IO.FileInfo In dirInfo.GetFiles("*.rtf")
fi.Delete()
Next
'== Make the main document visible
'****************************************************************
' anzichè semplicemente rendere il file compattato visibile io vorrei archiviarlo su una cartella a piacere es : "C:\Users\mirco\Desktop\Kdrill\stampertf"
' e con un nomefile di tipo rtf a mia discrezione es: "fattura.rtf"
'************************************************************
If Not objWord.Visible Then
objWord.Visible = True
End If
End Sub
Risposte
-
io eliminerei la cancellazione dei file originali ed anche la visualizzazione del risultato ed aggiungerei
objWord.ActiveDocument.SaveAs2(TextBox2.Text + "\fatture.rtf")
objWord.Quit()- Modificato patel45 domenica 6 ottobre 2019 16:38
- Proposto come risposta Yordan IvanovMicrosoft contingent staff, Moderator lunedì 7 ottobre 2019 08:16
- Contrassegnato come risposta Evgin IsmailMicrosoft contingent staff martedì 8 ottobre 2019 05:33
Tutte le risposte
-
io eliminerei la cancellazione dei file originali ed anche la visualizzazione del risultato ed aggiungerei
objWord.ActiveDocument.SaveAs2(TextBox2.Text + "\fatture.rtf")
objWord.Quit()- Modificato patel45 domenica 6 ottobre 2019 16:38
- Proposto come risposta Yordan IvanovMicrosoft contingent staff, Moderator lunedì 7 ottobre 2019 08:16
- Contrassegnato come risposta Evgin IsmailMicrosoft contingent staff martedì 8 ottobre 2019 05:33
-