2 Replies - 4167 Views - Last Post: 13 February 2012 - 12:36 AM Rate Topic: -----

#1 gwanztrevor  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 10-February 12

Creating a report in word

Posted 10 February 2012 - 01:23 AM

Imports System.Data
Imports Microsoft.Office.Interop
Imports Microsoft.Office.Interop.Word
Imports System.IO



i have been using the above references to print a report in word document but my problem is that i am failing to put headers and footers on my reports. i want to include report title on the header and page number on the footer. how do i do it?

thanks in advance
Is This A Good Question/Topic? 0
  • +

Replies To: Creating a report in word

#2 CharlieMay  Icon User is online

  • This space intentionally left blank
  • member icon

Reputation: 1533
  • View blog
  • Posts: 4,919
  • Joined: 25-September 09

Re: Creating a report in word

Posted 10 February 2012 - 07:25 AM

It's been a while and as you showed none of your code in doing this, I am going to take a stab at it based on how I remember the objects working. I think in order to set a header and/or footer is to use the .PageSetup Property of the document.

Something like
oDoc.PageSetup.Header = "This is my header"


Like I said it's been a while and your code may trigger a more concise thought.

Edit: See, I was completely wrong. Here is a tutorial from our tutorial section
Office Automation

This post has been edited by CharlieMay: 10 February 2012 - 07:48 AM

Was This Post Helpful? 0
  • +
  • -

#3 gwanztrevor  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 10-February 12

Re: Creating a report in word

Posted 13 February 2012 - 12:36 AM

thanks will give it a try. i managed to do it with PDF but im having a problem with my code because it placing all the records i selected in database table(like all the rows information in one line instead of a list of rows. this is my code.


Dim startTime As Date

        Command1.Enabled = False

        startTime = Now()
        lblEnd.Text = ""

        Dim clPDF As New clsPDFCreator
        Dim strFile As String
        Dim i As Integer

        '  output NAME
        strFile = App_Path & "\Demo.pdf"

        With clPDF
            .Title = "Pay Day Report"           ' TITLE
            .ScaleMode = clsPDFCreator.pdfScaleMode.pdfCentimeter
            .PaperSize = clsPDFCreator.pdfPaperSize.pdfA4                     ' PAGE FORMAT
            .Margin = 0                                 ' Margin
            .Orientation = clsPDFCreator.pdfPageOrientation.pdfPortrait               ' ORIENTATION

            .EncodeASCII85 = chkASCII85.Checked

            .InitPDFFile(strFile)

            ' DEFINING FONT
            .LoadFont("Fnt1", "Times New Roman")
            .LoadFont("Fnt2", "Arial", clsPDFCreator.pdfFontStyle.pdfItalic)
            .LoadFont("Fnt3", "Courier New")
            .LoadFontStandard("Fnt4", "Courier New", clsPDFCreator.pdfFontStyle.pdfBoldItalic)


            .LoadImgFromBMPFile("Img1", App_Path & "\img\20x20x24.bmp")
            .LoadImgFromBMPFile("Img2", App_Path & "\img\200x200x24.bmp")


            For i = 0 To 5
                '     open a page
                .BeginPage()


                .DrawText(19, 1.5, "page " & Trim(CStr(.Pages)), "Fnt1", 12, clsPDFCreator.pdfTextAlign.pdfAlignRight)
                .DrawObject("Footers")
                .DrawText(10.5, 27, "Unifrieght Sage", "Fnt1", 18, clsPDFCreator.pdfTextAlign.pdfCenter)

                .SetTextHorizontalScaling(70)
                .DrawText(20, 25, "Regnumber", "Fnt2", 14, clsPDFCreator.pdfTextAlign.pdfAlignRight)
                .DrawText(1, 25, "Name", "Fnt2", 14, clsPDFCreator.pdfTextAlign.pdfAlignLeft)
                .DrawText(10.5, 25, "Surname", "Fnt2", 14, clsPDFCreator.pdfTextAlign.pdfCenter)
                .SetTextHorizontalScaling(100)

                Dim Name1 As String
                Dim Surname As String
                Dim Regnumber As String

                Dim cmd As OdbcCommand = New OdbcCommand("Select *from tblMain ", cn)
                cmd.CommandType = CommandType.Text
                Dim DR As OdbcDataReader = cmd.ExecuteReader

                While DR.Read
                    Name1 = DR("name")
                    Surname = DR("surname")
                    Regnumber = ("regnumber")



                    .SetTextHorizontalScaling(70)
                    .DrawText(20, 23, Regnumber, "Fnt2", 14, clsPDFCreator.pdfTextAlign.pdfAlignRight)
                    .DrawText(1, 23, Name1, "Fnt2", 14, clsPDFCreator.pdfTextAlign.pdfAlignLeft)
                    .DrawText(10.5, 23, Surname, "Fnt2", 14, clsPDFCreator.pdfTextAlign.pdfCenter)
                    '.SetTextHorizontalScaling(100)
                    .SetCharSpacing(3)
                End While
                .EndPage()



                ' this is for the footers
                .StartObject("Footers", clsPDFCreator.pdfObjectType.pdfAllPages)
                .DrawText(10, 1.5, "Designed by Renegate", "Fnt3", 8, clsPDFCreator.pdfTextAlign.pdfCenter)
                .DrawText(20, 1.5, " of " & Trim(CStr(.Pages)), "Fnt1", 12, clsPDFCreator.pdfTextAlign.pdfAlignRight)
                .EndObject()

            Next
            ' closing the document
            .ClosePDFFile()

        End With

        Dim Elapsed As TimeSpan = Now().Subtract(startTime)
        lblEnd.Text = Elapsed.ToString()

        Command1.Enabled = True

        Call Shell("rundll32.exe url.dll,FileProtocolHandler " & (strFile), vbMaximizedFocus)
    End Sub


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1