Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7931529
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T20:44:48+00:00 2026-06-03T20:44:48+00:00

I am trying to build a report from vb.net, and here is Dim oWord

  • 0

I am trying to build a report from vb.net, and here is

Dim oWord As Word.Application
Dim oDoc As Word.Document
Dim oTable As Word.Table

    For Each dc As BSPLib.Bills.BillDeliverychallan In Bill.BillDCs

        Dim dcpara As Word.Paragraph
        dcpara = oDoc.Content.Paragraphs.Add(oDoc.Bookmarks.Item("\endofdoc").Range)
        dcpara.Range.Font.Bold = 5
        dcpara.Range.Text = "Delivery Challan: " & dc.DCName
        dcpara.Alignment = Word.WdParagraphAlignment.wdAlignParagraphLeft
        dcpara.Format.SpaceBefore = 12
        dcpara.Format.SpaceAfter = 2   '24 pt spacing after paragraph.
        dcpara.Range.InsertParagraphAfter()

        Dim count As Integer = dc.BillItems.Count

        Dim r As Integer
        oTable = oDoc.Tables.Add(oDoc.Bookmarks.Item("\endofdoc").Range, count + 1, 7)
        oTable.Range.ParagraphFormat.SpaceBefore = 2
        oTable.Range.ParagraphFormat.SpaceAfter = 0
        oTable.Columns(1).Width = oWord.CentimetersToPoints(0.89)
        oTable.Columns(2).Width = oWord.CentimetersToPoints(5.58)
        oTable.Columns(3).Width = oWord.CentimetersToPoints(2)
        oTable.Columns(4).Width = oWord.CentimetersToPoints(0.6)
        oTable.Columns(5).Width = oWord.CentimetersToPoints(1.7)
        oTable.Columns(6).Width = oWord.CentimetersToPoints(0.5)
        oTable.Columns(7).Width = oWord.CentimetersToPoints(2.01)
        For r = 1 To count
            'BQT TABLES 15  NOS @   25.00   =   375.00
            oTable.Cell(r, 1).Range.Text = dc.BillItems(r - 1).ItemSerial & "."
            oTable.Cell(r, 1).Range.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphRight
            oTable.Cell(r, 1).Range.Font.Bold = 0
            oTable.Cell(r, 2).Range.Text = dc.BillItems(r - 1).ItemName
            oTable.Cell(r, 2).Range.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphLeft
            oTable.Cell(r, 2).Range.Font.Bold = 0
            oTable.Cell(r, 3).Range.Text = dc.BillItems(r - 1).Quantity & " " & dc.BillItems(r - 1).ItemMeasure
            oTable.Cell(r, 3).Range.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphRight
            oTable.Cell(r, 3).Range.Font.Bold = 0

            oTable.Cell(r, 4).Range.Text = "@"
            oTable.Cell(r, 4).Range.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter
            oTable.Cell(r, 4).Range.Font.Bold = 0
            oTable.Cell(r, 5).Range.Text = dc.BillItems(r - 1).PricePerUnit.ToString("F")
            oTable.Cell(r, 5).Range.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphRight
            oTable.Cell(r, 5).Range.Font.Bold = 0
            oTable.Cell(r, 6).Range.Text = "="
            oTable.Cell(r, 6).Range.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter
            oTable.Cell(r, 6).Range.Font.Bold = 0
            oTable.Cell(r, 7).Range.Text = dc.BillItems(r - 1).TotalFinal.ToString("F")
            oTable.Cell(r, 7).Range.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphRight
            oTable.Cell(r, 7).Range.Font.Bold = 0
        Next
        oTable.Cell(r + 1, 7).Range.Text = (dc.Total / dc.Days).ToString("F")
        oTable.Cell(r + 1, 7).Range.Font.Bold = 0
        oTable.Cell(r, 7).Range.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphRight
        oTable.Rows.Alignment = Word.WdRowAlignment.wdAlignRowLeft

        'Using a line break before my next table
        Dim oLineBreak1 As Word.Paragraph
        oLineBreak1 = oDoc.Content.Paragraphs.Add(oDoc.Bookmarks.Item("\endofdoc").Range)
        oLineBreak1.Format.SpaceAfter = 0
        oLineBreak1.Format.SpaceBefore = 0
        oLineBreak1.Range.Font.Size = 2

        oTable = oDoc.Tables.Add(oDoc.Bookmarks.Item("\endofdoc").Range, 1, 2)
        oTable.Range.ParagraphFormat.SpaceAfter = 0
        oTable.Range.ParagraphFormat.SpaceBefore = 0
        If dc.Days > 1 Then
            oTable.Cell(1, 1).Range.Text = "    From " & dc.FromDate.ToShortDateString & " To " & dc.ToDate & " --- " & dc.Days & " days" & " For: " & dc.ForDate
        Else
            oTable.Cell(1, 1).Range.Text = "    From " & dc.FromDate.ToShortDateString & " To " & dc.ToDate & " --- " & dc.Days & " day" & " For:" & dc.ForDate
        End If
        oTable.Cell(1, 1).Width = oWord.CentimetersToPoints(12.44)
        oTable.Cell(1, 2).Width = oWord.CentimetersToPoints(2.67)
        oTable.Cell(1, 2).Range.Text = dc.Total.ToString("F")
        oTable.Cell(1, 2).Range.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphRight
        oTable.Rows.Alignment = Word.WdRowAlignment.wdAlignRowCenter




        'Dim break As Word.WdBreakType
        'End If
    Next

The problem is, if the data in the for each loop extends to next page, I want the entire data in for loop to move to next page. I think of adding a page count integer and verify it with starting and ending to determine and change the page. The problem is I dont know how to insert a page break at a specified line number. page break is Word.WdBreakType.wdPageBreak but how to insert it at a line number?

Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T20:44:50+00:00Added an answer on June 3, 2026 at 8:44 pm

    You can format the paragraph as “Keep Together“:

    http://msdn.microsoft.com/en-us/library/microsoft.office.interop.word.paragraph.keeptogether.aspx

    Determines if all lines in the specified paragraphs remain on the same page when Microsoft Word repaginates the document.

    This ensures that individual lines of a paragraph don’t get separated across two pages.

    You will also want to use “Keep with Next“:

    http://msdn.microsoft.com/en-us/library/microsoft.office.interop.word.paragraph.keepwithnext.aspx

    Determines if the specified paragraph remains on the same page as the paragraph that follows it when Microsoft Word repaginates the document.

    This ensures that individual paragraphs aren’t separated from each other across two pages.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was trying Build For Archiving application (from Titanium Mobile) with xCode 4.4, but
I am trying to build a setup file which will install my vb.net application
I'm trying to build a prototype application that consists of a table of data
I am trying to build a 2008 SSRS report so that it displays table
I'm trying to prepare to build a database driven .net application and I have
I'm trying to get a report built up from data mining our accounting software.
I'm trying build a method which returns the shortest path from one node to
I'm trying build an App Engine connected Android application and am having some problems
Trying to build sslsniff on a RHEL 5.2 system here. When compiling sslsniff on
I am trying to build a C# class from a XSD file. In short

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.