'If desired, you can proceed from here using the Microsoft Graph
'Object model on the oChart object to make additional changes to the
'chart.
oShape.Width = oWord.InchesToPoints(6.25)
oShape.Height = oWord.InchesToPoints(3.57)
'Add text after the chart.
oRng = oDoc.Bookmarks.Item("\endofdoc").Range
oRng.InsertParagraphAfter()
oRng.InsertAfter("THE END.")
'All done. Close this form.
Me.Close()
End Sub
End Class
tem até coisa que eu nem tirei ainda. pois bem. neste ponto, eu gostaria de saber como coloco uma figura antes ou depois de um parágrafo, como o símbolo da empresa.
e também se eu posso colocar um campo "data" que traz a data de hoje no arquivo word automaticamente.
Question
cimerio
oi, começei a mecher no visual basic para possibilitar a geração de documentos prontos de word, como circulares e comunicados.
pegando um modelo pronto da net, começei a fuçar, e fiz alguma coisa. aqui está:
Imports Word = Microsoft.Office.Interop.Word
Public Class Form1
Dim center As Integer
Dim Selection As Object
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Dim oWord As Word.Application
Dim oDoc As Word.Document
Dim oTable As Word.Table
Dim oPara1 As Word.Paragraph, oPara2 As Word.Paragraph
Dim oPara3 As Word.Paragraph, oPara4 As Word.Paragraph
Dim oRng As Word.Range
Dim oShape As Word.InlineShape
Dim oChart As Object
Dim Pos As Double
'Start Word and open the document template.
oWord = CreateObject("Word.Application")
oWord.Visible = True
oDoc = oWord.Documents.Add
'Insert a paragraph
oPara1 = oDoc.Content.Paragraphs.Add
oPara1.Range.Text = "SETOR DE TRANSPORTES"
oPara1.Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter
oPara1.Range.Font.Name = "Times New Roman"
oPara1.Range.Font.Size = 10
oPara1.Format.SpaceAfter = 2
oPara1.Range.InsertParagraphAfter()
oPara1.Range.Text = "DEPARTAMENTO DE INTENDENCIA E ALMOXARIFADO"
oPara1.Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter
oPara1.Range.Font.Name = "Times New Roman"
oPara1.Range.Font.Size = 10
oPara1.Format.SpaceAfter = 2
oPara1.Range.InsertParagraphAfter()
oPara1.Range.Text = "SEÇÃO DE COMPRAS"
oPara1.Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter
oPara1.Range.Font.Name = "Times New Roman"
oPara1.Range.Font.Size = 10
oPara1.Format.SpaceAfter = 30
oPara1.Range.InsertParagraphAfter()
'Insert a paragraph
oPara2 = oDoc.Content.Paragraphs.Add(oDoc.Bookmarks.Item("\endofdoc").Range)
oPara2.Range.Text = "Comunicado nº "
oPara2.Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphLeft
oPara2.Range.Font.Name = "Times New Roman"
oPara2.Range.Font.Size = 12
oPara2.Range.Font.Bold = True
oPara2.Format.SpaceAfter = 13
oPara2.Range.InsertParagraphAfter()
oPara3 = oDoc.Content.Paragraphs.Add(oDoc.Bookmarks.Item("\endofdoc").Range)
oPara3.Range.Text = "João Pessoa, de de 2012."
oPara3.Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphRight
oPara3.Range.Font.Name = "Times New Roman"
oPara3.Range.Font.Size = 12
oPara3.Range.Font.Bold = False
oPara3.Format.SpaceAfter = 50
oPara3.Range.InsertParagraphAfter()
oPara3.Range.Text = "Ao Departamento de Pessoal"
oPara3.Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphLeft
oPara3.Range.Font.Name = "Times New Roman"
oPara3.Range.Font.Bold = False
oPara3.Range.Font.Size = 12
oPara3.Format.SpaceAfter = 20
oPara3.Range.InsertParagraphAfter()
oPara3.Range.Text = "Assunto: Novos Uniformes"
oPara3.Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphRight
oPara3.Range.Font.Name = "Times New Roman"
oPara3.Range.Font.Size = 12
oPara3.Range.Font.Bold = True
oPara3.Format.SpaceAfter = 20
oPara3.Range.InsertParagraphAfter()
'Insert another paragraph.
oPara3 = oDoc.Content.Paragraphs.Add(oDoc.Bookmarks.Item("\endofdoc").Range)
oPara3.Range.Text = "This is a sentence of normal text. Now here is a table:"
oPara3.Range.Font.Bold = False
oPara3.Format.SpaceAfter = 24
oPara3.Range.InsertParagraphAfter()
'Dim r As Integer, c As Integer
'Add some text after the table.
'oTable.Range.InsertParagraphAfter()
oPara4 = oDoc.Content.Paragraphs.Add(oDoc.Bookmarks.Item("\endofdoc").Range)
oPara4.Range.InsertParagraphBefore()
oPara4.Range.Text = "And here's another table:"
oPara4.Format.SpaceAfter = 24
oPara4.Range.InsertParagraphAfter()
'Insert a 5 x 2 table, fill it with data, and change the column widths.
oTable = oDoc.Tables.Add(oDoc.Bookmarks.Item("\endofdoc").Range, 5, 2)
oTable.Range.ParagraphFormat.SpaceAfter = 6
For r = 1 To 5
For c = 1 To 2
oTable.Cell(r, c).Range.Text = "r" & r & "c" & c
Next
Next
oTable.Columns.Item(1).Width = oWord.InchesToPoints(2) 'Change width of columns 1 & 2
oTable.Columns.Item(2).Width = oWord.InchesToPoints(3)
'Keep inserting text. When you get to 7 inches from top of the
'document, insert a hard page break.
Pos = oWord.InchesToPoints(7)
oDoc.Bookmarks.Item("\endofdoc").Range.InsertParagraphAfter()
Do
oRng = oDoc.Bookmarks.Item("\endofdoc").Range
oRng.ParagraphFormat.SpaceAfter = 6
oRng.InsertAfter("A line of text")
oRng.InsertParagraphAfter()
Loop While Pos >= oRng.Information(Word.WdInformation.wdVerticalPositionRelativeToPage)
oRng.Collapse(Word.WdCollapseDirection.wdCollapseEnd)
oRng.InsertBreak(Word.WdBreakType.wdPageBreak)
oRng.Collapse(Word.WdCollapseDirection.wdCollapseEnd)
oRng.InsertAfter("We're now on page 2. Here's my chart:")
oRng.InsertParagraphAfter()
'Insert a chart and change the chart.
oShape = oDoc.Bookmarks.Item("\endofdoc").Range.InlineShapes.AddOLEObject( _
ClassType:="MSGraph.Chart.8", FileName _
:="", LinkToFile:=False, DisplayAsIcon:=False)
oChart = oShape.OLEFormat.Object
oChart.charttype = 4 'xlLine = 4
oChart.Application.Update()
oChart.Application.Quit()
'If desired, you can proceed from here using the Microsoft Graph
'Object model on the oChart object to make additional changes to the
'chart.
oShape.Width = oWord.InchesToPoints(6.25)
oShape.Height = oWord.InchesToPoints(3.57)
'Add text after the chart.
oRng = oDoc.Bookmarks.Item("\endofdoc").Range
oRng.InsertParagraphAfter()
oRng.InsertAfter("THE END.")
'All done. Close this form.
Me.Close()
End Sub
End Class
tem até coisa que eu nem tirei ainda. pois bem. neste ponto, eu gostaria de saber como coloco uma figura antes ou depois de um parágrafo, como o símbolo da empresa.
e também se eu posso colocar um campo "data" que traz a data de hoje no arquivo word automaticamente.
Link to comment
Share on other sites
2 answers to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.