itext 7 Table runs off page - itext7

I have a table that has variable rows of data. In this example there are 56 rows.The table works fine and accuratly splits over two pages when it's the only thing on the document. When I add some information to the top of the page, company address and customer address at top (not really a header.) It causes part of the table to push down and off the page (using setrelativeposition). The 56 rows will put rows 0-42 on the 1st page and then pick up with row 45 on the secod page. Rows 43 and 44 are off the page as shown in the picture.
Any Ideas or help would be appreciated. This is my 1st time with itext7
Dim Dest As String = ("C:\Users\Dan\Documents\JM\SIG\37065.pdf")
Dim Writer As PdfWriter = New PdfWriter(Dest)
Dim Pdf As PdfDocument = New PdfDocument(Writer)
Dim document As New Document(Pdf)
Dim Font = PdfFontFactory.CreateFont(StandardFonts.COURIER)
Dim Dateis As String = Now.ToShortDateString
Dim dsItems As DataSet = JMGetData.GetDS("Select qty, item, cast(price as decimal(10,2)) as price, cast(salestax as decimal(10,2)) as salestax, cast(linetotal as decimal(10,2)) as linetotal from sales where invnbr = '" & invnbr & "'")
Dim H1 As Paragraph = New Paragraph(New Text("J&M Home & Farm Supply")).SetFixedPosition(50, 800, 600).SetFontSize(9)
Dim H2 As Paragraph = New Paragraph(New Text("1580 Elkton Pike")).SetFixedPosition(50, 790, 600).SetFontSize(9)
Dim H3 As Paragraph = New Paragraph(New Text("Prospect TN 38477")).SetFixedPosition(50, 780, 600).SetFontSize(9)
Dim cust1 As Paragraph = New Paragraph(New Text("Dan Tester")).SetFixedPosition(50, 750, 600).SetFontSize(9)
Dim cust2 As Paragraph = New Paragraph(New Text("Street Addr")).SetFixedPosition(50, 740, 600).SetFontSize(9)
Dim cust3 As Paragraph = New Paragraph(New Text("City State Zip")).SetFixedPosition(50, 730, 600).SetFontSize(9)
document.Add(H1)
document.Add(H2)
document.Add(H3)
document.Add(cust1)
document.Add(cust2)
document.Add(cust3)
Dim pdftbl As New Table(6)
pdftbl.AddCell("Qty").SetWidth(15%)
pdftbl.AddCell("Item").SetWidth(40%)
pdftbl.AddCell("Price").SetWidth(15%)
pdftbl.AddCell("S-Tax").SetWidth(15%)
pdftbl.AddCell("L-Total").SetWidth(15%)
pdftbl.AddCell("Row").SetWidth(15%)
For I As Int32 = 0 To dsItems.Tables(0).Rows.Count - 1
Dim Qty As Int32 = CInt(dsItems.Tables(0).Rows(I).Item("qty"))
Dim Item As String = dsItems.Tables(0).Rows(I).Item("item").ToString
Dim Price As Decimal = CDec(dsItems.Tables(0).Rows(I).Item("price").ToString)
Dim stax As Decimal = CDec(dsItems.Tables(0).Rows(I).Item("salestax").ToString)
Dim Linetot As Decimal = CDec(dsItems.Tables(0).Rows(I).Item("linetotal").ToString)
pdftbl.AddCell(Qty).SetWidth(15%).SetFontSize(8)
pdftbl.AddCell(Item).SetWidth(40%).SetFontSize(8)
pdftbl.AddCell(Price).SetWidth(15%).SetFontSize(8)
pdftbl.AddCell(stax).SetWidth(15%).SetFontSize(8)
pdftbl.AddCell(Linetot).SetWidth(15%).SetFontSize(8)
pdftbl.AddCell(I).SetWidth(15%).SetFontSize(8)
Next
pdftbl.SetWidth(500)
pdftbl.SetRelativePosition(25, 90, 300, 700)
document.Add(pdftbl)
document.Close()
System.Diagnostics.Process.Start("C:\Program Files (x86)\Adobe\Acrobat DC\Acrobat\Acrobat.exe", "C:\Users\dan\Documents\JM\Sig\37065.pdf")
Me.Close()

Related

vsto - VB - find last cell from column in outlook addin

How do you search for the last empty cell in an excel sheet from a vsto outlook addin?
I have the following code (not compiling)
Imports Excel = Microsoft.Office.Interop.Excel
Dim ExcelApp As New Excel.Application
Dim ExcelWorkbook As Excel.Workbook
Dim ExcelWorkSheet As Excel.Worksheet= ExcelWorkbook.Worksheets(1)
Dim ExcelRange As Excel.Range = ExcelWorkSheet.Range("A1","A600")
Dim currentFind As Excel.Range = Nothing
Dim firstFind As Excel.Range = Nothing
currentFind = ExcelRange.Find("*", , Excel.XlFindLookIn.xlValues, Excel.XlLookAt.xlPart, Excel.XlSearchOrder.xlByRows, Excel.XlSearchDirection.xlNext, False)
While Not currentFind Is Nothing
' Keep track of the first range you find.
If firstFind Is Nothing Then
firstFind = currentFind
' If you didn't move to a new range, you are done.
ElseIf currentFind.Address = firstFind.Address Then
Exit While
End If
currentFind = ExcelRange.FindNext(currentFind)
End While
ExcelWorkbook.ActiveSheet.range(currentFind).Select()
I have updated it according to Scott Holtzman's comments but now I get an error message: HRESULT: 0x800A03EC
The code does not have the correct hierarchy according to the Object Model.
You cannot define a Range object without first defining a Worksheet object, which needs a Workbook object before it can be defined.
Try this:
Set ExcelApp = New Excel.Application
Dim ExcelWorkbook as Excel.Workbook
Set ExcelWorkbook = ExcelApp.Workbooks.Open("myPath") 'actually opens a workbook to work with
Dim ExcelWorksheet as Excel.Worksheet
Set ExcelWorksheet = ExcelWorkbook.Worksheets("mySheet")
Dim currentFind As Excel.Range = Nothing
Dim firstFind As Excel.Range = Nothing
Dim Fruits As Excel.Range = ExcelWorksheet.Range("A1", "A200")
Set currentFind = Fruits.Find("apples", , Excel.XlFindLookIn.xlValues, Excel.XlLookAt.xlPart, Excel.XlSearchOrder.xlByRows, Excel.XlSearchDirection.xlNext, False)
...
Set currentFind = Fruits.FindNext(currentFind)
SOLVED: I have the following code (now compiling!)
Imports Excel = Microsoft.Office.Interop.Excel
Dim ExcelApp As New Excel.Application
Dim ExcelWorkbook As Excel.Workbook
Dim ExcelWorkSheet As Excel.Worksheet= ExcelWorkbook.Worksheets(1)
Dim LastRow As Integer
LastRow = ExcelWorkSheet.Columns(1).Find("*", , , , Excel.XlSearchOrder.xlByColumns, Excel.XlSearchDirection.xlPrevious).Row
ExcelWorkSheet.Range("A" & LastRow).Select()
My error was in the actual property library choice. Beware to choose:
XlSearchOrder.xlByColumns, Excel.XlSearchDirection.xlPrevious

How to extract Defects with linked TCs using QC OTA

I am successfully able to download the defects using the below code, but how to get the count of linked TCs with status 'Failed or Blocked' against each defect?
Sub GetDefectsByFilter()
On Error Resume Next
Dim a
Dim intIndex As Integer
Dim sngPercent As Single
Dim BugFactory, BugList, BgFilter
Dim Response As VbMsgBoxResult
Dim DefectID As String
If TDC Is Nothing Then ConnecttoQC
Set BugFactory = TDC.BugFactory
Set BgFilter = BugFactory.Filter
DefectID = frmDefectFilter.txtDefectID
BgFilter.Filter("BG_BUG_ID") = DefectID
Set BugList = BgFilter.NewList
Dim Bug, Row, Count As Integer
Count = 1
Row = 2
ActiveSheet.Cells(1, 1).Value = "Defect ID"
ActiveSheet.Cells(1, 2).Value = "Application"
ActiveSheet.Cells(1, 3).Value = "Status"
For Each Bug In BugList
ActiveSheet.Cells(Row, 1).Value = Bug.Field("BG_BUG_ID")
ActiveSheet.Cells(Row, 2).Value = Bug.Field("BG_USER_06")
ActiveSheet.Cells(Row, 3).Value = Bug.Field("BG_STATUS")
Row = Row + 1
Count = Count + 1
Next
frmDefectFilter.Hide
End Sub
Thanks #Roland. The below code snippet helped me.
Sub ViewLinks()
'------------------------------------------------------
' Output all bug links.
Dim BugF As BugFactory, bList As List
Dim aBug As Bug
Dim bugL As ILinkable, LinkList As List, linkF As LinkFactory
'tdc is the global TDConnection object.
Set BugF = tdc.BugFactory
Set bList = BugF.NewList("")
For Each aBug In bList
'Cast the Bug object to an ILinkable reference
' to get the link factory.
Set bugL = aBug
Set linkF = bugL.LinkFactory
Set LinkList = linkF.NewList("")
Dim SourceObj As Object, TargetObj As Object, InitObj As Object, lnk As Link
Debug.Print: Debug.Print "---------------------------------"
Debug.Print "Source Type"; Tab; "ID"; Tab; "Target Type"; _
Tab; "ID"; Tab; "Initiated by"
For Each lnk In LinkList
With lnk
Set SourceObj = .SourceEntity
Set TargetObj = .TargetEntity
Set InitObj = .LinkedByEntity
Debug.Print TypeName(SourceObj); Tab; CStr(SourceObj.ID); _
Tab; TypeName(TargetObj); Tab; CStr(TargetObj.ID); _
Tab; TypeName(InitObj); Spc(3); InitObj.ID
End With
Next lnk
Next aBug
End Sub

Insert image filepath into cell as hyperlink and image itself into comment

I'm trying to create an Excel macro that takes a picture or pictures as input. It then adds the image as a comment to the selected cell. I have this much complete.
What I want to do next is take the path of the picture and insert it as a hyperlink in the cell.
e.g.
Image - \server\share\test\image.jpg
Insert image as comment
Insert image path as text
Here is my code so far:
Sub ImageLinkComment()
Dim Pict() As Variant
Dim ImgFileFormat As String
Dim PictCell As Range
Dim lLoop As Long
Dim sShape As Picture
ActiveSheet.Protect False, False, False, False, False
ImgFileFormat = "All Picture Files(*.emf;*.wmf;*.jpg;*.jpeg;*.jfif;*.jpe;*.png;*.bpm;*.gif;*.gfa;*.emz;*.wmz;*.pcz;*.tif;*.tiff;*.cgm;*.eps;*.pct;*.pict;*.wpg;*.pcd;*.pcx;*.cdr;*.fpx;*.mix), *.bmp"
'Note you can load in any nearly file format
Pict = Application.GetOpenFilename(ImgFileFormat, MultiSelect:=True)
If Not IsArray(Pict) Then
Debug.Print "No files selected."
Exit Sub
End If
Set PictCell = Selection.Cells(1)
For lLoop = LBound(Pict) To UBound(Pict)
PictCell.AddComment
PictCell.Comment.Visible = False
PictCell.Comment.Shape.Height = 215
PictCell.Comment.Shape.Width = 195
PictCell.Comment.Shape.Fill.UserPicture Pict(lLoop)
Set PictCell = PictCell.Offset(1)
Next lLoop
End Sub
So, after some playing around I got this code to work for one image at a time. It's not the prettiest but it's functional.
I assigned it to a button within my excel sheet, along with another button to clear the contents of a cell.
Sub InsertImagesAsComments()
Dim Pict
Dim ImgFileFormat As String
Dim PictCell As Range
Dim lLoop As Long
Dim sShape As Picture
ActiveSheet.Protect False, False, False, False, False
ImgFileFormat = "All Picture Files(*.emf;*.wmf;*.jpg;*.jpeg;*.jfif;*.jpe;*.png;*.bpm;*.gif;*.gfa;*.emz;*.wmz;*.pcz;*.tif;*.tiff;*.cgm;*.eps;*.pct;*.pict;*.wpg;*.pcd;*.pcx;*.cdr;*.fpx;*.mix), *.bmp"
'Note you can load in any nearly file format
Pict = Application.GetOpenFilename(ImgFileFormat, MultiSelect:=False)
If Pict = False Then Exit Sub
Set PictCell = Selection.Cells(1)
PictCell.AddComment
PictCell.Comment.Visible = False
PictCell.Comment.Shape.Height = 215
PictCell.Comment.Shape.Width = 195
PictCell.Comment.Shape.Fill.UserPicture Pict
ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:= _
Pict, _
TextToDisplay:= _
Pict
End Sub
Purpose of this code is to fetch the images from the file path and place them as comment in the adjacent row.
Assummning there are 5 file path in A1 to A5, the code asks to select the range, and then it puts the image as comment in B1 to B5.
Hope it helps someone
Sub Filepath_to_Picture_As_Comments()
Dim cmt As Comment
Dim rng As Range
Dim Workrng As Range
Dim Height As Long
Dim Width As Long
On Error Resume Next
xTitleId = "Select range of File paths"
Set Workrng = Application.Selection
Set Workrng = Application.InputBox("File paths", xTitleId, Workrng.Address, Type:=8)
Height = Application.InputBox("Add text", "Height of comment", "400", Type:=2)
Width = Application.InputBox("Add text", "Width of comment", "500", Type:=2)
For Each rng In Workrng
With rng.Offset(0, 1)
Set cmt = rng.Comment
If cmt Is Nothing Then
Set cmt = .AddComment
End If
With cmt
.Text Text:=""
.Shape.Fill.UserPicture rng.Value
.Visible = False
End With
End With
Next rng
For Each cmt In Application.ActiveSheet.Comments
cmt.Shape.Width = Width
cmt.Shape.Height = Height
Next cmt
End Sub

How To Read the TextBox value which is dynamically added into gridview on ajax tab container

I'm facing difficult condition to read the value from text box which is dynamically added into gridview which is inside TabPanel of AjaxTabContainer.
Note, all controls are added dynamically as per user options.
The sequence would be as follow:
Design Time:
One Panel and other user options (date & some other fields)
Run Time:
- Add AjaxTab container & Tab Panel which is vary upon user filter (Tab created based on db -records)
- Inside each tab, added the GridView with dataset
- Add some textbox into each of GridView Line
On Page:
I can successfully show tab control with gridview with text box (*as below)
Now, how to read value inside each text box when user click 'Update' button?
I try to use FindControls, but nothing.
My code:-
Private Sub DynamicTabGVLoad(ByVal seqno As String)
createTab()
ds = allotmentdb.getRoomType()
For i As Integer = 0 To ds.Tables(0).Rows.Count - 1
Dim tabcontent As New Control()
Dim tbldynamic As New Table()
Dim tbrdynamic As New TableRow()
Dim tbcdynamic As New TableCell()
Dim roomtypekey As String
roomtypekey = ds.Tables(0).Rows(i)("roomtypekey").ToString()
Dim gv_alines As New GridView
gv_alines.AutoGenerateColumns = True
gv_alines.Attributes.Add("runat", "server")
Dim ds1 As New Data.DataSet()
ds1 = allotmentdb.getAllotmentLinesTabGV(roomtypekey, seqno, System.DateTime.Now.ToString(("yyyy-MM-dd")))
gv_alines.EmptyDataText = "No Record Found!"
'gv_alines.ShowHeaderWhenEmpty = True
gv_alines.DataSource = ds1
gv_alines.DataBind()
If gv_alines.Rows.Count > 0 Then
gv_alines.HeaderRow.Cells(0).Visible = False
gv_alines.HeaderRow.Cells(1).Visible = False
gv_alines.HeaderRow.Cells(4).Visible = False
For Each gvr As GridViewRow In gv_alines.Rows
gvr.Cells(0).Visible = False
gvr.Cells(1).Visible = False
gvr.Cells(4).Visible = False
Dim txtInternetRoom As New TextBox()
txtInternetRoom.ID = "txtInternetRoom"
txtInternetRoom.Text = gvr.Cells(5).Text
txtInternetRoom.Style.Add("text-align", "right")
txtInternetRoom.Width = 100
gvr.Cells(5).Controls.Add(txtInternetRoom)
Dim txtInternetRate As New TextBox()
txtInternetRate.ID = "txtInternetRate"
txtInternetRate.Text = FormatNumber(gvr.Cells(6).Text, 2)
If txtInternetRate.Text = "0.00" Then txtInternetRate.Text = "NA"
txtInternetRate.Style.Add("text-align", "right")
txtInternetRate.Width = 100
gvr.Cells(6).Controls.Add(txtInternetRate)
Dim txtInternetRate2 As New TextBox()
txtInternetRate2.ID = "txtInternetRate2"
txtInternetRate2.Text = FormatNumber(gvr.Cells(7).Text)
If txtInternetRate2.Text = "0.00" Then txtInternetRate2.Text = "NA"
txtInternetRate2.Style.Add("text-align", "right")
txtInternetRate2.Width = 100
gvr.Cells(7).Controls.Add(txtInternetRate2)
Dim txtInternetRate3 As New TextBox()
txtInternetRate3.ID = "txtInternetRate3"
txtInternetRate3.Text = FormatNumber(gvr.Cells(8).Text)
If txtInternetRate3.Text = "0.00" Then txtInternetRate3.Text = "NA"
txtInternetRate3.Style.Add("text-align", "right")
txtInternetRate3.Width = 100
gvr.Cells(8).Controls.Add(txtInternetRate3)
Dim txtInternetRate4 As New TextBox()
txtInternetRate4.ID = "txtInternetRate4"
txtInternetRate4.Text = FormatNumber(gvr.Cells(9).Text)
If txtInternetRate4.Text = "0.00" Then txtInternetRate4.Text = "NA"
txtInternetRate4.Style.Add("text-align", "right")
txtInternetRate4.Width = 100
gvr.Cells(9).Controls.Add(txtInternetRate4)
Next
Else
End If
tbcdynamic.Controls.Add(gv_alines)
tbrdynamic.Cells.Add(tbcdynamic)
tbldynamic.Rows.Add(tbrdynamic)
tabcontent.Controls.Add(tbldynamic)
ajxTab.Tabs(i).Controls.Add(tabcontent)
Next
pnlDynamic.Controls.Add(ajxTab)
End Sub
Private Sub createTab()
ds = allotmentdb.getRoomType()
ajxTab = New AjaxControlToolkit.TabContainer()
ajxTab.Attributes.Add("runat", "server")
'Me.Controls.Add(ajxTab)
For i As Integer = 0 To ds.Tables(0).Rows.Count - 1
Dim tbpnlDynamic As New TabPanel()
tbpnlDynamic.Attributes.Add("runat", "server")
tbpnlDynamic.HeaderText = ds.Tables(0).Rows(i)("RoomType").ToString()
tbpnlDynamic.ID = ds.Tables(0).Rows(i)("RoomTypeKey").ToString()
tbpnlDynamic.Visible = True
ajxTab.Tabs.Add(tbpnlDynamic)
ajxTab.ActiveTabIndex = 0
Next
End Sub
I need it very urgently. Thanks in advance!

VB dataset issue

The idea was to create a message box that stores my user name, message, and post datetime into the database as messages are sent.
Soon came to realize, what if the user changed his name?
So I decided to use the user id (icn) to identify the message poster instead. However, my chunk of codes keep giving me the same error. Says that there are no rows in the dataset ds2.
I've tried my Query on my SQL and it works perfectly so I really really need help to spot the error in my chunk of codes here.
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim name As String
Dim icn As String
Dim message As String
Dim time As String
Dim tags As String = ""
Dim strConn As System.Configuration.ConnectionStringSettings
strConn = ConfigurationManager.ConnectionStrings("ufadb")
Dim conn As SqlConnection = New SqlConnection(strConn.ToString())
Dim cmd As New SqlCommand("Select * From Message", conn)
Dim daMessages As SqlDataAdapter = New SqlDataAdapter(cmd)
Dim ds As New DataSet
cmd.Connection.Open()
daMessages.Fill(ds, "Messages")
cmd.Connection.Close()
If ds.Tables("Messages").Rows.Count > 0 Then
Dim n As Integer = ds.Tables("Messages").Rows.Count
Dim i As Integer
For i = 0 To n - 1
icn = ds.Tables("Messages").Rows(i).Item("icn")
Dim cmd2 As New SqlCommand("SELECT name FROM Member inner join Message ON Member.icn = Message.icn WHERE message.icn = #icn", conn)
cmd2.Parameters.AddWithValue("#icn", icn)
Dim daName As SqlDataAdapter = New SqlDataAdapter(cmd2)
Dim ds2 As New DataSet
cmd2.Connection.Open()
daName.Fill(ds2, "PosterName")
cmd2.Connection.Close()
name = ds2.Tables("PosterName").Rows(0).Item("name")
message = ds.Tables("Messages").Rows(i).Item("message")
time = ds.Tables("Messages").Rows(i).Item("timePosted")
tags = time + vbCrLf + name + ": " + vbCrLf + message + vbCrLf + tags
Next
txtBoard.Text = tags
Else
txtBoard.Text = "nothing to display"
End If
End Sub
Would it be more efficient to combine both cmd and cmd2, such that cmd becomes
SELECT msg.*,mem.Name FROM Message msg INNER JOIN Member mem ON msg.icn = mem.icn ?
This way, your Member.name would be in the same dataset as your Messages table, making your code much cleaner.
-Joel

Resources