|
How to create Pdf in windows application? Please Help me
thanku
Piyush Vardhan Singh
p_vardhan14@rediffmail.com
http://holyschoolofvaranasi.blogspot.com
http://holytravelsofvaranasi.blogspot.com
|
|
|
|
|
|
THankou Sir
Answer:
Dim Filename As String = Application.StartupPath + "\Export.pdf"
Dim _SaveFileDialog As New SaveFileDialog
_SaveFileDialog.Filter = "Apache Files (.pdf)|.pdf"
'sss.Filter = "HTML Files (.htm)|.htm|" + _
' "Active Server Pages (.asp)|.asp|" + _
' "Apache Files (.pdf)|.pdf|" + _
' "Perl Script (.pl)|.pl|" + _
' "All Files|"
_SaveFileDialog.ShowDialog()
Filename = _SaveFileDialog.FileName
If Windows.Forms.DialogResult.Yes Then
Dim myDoc As New Document()
PdfWriter.GetInstance(myDoc, New FileStream(Filename, FileMode.Create))
myDoc.Open()
myDoc.Add(New Paragraph(" "))
myDoc.Add(New Paragraph("User Responses are as Follows:"))
myDoc.Close()
End If
Piyush Vardhan Singh
p_vardhan14@rediffmail.com
http://holyschoolofvaranasi.blogspot.com
http://holytravelsofvaranasi.blogspot.com
|
|
|
|
|
Hi everyone,
I have data from my server using sql data. I had the problem to export my data from datagrid to excel. For 200 data is oke, no problem but more than 200 , the program is stuck. Anybody can help me to solve this problem ????
Private Sub ToolStripexport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripexport.Click
If (Me.dbgridinv Is Nothing) Then
Throw New ArgumentNullException("No DataGridView was provided for export")
End If
Using saveFileDialog As SaveFileDialog = Me.GetExcelSaveFileDialog
If (saveFileDialog.ShowDialog(Me) = DialogResult.OK) Then
Dim fileName As String = saveFileDialog.FileName
ExcelGenerator.Generate(Me.dbgridinv).Save(fileName)
Process.Start(fileName)
End If
End Using
End Sub
---------------------------------------------------
Imports CarlosAg.ExcelXmlWriter
Imports System
Imports System.Drawing
Imports System.Windows.Forms
Public Class ExcelGenerator
' Methods
Public Shared Function Generate(ByVal dataGridView As DataGridView) As Workbook
Dim workbook As New Workbook
Dim worksheet As Worksheet = workbook.Worksheets.Add("Sheet 1")
Dim worksheetRow As New WorksheetRow
Dim dataGridViewColumn As DataGridViewColumn
For Each dataGridViewColumn In dataGridView.Columns
worksheet.Table.Columns.Add(New WorksheetColumn(dataGridViewColumn.Width))
worksheetRow.Cells.Add(New WorksheetCell(dataGridViewColumn.HeaderText))
Next
worksheet.Table.Rows.Insert(0, worksheetRow)
Dim worksheetDefaultStyle As WorksheetStyle = ExcelGenerator.GetWorksheetStyle(dataGridView.DefaultCellStyle, "Default")
workbook.Styles.Add(worksheetDefaultStyle)
Dim rowIndex As Integer
For rowIndex = 0 To dataGridView.RowCount - 1
worksheetRow = worksheet.Table.Rows.Add
Dim columnIndex As Integer
For columnIndex = 0 To dataGridView.ColumnCount - 1
Dim cell As DataGridViewCell = dataGridView.Item(columnIndex, rowIndex)
Dim cellStyle As WorksheetStyle = ExcelGenerator.GetWorksheetStyle(cell.InheritedStyle, String.Concat(New Object() {"column", columnIndex, "row", rowIndex}))
If (Not cellStyle Is Nothing) Then
workbook.Styles.Add(cellStyle)
Else
cellStyle = worksheetDefaultStyle
End If
Dim dataType As DataType = ExcelGenerator.GetDataType(cell.ValueType)
worksheetRow.Cells.Add(cell.FormattedValue.ToString, dataType, cellStyle.ID)
Next columnIndex
Next rowIndex
Return workbook
End Function
Private Shared Function GetColorName(ByVal color As Color) As String
Return ("#" & color.ToArgb.ToString("X").Substring(2))
End Function
Private Shared Function GetDataType(ByVal valueType As Type) As DataType
If (Not valueType Is GetType(DateTime)) Then
If (valueType Is GetType(String)) Then
Return DataType.String
End If
If ((((((valueType Is GetType(SByte)) OrElse (valueType Is GetType(Byte))) OrElse ((valueType Is GetType(Short)) OrElse (valueType Is GetType(UInt16)))) OrElse (((valueType Is GetType(Integer)) OrElse (valueType Is GetType(UInt32))) OrElse ((valueType Is GetType(Long)) OrElse (valueType Is GetType(UInt64))))) OrElse ((valueType Is GetType(Single)) OrElse (valueType Is GetType(Double)))) OrElse (valueType Is GetType(Decimal))) Then
Return DataType.Number
End If
End If
Return DataType.String
End Function
Private Shared Function GetWorksheetStyle(ByVal dataGridViewCellStyle As DataGridViewCellStyle, ByVal id As String) As WorksheetStyle
Dim worksheetStyle As WorksheetStyle = Nothing
If (Not dataGridViewCellStyle Is Nothing) Then
worksheetStyle = New WorksheetStyle(id)
If Not dataGridViewCellStyle.BackColor.IsEmpty Then
worksheetStyle.Interior.Color = ExcelGenerator.GetColorName(dataGridViewCellStyle.BackColor)
worksheetStyle.Interior.Pattern = StyleInteriorPattern.Solid
End If
If Not dataGridViewCellStyle.ForeColor.IsEmpty Then
worksheetStyle.Font.Color = ExcelGenerator.GetColorName(dataGridViewCellStyle.ForeColor)
End If
If (Not dataGridViewCellStyle.Font Is Nothing) Then
worksheetStyle.Font.Bold = dataGridViewCellStyle.Font.Bold
worksheetStyle.Font.FontName = dataGridViewCellStyle.Font.Name
worksheetStyle.Font.Italic = dataGridViewCellStyle.Font.Italic
worksheetStyle.Font.Size = CInt(dataGridViewCellStyle.Font.Size)
worksheetStyle.Font.Strikethrough = dataGridViewCellStyle.Font.Strikeout
worksheetStyle.Font.Underline = IIf(dataGridViewCellStyle.Font.Underline, UnderlineStyle.Single, UnderlineStyle.None)
End If
worksheetStyle.Borders.Add(StylePosition.Top, LineStyleOption.Continuous, 1, "Black")
worksheetStyle.Borders.Add(StylePosition.Right, LineStyleOption.Continuous, 1, "Black")
worksheetStyle.Borders.Add(StylePosition.Bottom, LineStyleOption.Continuous, 1, "Black")
worksheetStyle.Borders.Add(StylePosition.Left, LineStyleOption.Continuous, 1, "Black")
End If
Return worksheetStyle
End Function
End Class
|
|
|
|
|
I have an app where I have a parent and child form. How can I capture the key that is pressed (if any) on the child form? I tried the keydown method, but when I run the program, it will not enter the method when I type a key.
Any help would be appreciated. Thanks.
|
|
|
|
|
the 2 forms are completely independent of each other even though you started one from another. event or delegate is the proper way to go.
the event example(done by memory - syntax is mostly good)
public class form1
private withevents mForm2 as form2
private sub ChildKeyDown(sChar as string) handles mForm2.ChildKeyDown
msgbox("the key pressed was: " & sChar
end sub
'add logic to show form2
end class
public class form2
event ChildKeyDown(sChar as string)
private textbox1_keydown(sender , e ) handles textbox1.keydown
raiseevent childkeydown(e.keychar)
end sub
end class
'Never argue with an idiot; they'll drag you down to their level and beat you with experience.' ~ anonymous
'Life's real failure is when you do not realize how close you were to success when you gave up.' ~ anonymous
|
|
|
|
|
Just wanted to say thanks for this post - this is an area that is new to me and you have answered a question I had. 5 Stars
Guy
You always pass failure on the way to success.
|
|
|
|
|
hi
we are currently making a website, we also have a client in vb.net
the client works like gtalk where the user has to log in..
the same username and password will apply to the website and the client
is there anyway that we can post values/data from the client to the website, but it needs to be specific to the username provided by the user
in other word, what ever is uploaded from the client must go directly to the webpage of the specific user
any help would be most appreciated
thanks
|
|
|
|
|
I'd recommend developing a webservice to which your client app. 'talks'...
|
|
|
|
|
I'm using the SaveFileDialog in VB.NET 1.1 and would like to perform some processing if the user has clicked yes to overwritting an existing file but I cant seem to be able to catch this. I have tried to use something like (If SaveFileDialog.ShowDialog = DialogResult.Yes Then) but I cant seem to hit this condition at all. Any help please!
JojoStoneHead
|
|
|
|
|
Have you tried using DialogResult.OK ?
I hope this helps.
|
|
|
|
|
thanks but DialogResult.OK is only hit if the file does not exist and the over write dialog is not displayed. However when the overwrite dialog is displayed the buttons displayed are Yes/No and after accepting to overwrite I cant hit DialogResult.OK or DialogResult.Yes
|
|
|
|
|
The following code works fine for me, even if the file exists and I press Yes to the Overwrite Prompt.
If sfd.ShowDialog = Windows.Forms.DialogResult.OK Then<br />
MsgBox("Save Done")<br />
End If
Which version of Visual Basic are you using? I suppose if worse comes to worse, you could disable the Overwrite Prompt property and do a manual check whether the file exists or not, IO.File.Exists(SaveFileDialog.FileName) , and then proceed from there.
|
|
|
|
|
Hi,
IMO you worry too much.
this is the behavior I expect: when you choose the destination file and it
- either does not exist
- or it exists but you allow for an overwrite,
then the SaveFileDialog will return a go-ahead result (I think it's OK),
and your code should open the file for writing in such a way that it does not
matter whether it already exists or not, such as:
- File.Create() which creates new, or overwrites without appending
- File.CreateText() which creates new, or overwrites without appending
The above would work fine, except in one special case, that's when the file already exists
but is set to read-only (not checked by SaveFileDialog).
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
for the existing MenuStrip-Item I want to create an appropriate ToolStrip with identical buttons.
But how can I access the existing click-events?
I cannot "addhandler mmi.click, adressof mi.click" and
"adressof mi.onclick" also fails because it's protected.
In c# I must add the handlers manually, so I know them, but in vb
it's hidden...
<br />
For Each Mi As ToolStripItem In FileMenu.DropDownItems<br />
If TypeOf (Mi) Is ToolStripMenuItem Then<br />
Dim mmi As New ToolStripButton<br />
mmi.Text = ""<br />
mmi.Image = Mi.Image<br />
mmi.ToolTipText = Mi.Text<br />
<br />
addhandler mmi.click, "get the handler of the mi.click-event"<br />
<br />
tsProgramm.Items.Add(mmi)<br />
ElseIf TypeOf (Mi) Is ToolStripSeparator Then<br />
Dim mmi As New ToolStripSeparator<br />
tsProgramm.Items.Add(mmi)<br />
Else<br />
<br />
End If<br />
Next<br />
Thanks in advance
Chris
|
|
|
|
|
Where is this existing click handler coming from?
If you haven't created and assigned one, it doesn't yet exist.
If you have, then keep a reference to the delegate for later assignment.
If you're refering to one used by the control internally, it maybe accessible via reflection - but that would be very poor design.
I'm largely language agnostic
After a while they all bug me
|
|
|
|
|
MidwestLimey wrote: Where is this existing click handler coming from?
I wrote it, every menuitem has a eg fileopen_click(sender, e) handles fileopen.click.
MidwestLimey wrote: If you have, then keep a reference to the delegate for later assignment.
Isn't there a get-the-address-of-the-onclick-event--function in the .net-jungle?
MidwestLimey wrote: If you're refering to one used by the control internally, it maybe accessible via reflection - but that would be very poor design.
Ugly, yes...
Fastest way would be coding out every menuitem, but that's not very genious.
Thanks for your answer
Chris
|
|
|
|
|
I got a solution, but with that I have to declare all Menuitem_Click-Subs as Public and I have to set an InitFlag into them to supress invocation, because CallByName calls the event...
For Each Mi As ToolStripItem In FileMenu.DropDownItems<br />
If TypeOf (Mi) Is ToolStripMenuItem Then<br />
Dim mmi As New ToolStripButton<br />
mmi.Text = ""<br />
mmi.Image = Mi.Image<br />
mmi.ToolTipText = Mi.Text<br />
Dim pArray() As Object = {Mi, New System.EventArgs}<br />
<br />
Dim delegateMn As System.EventHandler = CType(CallByName(Me, Mi.Name & "_Click", CallType.Method), System.EventHandler)<br />
AddHandler mmi.Click, delegateMn<br />
<br />
tsProgramm.Items.Add(mmi)<br />
ElseIf TypeOf (Mi) Is ToolStripSeparator Then<br />
Dim mmi As New ToolStripSeparator<br />
tsProgramm.Items.Add(mmi)<br />
Else<br />
<br />
End If<br />
Next
|
|
|
|
|
Why not declare the delegate ahead of time and then assign to each item's event?
Dim myDelegate As EventHandler = AddressOf MenuItem_Click
Where MenuItem_Click is a generic event handler for tool strip menu items.
I'm largely language agnostic
After a while they all bug me
|
|
|
|
|
Then I have to write 15 or more new delegates? Right?
The aim was to add a toolstrip to the existing menustrip to act like a buddy.
The new toolstrips get all properties from the existing menustrips and share the same events (there are more than 1 menustrip in the mdi).
So I thought I could put some code-lines into a loop....
|
|
|
|
|
If I understand what you're trying to do (bear with me, I'm slow today!), then wouldn't it be easier to add a general event handler to the buddy strip buttons that calls PerformClick on the appropriate menu buttons? You could maintain context via either the Tag property or a dictionary.
I'm largely language agnostic
After a while they all bug me
|
|
|
|
|
That would be a very good solution. I'll try it out.
Thanks
Chris
|
|
|
|
|
Hi
Don't think this is VB.NET but... How do I loop thru each non-empty row in Excel VBA?
<br />
For Each oSheet In Worksheets<br />
For Each oRw In oSheet.Rows<br />
IsRowEmpty(oRw) ' Do I need to code IsRowEmpty?<br />
Next oRw<br />
Next oSheet
Thanks
devy
|
|
|
|
|
devvvy wrote: IsRowEmpty(oRw) ' Do I need to code IsRowEmpty?
Yes, because "empty" can have any number of meanings. Does empty mean that there are no values?, no formulas?, no formatting?, ... You have to code this to test to see if the row meets your specification of "empty".
|
|
|
|
|
Okay you are right. But then comes another technical problem...
say I selected three rows on worksheet.
Worksheets("Data").ActiveCell.Row only gives you ONE of the three selected rows.
How do I retrieves all three selected rows?
Thanks!
devy
|
|
|
|