Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
Imports Word = Microsoft.Office.Interop.Word
Imports Microsoft.Office.Interop
Imports System.Runtime.InteropServices
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim doc As New Word.Document
Dim WordApp As New Word.Application()
Dim file As Object = "Z:\j.doc"
Dim Nothingobj As Object = System.Reflection.Missing.Value
doc = WordApp.Documents.Open(file, Nothingobj, Nothingobj, Nothingobj, Nothingobj, Nothingobj, Nothingobj, Nothingobj, Nothingobj, Nothingobj, Nothingobj, Nothingobj)
doc.ActiveWindow.Selection.WholeStory()
doc.ActiveWindow.Selection.Copy()
Dim data As IDataObject = Clipboard.GetDataObject()
doc.Close()
End Sub
Private Sub DesarToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim saveFileDialog1 As New SaveFileDialog()
saveFileDialog1.Filter = "Document de Word Convertit|*.doc"
saveFileDialog1.Title = "Guardar Document de Word Convertit"
saveFileDialog1.ShowDialog()
If saveFileDialog1.ShowDialog() = DialogResult.OK Then
RichTextBox1.SaveFile(saveFileDialog1.FileName, _
RichTextBoxStreamType.PlainText)
MsgBox("correcto")
End If
End Sub
Private Sub SortirToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
End
End Sub
Private Sub ConvertirDocumentToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ConvertirDocumentToolStripMenuItem.Click
End Sub
Private Sub ObrirDocumentToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ObrirDocumentToolStripMenuItem.Click
RichTextBox1.Text = ""
End Sub
Private Sub GuardarToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GuardarToolStripMenuItem.Click
End Sub
Private Sub GenerarWordToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GenerarWordToolStripMenuItem.Click
Dim saveFileDialog1 As New SaveFileDialog()
saveFileDialog1.Filter = "Word Final |*.doc"
saveFileDialog1.Title = "Document de Word Final "
If saveFileDialog1.ShowDialog() = DialogResult.OK Then
' Create Word Application
Dim oWord As Object
oWord = CreateObject("Word.Application")
' Create new word document
Dim doc As New Word.Document
oWord.ScreenUpdating = False
ToolStripStatusLabel1.Text = "Word obert"
Dim file As Object = saveFileDialog1.FileName
Dim data As IDataObject = Clipboard.GetDataObject()
Dim oTable As Word.Table
Dim datos(0 To RichTextBox1.Lines.GetLength(0), 0 To 2) As String
Dim i As Integer
i = 0
Dim lines() As String = RichTextBox1.Lines
Dim doit As String
doit = "false"
For Each line As String In RichTextBox1.Lines
Dim primercaracter As String
If RichTextBox1.Lines(i).ToString = vbCrLf Then MsgBox(RichTextBox1.Lines(i).ToString)
If (RichTextBox1.Lines(i).ToString = "") Then
'MsgBox(RichTextBox1.Lines(i).ToString & vbCrLf & i)
Else
primercaracter = RichTextBox1.Lines(i).Substring(0, 1).ToString
If (primercaracter = "<") Then
datos(i, 0) = "newtake"
datos(i, 1) = RichTextBox1.Lines(i).Trim.ToString
datos(i, 2) = "-NADA-"
doit = "true"
ElseIf (primercaracter = "*") Then
Dim textof As String
Dim textofs() As String
textof = RichTextBox1.Lines(i).ToString
textofs = textof.Split("*")
datos(i, 0) = "voz"
datos(i, 1) = textofs(1).Trim.ToString
datos(i, 2) = textofs(2).Trim.ToString
Else
If (doit = "false") Then
datos(i, 0) = "titulo"
datos(i, 1) = RichTextBox1.Lines(i).ToString
datos(i, 2) = "-NADA-"
Else
If (datos(i - 1, 2) = "") Then
'MsgBox("fila : " & i & vbCrLf & "previo : " & datos(i - 2, 2) & vbCrLf & "actual : " & RichTextBox1.Lines(i).ToString)
datos(i - 2, 2) = datos(i - 2, 2) & " " & RichTextBox1.Lines(i).ToString
Else
'MsgBox("fila : " & i & vbCrLf & "previo : " & datos(i - 1, 2) & vbCrLf & "actual : " & RichTextBox1.Lines(i).ToString)
datos(i - 1, 2) = datos(i - 1, 2) & " " & RichTextBox1.Lines(i).ToString
End If
End If
End If
End If
i = i + 1
Next line
Dim datos2(0 To RichTextBox1.Lines.GetLength(0), 0 To 2) As String
Dim canti As String = datos.GetUpperBound(0)
Dim p As Integer = 0
For j As Integer = 1 To canti - 1 Step +1
If datos(j - 1, 1) = "" Then
Else
datos2(p, 1) = datos(j - 1, 1)
datos2(p, 2) = datos(j - 1, 2)
p = p + 1
End If
Next
oWord.Visible = False
oTable = doc.Tables.Add(doc.Bookmarks.Item("\endofdoc").Range, datos2.GetUpperBound(0), 2)
oTable.Range.ParagraphFormat.SpaceAfter = 6
oTable.Range.Font.Name = "Times New Roman"
oTable.Range.Font.Size = 11
oTable.Range.Font.Bold = True
Dim takes As Boolean = False
For n As Integer = 1 To datos2.GetUpperBound(0) Step +1
Me.Text = "Quedan " & (datos2.GetUpperBound(0) - n) - 1 & " Lineas per convertir"
If (n <= 1) Then
oTable.Cell(1, 1).Range.Text = datos2(n - 1, 1)
oTable.Cell(1, 1).Merge(oTable.Cell(1, 2))
Else
Dim pric As String
'(datos(n - 1, 1))
If (datos2(n - 1, 1) = "") Then
' oTable.Rows(n - 1).Delete()
Else
If datos2(n - 1, 1) IsNot "" Then
pric = datos2(n - 1, 1).Substring(0, 1).ToString
If (pric = "<") Then
oTable.Cell(n, 1).Merge(oTable.Cell(n, 2))
oTable.Cell(n, 1).Range.Text = datos2(n - 1, 1)
oTable.Cell(n, 1).Range.Font.ColorIndex = Word.WdColorIndex.wdGreen
takes = True
Else
If takes = True Then
oTable.Cell(n, 1).Range.Text = "*" & datos2(n - 1, 1) & "*"
oTable.Cell(n, 2).Range.Text = datos2(n - 1, 2)
oTable.Cell(n, 2).Width = 360
oTable.Cell(n, 1).Width = 100
Else
oTable.Cell(n, 1).Range.Text = datos2(n - 1, 1)
oTable.Cell(n, 1).Merge(oTable.Cell(n, 2))
End If
End If
Else
'oTable.Rows(n - 1).Delete()
End If
End If
End If
Next
doc.SaveAs2(saveFileDialog1.FileName)
doc.Close()
oWord.Application.Quit()
MsgBox("Guardat :)")
ToolStripStatusLabel1.Text = "Word tancat"
End If
End Sub
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
End Sub
Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
End Sub
End Class