C# To Generate Word Document - c#

So I have a friend who is helping me and I'm really not a programmer but I can understand things when I have a template to build from.
I'm trying to create a program that accepts input from the user to generate a report for traffic accidents. Just to get started I was going to try and learn as much as I could to create the notification section which requires very little input and has little variance.
Section in CAPS would be the input requested from the user. It would be used in other areas so it should be stored as a string for other sections. Also, later there will be areas where the user has to enter parties, witnesses, and vehicles. Since there could be any number of combinations of the three it would have to be programmatically generated where as the notification could be find and replace.
Can someone point me in the right direction with an example code for just the following:
NOTIFICATION: On DATE_DISPATCHED, at approximately TIME_DISPATCHED
hours, I was dispatched to LOCATION_DISPATCHED at COLLEGE for a report
of a CALL_TYPE
NOTIFICATION: On 01-01-2000, at approximately 1000
hours, I was dispatched to South Lot at 1010 Address St for a report
of a small narrative about what happened.

If you are trying to assemble a word document based on a template and some user's input. I think HotDocs is what you need.
If you want to assemble a document programmatically you may refer to Word Add-ins or Office App from Microsoft. Or OpenXML Power Tools for more flexibility.

DOCX has the function I needed and I was able to get this almost completely fixed. I have a working version of exactly what I need but I am now having other problems with the output format. I would suggest anyone with the same goal as I had here to study using a builder to transfer variables in textboxes to a DOCx argument string which is well documented on the DOCX webpage. https://docx.codeplex.com/discussions

Related

Is there a way to capture a view and save it?

We have many element(s) in a ContentPage. The goal is to take a picture of a specific element and then have access to that data - to save it or possibly other things such as cropping it.
So this question is twofold - is there a way to photographically capture a given element? Is there a way to do this if the element is not fully in view? Example a ScrollView would potentially have some of its elements not currently in view.
Our attempt at this is to use device specific screenshots and crop them to a given element. The screenshots are working, but we aren't having luck with cropping. Not to mention in the case as described above the screenshot will not work as the view isn't fully visible.
Is there a way to obtain the "graphical" (photo) data of an element at a given time even if it's not currently visible/partially visible?
Thanks for reading in advance.
After a lot of talking, this is what I understand
The Users of your application are the Workers of Your company
The application is for managing the accounts of your companies Customers
The Customers have no access to their data, in any shape or form
Part of the Customer Data is their Email Adress
You want to send a copy of their Data to the Customers
As Emails do not allow formating that well, you want to send that Data as a Screenshot of the UI.
If I got all that right:
You are neck-deep in a XY Problem. Or rather a ((XY)Y)Y Problem - a XY problem of the 3rd Generation.
The obvious solution would be to fix point 3 and give your customers access to their Data already:
You can do that via a extra Programm, App, a Webpage or anything similar. If they can receive emails, they can download a app or open a Webpage and see their data there. May need a login, but nothing special. There are even ways to encode data/direct links into Emails and register your Programm with a custom Format. Indeed, that is how Steam Links on the Desktop work.
Meanwhile the In-House user get a "Customer Management" Programm that allows more direct access to the Customers Data in the Database (I asume you got a backend Database. But it is at least possible you do not).
If you can not fix Option 3 for stupid Boss/Legal Reasons (these are the only Valid reasons I can Imagine. And I can not stress enoug how stupid the boss would have to be in that), you should at least be able to fix at Point 5/6:
The first Option would be to send Text Emails. People often underestimate jsut how much is possible with pure Text. It is basically like writing on a Console, but even that is enough medium to make a Art in it.
The other ways involve Managing the HTML limitations:
Save HTML Mail
The main security issue with HTML mails, is "downloading external content" part. Those operations can not be reliable scanned by Virus scanners and the like - especially in the age of HTTPS. Unless we talk about Kaspersky and the stupid Idea they had.
And even if they can be scanned reliable, even just the request of those files can be used for spam senders to verify the Email Adress is still in use. So it is a no-go too.
So you will need to Inline as much as possible. Inlining images is not that possible. While HTML totally has a Standart for that - you Base64 encode the binary into the HTML - this does not work reliably. At least Microsoft Outlook is known to interpret all Base64 images in the Email as Attachments - even the inlined ones. And even if they fixed this or it is no longer a relevant issue, inlining images tends to increase the HTML size significantly.
You can use CSS to some degree. But aside from inlining it, you might have to go back a step or two. In the end, Email Programms are really weak web-browsers. So they do not nessesarily support all the latest stuff instantly. Anything below CSS 3.0 should reliably work by now. But you better ask someone once you got more specific Requirements for this Email.
PDF Attachment
Somewhat more established is to create a .PDF file and send it. All those bills/other stuff in .PDF format you get - those have been created on demand from a Database, by the same code that also send the Email. In many cases the demand was automated too or the Sending Programm was a outright Background Process.
.PDF allows all Formating you could want. It can take up images inline. And there is plenty of ways to create .PDF from code. And as you can send it as a attachment, the Virus scanner has time to go over it. And we are not in the last Millenium, where a PDF Reader was a uncommon programm to have installed (I still remember the times when a current Version of Acrobat PDf Reader was delivered on every CD with a .PDF Format Handbook).
If you are stil dead serious about the whole "make a Image of the UI to send that", my only question is: How many Years have been aloted for that?

Connecting To A Website To Look Up A Word(Compiling Mass Data/Webcrawler)

I am currently developing a Word-Completion application in C# and after getting the UI up and running, keyboard hooks set, and other things of that nature, I came to the realization that I need a WordList. The only issue is, I cant seem to find one with the appropriate information. I also don't want to spend an entire week formatting and gathering a WordList by hand.
The information I want is something like "TheWord, The definition, verb/etc."
So, it hit me. Why not download a basic word list with nothing but words(Already did this; there are about 109,523 words), write a program that iterates through every word, connects to the internet, retrieves the data(definition etc) from some arbitrary site, and creates XML data from said information. It could be 100% automated, and I would only have to wait for maybe an hour depending on my internet connection speed.
This however, brought me to a few questions.
How should I connect to a site to look up these words? << This my actual question.
How would I read this information from the website?
Would I piss off my ISP or the website for that matter?
Is this a really bad idea? Lol.
How do you guys think I should go about this?
EDIT
Someone noticed that Dictionary.com uses the word as a suffix in the url. This will make it easy to iterate through the word file. I also see that the webpage is stored in XHTML(Or maybe just HTML). Here is the source for the Word "Cat". http://pastebin.com/hjZj6AC1
For what you marked as your actual question - you just need to download the data from the website and find what you need.
A great tool for this is CsQuery which allows you to use jquery selectors.
You could do something like this:
var dom = CQ.CreateFromUrl("http://www.jquery.com");
string definition = dom.Select(".definitionDiv").Text();

How to write to word document (in a particular format ) From C# windows forms application

I am developing a C# windows application , which captures the user's inputs(in the form of numerous textboxes, radio buttons and drop downs).
I need to write the captured response from User to a word document which fits in the word document which has a predefined template.
Could some one let me know the best way to approach that?
Thanks in advance,
Vijay
Depending upon how complex your needs are and the depth of your pockets there is a great product called Aspose.Words. We use their suite of products for generating office documents at work and they're really easy to work with. It's unfortunately a pretty expensive product so unless you are very committed to your product it might not be right for you.
Otherwise you might want to check out Microsoft's Open XML SDK.
[I have no affiliation with the company, aside from having used their products.]

Using MS Word Templates to allow a user to fill out a report

I'm trying to create create a simple word template on the fly which would just contain text and a few text input fields and then open a new word document based on that template for the user to fill out. I don't think this would be too difficult using Word automation and C#, but I've never worked with Word's COM interface before.
Any links to examples or fresh examples on how to create a simple template with some text and a text input field and then how to open a document based on that template in C# would be greatly appreciated.
Thanks in advance!
I think "Office Interop" is the keyword you are looking for.
You'll find a starting point here: http://support.microsoft.com/kb/316384
Several drawbacks involved (for instance, installed Office on client machine required; not advisable to be run as a server process), but might do the job for your requirement.
I have done a fair amount of work with Word automation - though not really so much with tempates... My advice would be first of all to have a look at the documentation that ships with the product - which is a simple matter of editing a word macro, and pushing F1 in the code editor. I have found that to be a rich source of information...
The other piece of advice I would give you is to try recording a macro in Word that covers any task you want to do, and then inspecting the code that is generated. This has proven invaluable to me in getting stuff up and running quickly...
Hope this helps...
Martin.

Reading Character from Image

I am working on an application which requires matching of numbers from a scanned image file to database entry and update the database with the match result.
Say I have image- employee1.jpg. This image will have two two handwritten entries - Employee number and the amount to be paid to the employee. I have to read the employee number from the image and query the database for the that number, update the employee with the amount to be paid as got from the image. Both the employee number and amount to be paid are written inside two boxes at a specified place on the image.
Is there any way to automate this. Basically I want a solution in .net using c#. I know this can be done using artificial neural networks.
Any ideas would be much appreciated.
You can use Microsoft Office Document Imaging Library (MODI), which is contained in the Office 2003/2007.
Links:
OCR with Microsoft® Office - Code
Project - example of using MODI
Microsoft Office Document Imaging -
Wikipedia - contains a simple
example in VB.NET
Pattern recognition is a basic example when neural networks are studied. I don't know if is any library/framework to work with AI in C#. If you find one, first you have to do is to train the network (supervised learning) and for this you need to prepare a big sample set of images; more examples -> result more accurate. In the other hand you can use OpenCV (C/C++, Python and Java) that is a library specialized in computer vision and has a module to implement AI methods.
Have a nice day!
Oscar.
I think this is very hard to automate. The problem is just because you need some kind of very good OCR software. And even if you got this, what if it reads something wrong, cause of the frouzy handwriting of someone? If the ID is wrong the paid is booked to the wrong employee and if the amount is wrong he got the wrong salary!
Both are things you won't really happen. Just to show you how hard a good ocr to find is, just take a look out there on how a captcha works. The principle is nothing more than an image of an hard to read text.
So my opinion would be, that you can't really automate this process. At least you can write a program to assist a human by entering the values manually (also take a look at Amazon Mechanical Turk):
Show on the right the picture with the handwritten values, or if they are always on the same position or specially marked (with a box around them, etc.), try to find these places automatically and show them to the user.
On the left offer two textboxes, where the user can enter the values.
To get this to a fast and fluent process, you have to take great care about how the user can enter easily the values by just using the keyboard:
When showing a new picture, set the focus to the id textbox
If the user id is always a specific length, switch to the next box if all numbers are entered
(If you allow this, a backspace in the empty next box should focus back to the previous one)
Otherwise allow a change to the next textbox by hitting tab or return
Normally these textboxes are arranged above each other (not side by side), thus you should support switching between them using the up down arrow keys.
After finishing the entry in the last textbox automatically show the next image.
Also in this case of a fresh new entry (nothing already entered) allow a easy switch back to the old entry by using the backspace or left arrow key)
By using such a process a single person can enter many entries into your database and the costs are much cheaper than finding wrong entries in your database afterwards.
Just a last suggestion:
Cause this is a boring process for a human which can easily leads to errors, maybe let two people enter these values and only if both are entering the same than take this value as approved. This should lead to a correct rate somewhere above 99%. If you need absolutely 100% think about letting 4-5 people checking one entry and only if all of them enter the same values take it as approved. To get also a comparsion about how good your ocr software would be, just let it also run over your images and compare this results to the human entered values to get an idea, when you can really rely on your ocr only.
OCR engines are not trained to read handwritten text, so you might have trouble with MODI. You want to try to find an ICR engine. Even so, the best ones of these are only 80% accurate on good inputs. You might get better because you know that your text is always numbers.
This SO question/answer says that OCROpus has ICR
FOSS Intelligent Character Recognition (ICR)
There is LeadTools SDK for OCR/ICR. This is very handy in recognising the handwritten characters. I am doing a feasibilty study with this, and till now I think it will work out. leadTools have provided components which can be used in your application, it supports C, C++, C#, VB.Net etc.
You can visit the following link for this:
http://www.leadtools.com/downloads/default.htm?category=

Categories

Resources