i want to create a table and fill the data inside. i have crated table manully using loop now i want to fill data inside it... how we can fill plz help

Dim tmpcounter As Integer
tmpcounter = pageLeft + Printer.CurrentY

    For x1 = pageLeft To 2036 Step 200
          Printer.Line (x1, tmpcounter)-(x1, 2036)         
    Next

    For y1 = tmpcounter To 2036 Step 200
            Printer.Line (pageLeft, y1)-(2036, y1)
    Next

needed urgently .....

Dani AI

Generated

already draws the grid lines; filling each cell is a matter of calculating the cell rectangle, measuring the text, and placing the text at the right coordinates with the Printer object. Printer coordinates are measured from the page top-left and (by default) use twips; text measurement functions depend on the current Printer font, so set Printer.FontName/FontSize before measuring. Use Printer.CurrentX and Printer.CurrentY plus Printer.Print to draw text, and Printer.TextWidth / Printer.TextHeight to align it precisely. (Printer.CurrentX/CurrentY docs, TextWidth/TextHeight docs).

' Sample: center an array of strings into a pre-drawn grid
Dim cols As Integer: cols = 4
Dim rows As Integer: rows = 3

Dim leftMargin As Long: leftMargin = 144   ' twips
Dim topMargin  As Long: topMargin  = 144
Dim cellW As Long: cellW = 2000
Dim cellH As Long: cellH = 2000

Dim r As Integer, c As Integer
Dim txt As String
Dim txtW As Single, txtH As Single
Dim cx As Long, cy As Long

Printer.FontName = "Arial"
Printer.FontSize = 10

Dim data() As String
ReDim data(1 To rows, 1 To cols)
data(1,1) = "ID": data(1,2) = "Name": data(1,3) = "Qty": data(1,4) = "Price"
data(2,1) = "1":  data(2,2) = "Widget": data(2,3) = "10": data(2,4) = "$9.99"

For r = 1 To rows
  For c = 1 To cols
    txt = data(r, c)
    txtW = Printer.TextWidth(txt)
    txtH = Printer.TextHeight(txt)
    cx = leftMargin + (c - 1) * cellW + (cellW - txtW) / 2
    cy = topMargin  + (r - 1) * cellH + (cellH - txtH) / 2
    Printer.CurrentX = cx
    Printer.CurrentY = cy
    Printer.Print txt
  Next c
Next r

Printer.EndDoc

Common pitfalls: set the font before calling TextWidth/TextHeight; Printer.Print advances the print position so always set CurrentX/CurrentY for each cell; watch units (twips or changed ScaleMode) and handle NewPage/EndDoc for multi-page output (Printer class reference). This approach answers ’s request for how the data can be placed and builds directly on the grid created by ; alignment formulas can be changed for left/right/top/bottom placement as needed.

Recommended Answers

All 5 Replies

Can you post the code for the table? What do you want the data to look like in the table?

above code is creating a table. in printermode we have to create manually table which is actually vertcal and horizontal lines but looks like table.. so i done this but not getting the data inside these line..

Great effort

Great effort

what do you want to do exactly?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.