|
this is the function I am using by passing datatable and filename
Private Sub SaveDataToMSWord(ByVal dt As DataTable, ByVal FileName As String)
Try
Dim oldCI As System.Globalization.CultureInfo = _
System.Threading.Thread.CurrentThread.CurrentCulture
System.Threading.Thread.CurrentThread.CurrentCulture = _
New System.Globalization.CultureInfo("en-US")
Dim wapp As Word.Application
Dim wdoc As Word.Document
' Dim strDbFullPath As String
Dim strText As String
wapp = New Word.Application
wapp.Visible = True
wdoc = wapp.Documents.Add
Dim Count As Integer = 0
For Count = 0 To dt.Rows.Count - 1
Dim strDesignation As String = dt.Rows(Count).Item("ConJobTitleManual")
If strDesignation = "" Then
strDesignation = dt.Rows(Count).Item("Others")
End If
strText = dt.Rows(Count).Item("cpyName")
With (wapp.Selection)
.Font.Size = 14
.Font.Color = Word.WdColor.wdColorBlack
.Font.Bold = True
.TypeText(strText)
.InsertBreak(Type:=Word.WdBreakType.wdLineBreak)
.Font.Size = 9
.Font.Bold = False
.TypeText(dt.Rows(Count).Item("cpyAddress1") & "," & dt.Rows(Count).Item("cpyTown") & "," & dt.Rows(Count).Item("cpyCounty") & "," & dt.Rows(Count).Item("cpyPostCode"))
.InsertBreak(Type:=Word.WdBreakType.wdLineBreak)
.TypeText(dt.Rows(Count).Item("cpyCountry"))
.InsertBreak(Type:=Word.WdBreakType.wdLineBreak)
If dt.Rows(Count).Item("cpySIC1") <> 0 Then
.TypeText("SIC:" & dt.Rows(Count).Item("cpySIC1"))
If dt.Rows(Count).Item("cpySIC2") <> 0 Then
.TypeText("," & dt.Rows(Count).Item("cpySIC2"))
End If
End If
.InsertBreak(Type:=Word.WdBreakType.wdLineBreak)
.TypeText(dt.Rows(Count).Item("cpyURL"))
.InsertBreak(Type:=Word.WdBreakType.wdLineBreak)
.TypeText("Tel:" & dt.Rows(Count).Item("ConTelMain"))
.InsertBreak(Type:=Word.WdBreakType.wdLineBreak)
End With
Dim counter As Integer = Count
For counter = Count To dt.Rows.Count - 1
If dt.Rows(counter).Item("cpyName") = dt.Rows(Count).Item("cpyName") Then
strText = strDesignation & vbTab & dt.Rows(counter).Item("conEmail") & vbTab & vbTab & dt.Rows(counter).Item("cpyTelSwitchBoard")
With (wapp.Selection)
.Font.Size = 9
.Font.Bold = True
.Font.Color = Word.WdColor.wdColorBlack
.TypeText(dt.Rows(counter).Item("conFirstName") & " " & dt.Rows(counter).Item("ConSurName"))
.Font.Bold = False
.TypeText(" " & strText)
.InsertBreak(Type:=Word.WdBreakType.wdLineBreak)
End With
Else
Count = counter - 1
Exit For
End If
Next
Next
wapp.Selection.InsertBreak(Type:=Word.WdBreakType.wdPageBreak)
wdoc.SaveAs(FileName)
Dim idoc As Word._Document
idoc = wdoc
idoc.Close()
Dim iapp As Word._Application
iapp = wapp
iapp.Quit()
wapp = Nothing
GC.Collect()
Catch ex As Exception
msgbox(ex.Message)
End Try
End Sub
if it does not work then your asp_net user do not have rights to use the word. go to control panel and in user accounts change the asp net user from limited to adminsitrator. Hopefully this will reolve your problem.
Regards
Rizwan Bashir
|
|
|
|
|
Thanx rizwan for your help.....but this code works in windows application not in web application...anyways i got a way to get it in web application, but now i have another problem, i have a datagrid in the same application now i want to get that data grid in the word document....can you help me on this.....
thanks a lot rizwan
manik
|
|
|
|
|
Hi
Friend, i need a small help
I want to displya the word document on the web form
with out changing the formate
ie ., i need some control with in which i can display
the word document in the server
Thanks in Advance
|
|
|
|
|
if u add reference office 11 object library then..you can open word.
|
|
|
|
|
Hi everyone,
I am trying to convert a string format date e.g "13/07/2006" to a date. I am getting an error "String was not recognized as a valid DateTime".
How can i convert it to "MM/dd/yyyy" format.
Please reply
thanks,
Sanded
|
|
|
|
|
Use the DateTime.ParseExact method.
---
b { font-weight: normal; }
|
|
|
|
|
hey
u can use any of this...
1.FormatDateTime(frDate, DateFormat.ShortDate)
2.cDate(frdate) this is best method to convert ur string .
Parag
|
|
|
|
|
first import System.Globalization namespace
'create an object of culture info
Dim myCI As New CultureInfo("en-US", False)
'take culture info's clone
Dim myCIclone As CultureInfo = CType(myCI.Clone(), CultureInfo)
'customise its date pattern
myCIclone.DateTimeFormat.DateSeparator = "/"
myCIclone.DateTimeFormat.ShortDatePattern = "dd/MM/yyyy"
'parse date string with this pattern
DateTimePicker1.Value = DateTime.Parse("13/07/2006", myCIclone.DateTimeFormat)
and u have done !;)
milan
|
|
|
|
|
thanks milanatdigi,
Your solution was helpful. While the Solution provided by other guys created the same error message but i really appreciate their help as well.
thanks,
Sanded
|
|
|
|
|
my application is actually a web application where i manually upload CSV file to the database.but i want to automate the process,so i have thought of a second stage to this application i.e through a windows application i would download the CSV file from the NSEIndia.com site automatically and then upload the same to SQLServer on the server.i am facing a problem with upload i.e exporting the data to the database.it would be a great help to me if any one could provide me a solution either in VB.Net code or C# code.
AMIT(TATA CMC)
-- modified at 1:47 Tuesday 11th July, 2006
|
|
|
|
|
Hi All ,
I'm new in VB6.I have some doubts regarding forms.Basically my project consist of 2 forms(Form1 & Form2).Form1 is working perfectly fine.But when Form2 is load,the functions in it tends to slow down.But the codes is the same as Form1.Anyone met this prob before?I tried setting the timer faster but the outcome is the same.Thanks in advance.
|
|
|
|
|
Never heard of the problem before. There's go to to be something in your code that's doing it. You mentioned Timers? Are you doing things on both forms at the same time? This might have something to do with it...
Why are you learning VB6?? It's pretty much a dead product. You can get VB.NET 2005 Express Edition for free here[^].
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Oh,i know VB.NET is a more updated version.But i'm handling a project that
is previously done by other people.He uses VB6 so i have to continue with it.
Regarding the timers,at only 1 time,only an event is executed.But i have set timer6 in Form1 as well as Form2.After proceeding from Form1 to Form2,i hope that the events at Form1 won't be executed.But i also don't want to unload it as i need it at a later part.I cant possibly declare all timers disabled at Form2 as there are a large number of timers at Form1.So i hope someone can help me with this.Thanks alot.
|
|
|
|
|
K718 wrote: as there are a large number of timers at Form1
Uhhh, yeah. You might have found your problem.
Your explanation of what each form is doing is far from useful. All I know is that your using a large number of Timers, which is not a good idea. Since every one of those timers is firing it's "Tick" event on the UI thread, your Timers are probably bogging down your entire application.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
hmm...as my proj need quite alot of functions,so i need to use so many timers.For Form1,i'm using Timer6 to make numbers selection.For Form2,i'm also using Timer6.It is the same codes but its the running of the contents that is different.Form1 is working fine(with some minor errors) but Form2 tends to be slower in reacting that causes distorted output.I set the timer interval faster but there isn't any difference.So what could be due to?Thanks alot.
|
|
|
|
|
K718 wrote: i'm using Timer6
Whats a "Timer6"?
Without seeing any of your code, it's impossible to understand what your trying to describe.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Hi,
I am getting this error when I try to add null to the value. Operator is not valid for type DBNull and type Date. Not sure how to fix this issue. I tried everything I could, but with no luck. Any help will be appreciated. Thanks
This is the code I have so far, which is causing the error.
comm.CommandText = "Update testbackup set datein = (null) & timein = (null) where barcodeid = '" & DgDisplay.Item(DgDisplay.CurrentRowIndex, 0).ToString & "'"<br />
comm.ExecuteNonQuery()
|
|
|
|
|
I'm not sure there's a way to specify DBNull in a string, perhaps you need to write a stored proc ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
What excatly would I write. Would you be able to help me with that like get me started on the right track. Appreciate it. Thanks
|
|
|
|
|
Assuming you're using SQL Server, something like:
CREATE PROC ClearBackup @id nvarchar(20)
as
Update testbackup set datein = null & timein = null where barcodeid = @id
go
will create the proc. Change nvarchar(20) to whatever type your ID is ( why is it not a number ? )
Then you can execute it from code, and pass in the ID.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
I am using access as my back end for database. I am not using SQL server. Sorry for not letting you know before. Does that change now and how
|
|
|
|
|
Access allows stored procs nowadays, I believe, but I don't know the exact way to create them.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Alright. Well thanks for your help. I don't know how to create them either. Hope somebody can help me. Really appreciate your help so far though.
|
|
|
|
|
|
Sorry about not writing in my first post that I am using access as my database. I am not using SQL server. How will the code change and also I am using vb.net 2003 version. Thanks
|
|
|
|