Hi iam creating a Word document like:
Dim oApp As Word.Application
Dim oDoc As Word.Document
oApp = CreateObject("Word.Application")
oDoc = oApp.Documents.Add
Dim rng As Word.Range = oDoc.Range(0, 0)
rng.Font.Name = "Verdana"
rng.Font.Size = 16
.......
...............
oApp.Visible = True
oDoc = Nothing
oApp = Nothing
This works perfect on my local machine. But if i put my Code on Webserver it of course does not work.
My Question is: What i have to do, that the Word document gets created on the server and offer the created document to the client as Download.
Can someone help me with that? Thanks!!
I think they way you are currently doing this requires Microsoft Word (Or at least the Interop components) to be present on the server to allow this.
Perhaps a better approach would be to create a PDF on the fly and offer that to the client
alternatively perhaps this approach would work or this?
EDIT:
Also please see how-to-generate-word-documentdoc-docx-in-asp-net
EDIT:
This code snippet will allow you to stream the file down to the client
using (MemoryStream mem = new MemoryStream())
{
// Create Document
using (<declare document>))
{
//create your document here
// Stream it down to the browser
Response.ContentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
Response.AppendHeader("Content-Disposition", "attachment;filename=HelloWorld.docx");
mem.Position = 0;
mem.CopyTo(Response.OutputStream);
Response.Flush();
Response.End();
}
}
Just saw this...
I have managed to get Word running on a server (Apache). You must run Apache under a user account that can run Word. Also if you use Office 32-bit you must run Apache 32-bit. Only one instance of Word runs at one time. However, Word can have multiple documents open at the same time. I developed an addin that I put in Word's startup directory so it is available for each document. In the AutoExec macro I trigger the code that reads a job queue and generates the document. All this is run from the web using AJAX and PHP.
Related
I have a program that requires the use of a file with the extension .dotx. Right now I have it as a resource in the solution. With the following code, instead directly using "C:\letterhead.dotx" I want to use the file I have as an 'Embedded Resource'. I tried the following.
Dim oWord As Word.Application
Dim oDoc As Word.Document
oWord = CreateObject("Word.Application")
oWord.Visible = False
'Works:
oDoc = oWord.Documents.Add("C:\Letterhead.dotx")
'Does not work:
oDoc = oWord.Documents.Add(My.Resources.Letterhead)
'Does not work:
oDoc = oWord.Documents.Add(My.Resources.ResourceManager.BaseName & "\Letterhead.dotx")
I am aware that all of those are returning the wrong values and not what I want. I just don't want to force anyone, using this, to put the Letterhead file in a specific place on their computer before running it. I'm sure there's a simple solution, I just don't know it.
Solution:
For all of those (just me) that are also having this problem, all you have to do is the following to write the embedded file to C:\ -
Try
File.WriteAllBytes("C:\Letterhead.dotx", My.Resources.Letterhead)
Catch ex As Exception
MessageBox.Show("Failed to write to C:\", "", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
You can absolutely store a Word document in a .NET assembly in an embedded resource, and it's fairly trivial to extract it. However, if you want to open a Word document, the steps would be:
Extract the embedded resource to a bytestream
Write the bytestream to a disk (temp folder, perhaps?) as a "doc" or "docx" file
Open that file from disk with Word
...which is quite a bit more work than just including a Word document with the software. Unless you have a very compelling reason to do this with an embedded resource, I would just include the Word document with the application.
If you want some more details, check out Aseem Gautam's answer to this question.
I am using this code to get and minimize all open Word documents.
Word.Application wordApp = new Word.Application();
Word.Documents docs = wordApp.Documents;
wordApp.ScreenUpdating = true;
wordApp.WindowState = Word.WdWindowState.wdWindowStateMinimize;
But documents list is empty despite the fact that I have open Word 2010 documents in Windows 7. Also minimization is not working.
How can I get and minimize all open Word documents?
new Word.Application() will always create a new instance of Word.
to connect to an existing instance, you can use
Word.Application wordApp = (Word.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Word.Application");
(this is similar to the VB/VBA "GetObject" function).
Then you should be able to access your documents.
I'm trying to open a doc file under VB.NET, I found a very simple way to do it using word:
For example:
Dim doc As Word.Document
Dim wordApp As New Word.Application
Dim allText As String
Try
doc = wordApp.Documents.Open("C:\marti.doc")
allText = doc.Range.Text()
doc.Close()
RichTextBox1.Text = allText
Catch
'error
End Try
(More detailed info: http://support.microsoft.com/kb/316383)
This could work, but it need to open Microsoft Word window to handle it. I need to use it without Word installed. So I need a Library which can open doc/excel files.
Do you know a good Library that can do this?
I found this library:
http://bytescout.com/download/trial/documentsdk.html
Have you tried this?
The recommended way of interacting with Office files is through the Office OpenXML library. You can get it here.
If you are using Microsoft Office 2003, you can load and save documents in Open XML if you have installed the Microsoft Office Compatibility Pack for Word, Excel, and PowerPoint 2007 File Formats. You can download the compatibility pack and find more info here.
This is an example method to gather the content of the document:
Private Shared Function GetWordDocContent(strDoc As String) As String
Dim stream As Stream = File.Open(strDoc, FileMode.Open)
Dim wordprocessingDocument__1 As WordprocessingDocument = WordprocessingDocument.Open(stream, True)
Dim body As Body = wordprocessingDocument__1.MainDocumentPart.Document.Body
Dim content As String = body.InnerText
wordprocessingDocument__1.Close()
Return content
End Function
Another example here.
for handling docx file you can try NPOI or DocX
for the old word format (.doc) I've tried Syncfusion DocIO components, but i prefer to use word automation with NetOffice, much better than the interop
I'm stuck with this problem for days
I have to read a specific mailbox in lotus notes and bring all the content into an excel spread sheet
but so far I have only been able to read the default inbox and have no way of switching to the other mailbox. I 'm really new to VBA can any one help me sort this out
here is the code I 'm using
Set NSession = CreateObject("Notes.NotesSession")
'get the name of the mailfile of the current user
DbLocation = NSession.GETENVIRONMENTSTRING("mail/mailbox", True)
'Get the notesdatabase for the mail.
Set NMailDb = NSession.GETDATABASE("mailboxer", DbLocation)
MsgBox (DbLocation)
I get an empty msgbox poping up
GetEnvironmentString() reads the notes.ini file. I'm not sure that's what you really want to be doing. Just from the syntax, I think you're using "mail/mailbox" as a placeholder for the actual path to the mailbox that you're looking for. E.g., you're really trying to read the mail from something like "mail/jsmith.nsf". (If I'm wrong, and you really do want to be reading the notes.ini file to get the location of the mail file, then your problem is that "mail/mailbox" is not a valid key for an ini file entry.)
My next assumption is that the Domino server where the mailbox lives is called "mailboxer", because that's what you're putting in the first argument of GetDatabase().
If I'm right about these things, then what what you need is
Set NMailDb = NSession.GETDATABASE("mailboxer", "mail/mailbox")
where "mail/mailbox" is replaced with the actual path to the mailbox that you are trying to open.
Some thoughts:
use Lotus.NotesSession if you don't have to interact with the Notes UI (Lotus.NotesSession is COM based, whereas Notes.NotesSession is OLE based)
make sure the user of the Notes client on the workstation running your VBA application has the rights require to open and read the mailbox
As D. Bugger stated, you need to be sure you have the Notes client installed on the same client machine your VB code will run, and you need to be sure the folder with the nnotes.exe file and the folder with the notes.ini file are in your environment path. (If not, you will get a COM error instantiating the Notes.NotesSession object.
If this helps, here is some starter code - not tested, but a rough guide... This walks through all documents in a Notes mailbox database, ignores anything except email documents (which have the form field = "Memo") and grabs some fields from each email.
Public Sub exportNotesMail(MailServer$, MailDBPath$)
Dim mailDb As Object, doc As Object, alldocs As Object, Session As Object
Set Session = CreateObject("Notes.NotesSession")
Set mailDb = Session.GETDATABASE(MailServer, MailDbPath$)
If mailDb.IsOpen = False Then mailDb.OPENMAIL
Set alldocs = mailDb.AllDocuments
Set doc = alldocs.GetFirstDocument
while not (doc is nothing)
If doc.GetItemValue("Form")(0) = "Memo" Then
thisSubject = doc.getItemValue("Subject")(0)
thisFrom = doc.getItemValue("From")(0)
' get more field values
' Export to Excel or wherever
End If
Set doc = alldocs.GetNextDocument(doc)
Next i
' done
End Sub
call exportNotesMail ("MyServer", "mail\myMailFile.nsf")
I am working on a vb.net project. I am trying to convert the content of a pdf file to string using acrobat dlls (cannot use other 3 rd party dlls). Below is my code, when I run the program I am getting the following error: "Retrieving the COM class factory for component with CLSID, failed due to the following error: 80040154 Class not registered". I did some research and found out that I have to install the full version of acrobat standard or professional version. Not only that the full version of acrobat must also be installed in all the user machines that the program runs.
Can anyone tell me if this is true and suggest how to fix the class not registered error?
Sub Main()
Dim s As String
Dim sSourceFile As String
sSourceFile = "P:\Report images\DevReports\New Folder\UM-STD-Approval_154.pdf"
Dim oSourceFileInfo As New System.IO.FileInfo(sSourceFile)
Dim st As New AcroPDDoc
st.Open(sSourceFile)
s = GetText(st)
Dim oAcroApp As Acrobat.CAcroApp = New Acrobat.AcroApp
Dim oAcroAvDoc As Acrobat.CAcroAVDoc = New Acrobat.AcroAVDoc
Dim oAcroPDDoc As Object = Nothing
If oAcroAvDoc.Open(sSourceFile, "") Then
'Set PDDoc object and save the file.
oAcroPDDoc = oAcroAvDoc.GetPDDoc()
' oAcroPDDoc.Save(1, sOutputFile)
Else ' Document FAILED to open.
MsgBox("Cannot open ")
End If
oSourceFileInfo = Nothing
oAcroApp.CloseAllDocs()
oAcroPDDoc = Nothing
oAcroAvDoc = Nothing
oAcroApp.Exit()
oAcroApp = Nothing
End Sub
Apologies for the obvious answer but you've kind of answered your own question already.
Adobe Reader is a free application with a very limited interface allowing automation; in practice it's limited to the point where you can display a PDF file and navigate through it (to some extent).
For full features automation (like what I think you are looking for) you will need to install the full Adobe Acrobat. And yes, any system you run this on will also need to have Adobe Acrobat installed.
Now, there are probably libraries out there (including libraries from Adobe or containing Adobe technology inside) that will allow you to embed the functionality you are looking for in your application, but those too will not be free...