Imports Word = Microsoft.Office.Interop.Word Public Class GUI_Export Private Shared gratingTable As New DataTable Public Shared Sub Generate_Quote() gratingTable = User_Input.Create_ExportTable() Dim doc As Word.Document = New Word.Document() 'Page 1 Create_HeaderFooter(doc) Create_QuoteInfo(doc) Create_ProductsInfo(doc) 'Page 2-X doc.Words.Last.InsertBreak(Word.WdBreakType.wdPageBreak) Generate_Screenshot() Dim drawingPara As Word.Paragraph Dim lineRange As Word.Range = doc.Bookmarks.Item("\endofdoc").Range drawingPara = doc.Content.Paragraphs.Add(lineRange) drawingPara.Range.InsertParagraphBefore() drawingPara.Format.SpaceBefore = 10 drawingPara.Range.InlineShapes.AddPicture(Individual.filepath & "\X2021\Specification_PDF\GUI.png") drawingPara.Range.InlineShapes(1).ScaleHeight = 55 drawingPara.Range.InlineShapes(1).ScaleWidth = 55 drawingPara.Format.SpaceAfter = 10 drawingPara.Range.InsertParagraphAfter() doc.ExportAsFixedFormat(Individual.filepath & "\X2021\Specification_PDF\Specification.pdf", Word.WdExportFormat.wdExportFormatPDF) doc.Close(False) End Sub Private Shared Sub Generate_Screenshot() 'Dim startPoint As New Point(Me.Left + Panel_Grating.Left, Me.Top + Panel_Grating.Top) 'Dim startPoint As New Point 'startPoint = Individual.Panel_Grating.PointToScreen(Point.Empty) 'Dim tempImg As New Bitmap(Individual.Panel_Grating.Width - 1, Individual.Panel_Grating.Height - 1) 'Dim test As Graphics = Graphics.FromImage(tempImg) 'test.CopyFromScreen(startPoint, New Point(0, 0), tempImg.Size) 'tempImg.Save(Individual.filepath & "\X2021\Specification_PDF\GUI.png", Imaging.ImageFormat.Png) Dim gratingImg As New Bitmap(Individual.Panel_Grating.Width - 1, Individual.Panel_Grating.Height - 1) Dim graphicImg As Graphics = Graphics.FromImage(gratingImg) Draw_Grating.Draw_Grating(graphicImg, 12) gratingImg.Save(Individual.filepath & "\X2021\Specification_PDF\GUI.png", Imaging.ImageFormat.Png) End Sub Private Shared Sub Create_HeaderFooter(doc As Word.Document) doc.Sections(1).PageSetup.DifferentFirstPageHeaderFooter = False 'Header Dim headerTable As Word.Table headerTable = doc.Sections(1).Headers(Word.WdHeaderFooterIndex.wdHeaderFooterPrimary).Range. Tables.Add(doc.Sections(1).Headers(Word.WdHeaderFooterIndex.wdHeaderFooterPrimary).Range, 1, 2) headerTable.Cell(1, 1).Range.InlineShapes.AddPicture(Individual.filepath & "\X2021\Specification_PDF\Weland_Logo.png") headerTable.Cell(1, 1).Range.InlineShapes(1).ScaleHeight = 50 headerTable.Cell(1, 1).Range.InlineShapes(1).ScaleWidth = 50 headerTable.Cell(1, 2).Range.Text = "QUOTE" headerTable.Cell(1, 2).Range.Font.Size = 18 headerTable.Cell(1, 2).Range.Font.Bold = True headerTable.Cell(1, 2).Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphRight headerTable.Cell(1, 2).VerticalAlignment = Word.WdVerticalAlignment.wdAlignVerticalBottom 'Footer Dim footerTable As Word.Table footerTable = doc.Sections(1).Footers(Word.WdHeaderFooterIndex.wdHeaderFooterPrimary).Range. Tables.Add(doc.Sections(1).Footers(Word.WdHeaderFooterIndex.wdHeaderFooterPrimary).Range, 3, 2) footerTable.Columns(1).SetWidth(360, 2) footerTable.Cell(1, 1).Range.Text = "Phone Number: " footerTable.Cell(2, 1).Range.Text = "Email: " footerTable.Cell(3, 1).Range.Text = "Webpage: " footerTable.Cell(1, 2).Range.Text = "0731-344 00" footerTable.Cell(2, 2).Range.Text = "info@weland.se" footerTable.Cell(3, 2).Range.Text = "www.weland.com" For i = 1 To footerTable.Rows.Count footerTable.Cell(i, 1).Range.Font.Bold = True For j = 1 To footerTable.Columns.Count footerTable.Cell(i, j).Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphRight footerTable.Cell(i, j).Range.Font.Size = 10 Next Next End Sub Private Shared Sub Create_QuoteInfo(doc) Dim lineBreak As Word.Paragraph lineBreak = doc.Content.Paragraphs.Add lineBreak.Range.InsertParagraphBefore() lineBreak.Range.Text = "" lineBreak.Format.SpaceAfter = 20 lineBreak.Range.InsertParagraphAfter() Dim infoTable As Word.Table Dim tableRange As Word.Range = doc.Bookmarks.Item("\endofdoc").Range infoTable = doc.Tables.Add(tableRange, 4, 2) infoTable.Columns(1).SetWidth(120, 2) infoTable.Rows.SetHeight(18, 2) Dim date2 As Date = Date.Today infoTable.Cell(1, 1).Range.Text = "Quote Date:" infoTable.Cell(1, 2).Range.Text = date2.ToString("dd-MM-yyyy") infoTable.Cell(2, 1).Range.Text = "Order number:" infoTable.Cell(2, 2).Range.Text = date2.ToString("ddMMyyyy") & Get_RandomNumber(10000, 99999) infoTable.Cell(3, 1).Range.Text = "Customer number:" infoTable.Cell(3, 2).Range.Text = Get_RandomNumber(10000, 99999) infoTable.Cell(4, 1).Range.Text = "Sales Representative:" infoTable.Cell(4, 2).Range.Text = "Sven Svensson" End Sub Private Shared Sub Create_ProductsInfo(doc) Dim lineBreak As Word.Paragraph Dim lineRange As Word.Range = doc.Bookmarks.Item("\endofdoc").Range lineBreak = doc.Content.Paragraphs.Add(lineRange) lineBreak.Range.InsertParagraphBefore() lineBreak.Range.Text = "" lineBreak.Format.SpaceAfter = 10 lineBreak.Range.InsertParagraphAfter() Dim productsTable As Word.Table Dim tableRange As Word.Range = doc.Bookmarks.Item("\endofdoc").Range productsTable = doc.Tables.Add(tableRange, 5, 5) 'FIXA generiskt productsTable.Rows.SetHeight(18, 2) productsTable.Columns(1).SetWidth(240, 2) productsTable.Columns(2).SetWidth(78, 2) productsTable.Columns(3).SetWidth(40, 2) productsTable.Columns(4).SetWidth(60, 2) productsTable.Columns(5).SetWidth(52, 2) For c = 1 To productsTable.Columns.Count productsTable.Cell(1, c).Range.Font.Color = Word.WdColor.wdColorWhite productsTable.Cell(1, c).Shading.BackgroundPatternColor = Word.WdColor.wdColorBlack productsTable.Cell(1, c).VerticalAlignment = Word.WdVerticalAlignment.wdAlignVerticalBottom If c > 2 Then For r = 1 To productsTable.Rows.Count productsTable.Cell(r, c).Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphRight Next End If If c = 5 Then For r = 2 To productsTable.Rows.Count productsTable.Cell(r, c).Range.Font.Bold = True Next End If Next productsTable.Cell(1, 1).Range.Text = "Description" productsTable.Cell(1, 2).Range.Text = "Art. Nr." productsTable.Cell(1, 3).Range.Text = "QTY" productsTable.Cell(1, 4).Range.Text = "Unit Price" productsTable.Cell(1, 5).Range.Text = "Price" For i = 2 To productsTable.Rows.Count productsTable.Cell(i, 1).Range.Text = "Floor Grating " & gratingTable.Rows(0)("NAME") & " " & gratingTable.Rows(0)("LOADBAR_HEIGHT") & "/" & gratingTable.Rows(0)("LOADBAR_THICKNESS") If gratingTable.Rows(0)("SERRATED") Then productsTable.Cell(i, 2).Range.Text = gratingTable.Rows(0)("NAME").substring(0, 1) & "S" & gratingTable.Rows(0)("LOADBAR_HEIGHT") & Get_RandomNumber(10000000, 99999999) Else productsTable.Cell(i, 2).Range.Text = gratingTable.Rows(0)("NAME") & gratingTable.Rows(0)("LOADBAR_HEIGHT") & Get_RandomNumber(10000000, 99999999) End If productsTable.Cell(i, 3).Range.Text = "5" productsTable.Cell(i, 4).Range.Text = "20 000" productsTable.Cell(i, 5).Range.Text = "100 000" For j = 1 To productsTable.Columns.Count productsTable.Cell(i, j).Range.Font.Size = 10 Next Next Dim lineBreak2 As Word.Paragraph lineRange = doc.Bookmarks.Item("\endofdoc").Range lineBreak2 = doc.Content.Paragraphs.Add(lineRange) lineBreak2.Range.InsertParagraphBefore() lineBreak2.Range.Text = "" lineBreak2.Format.SpaceAfter = 20 lineBreak2.Range.InsertParagraphAfter() Dim priceTable As Word.Table tableRange = doc.Bookmarks.Item("\endofdoc").Range priceTable = doc.Tables.Add(tableRange, 1, 2) priceTable.Columns(1).SetWidth(370, 2) priceTable.Cell(1, 1).Range.Text = "Total Price:" priceTable.Cell(1, 1).Range.Font.Bold = True priceTable.Cell(1, 1).Range.Font.Size = 20 priceTable.Cell(1, 2).Range.Text = "100 000" priceTable.Cell(1, 2).Range.Font.Bold = True priceTable.Cell(1, 2).Range.Font.Size = 20 priceTable.Cell(1, 1).Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphRight priceTable.Cell(1, 2).Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphRight End Sub Private Shared Function Get_RandomNumber(Min As Integer, Max As Integer) As Integer ' Static Generator As System.Random = New System.Random() Return Generator.Next(Min, Max) End Function End Class