Is It Possible word automation in Openoffice - c#

I have code in C# for word automation in MS-office.But I want word automation in openoffice using C#. so Is it possible through openoffice? I want to read ,write and saveAs .doc file programatically in openoffice using C#
Thanks in advance

Short answer no,
Word is not part of Open Office, so how would that work?
You can however automate Writer but, it has a different model so much of you code would have to be re-written.
If Open Office were to expose a compatible API I think that would raise some interesting Copyright and Intellectual Property issues but, I'm no lawyer. However, I'm not extolling the benefits of either product or API, they are just different.

It's possible. You must setup. OpenOffice, OpenOffice SDK, when the SDK is installed, you must run setsdkenv_windows.bat in the SDK folder, then it will require another components, you must install just 3 or 4 from here http://gnuwin32.sourceforge.net/packages.html.
The sample for CALC could be in a path like C:\Program Files\OpenOffice.org 3\Basis\sdk\examples\CLI\CSharp\Spreadsheet
The samples for Writer are just online, just now I need the samples for Impress, but the automation with the automation for CALC is 10/10

Related

How Print MS Office document without office installed

My C# Windows application needs to print office documents silently(without popup dialog or open up applications such as Word, Excel ). So I'm trying to find a way to print office documents without office (Otherwise user needs to buy office package also to use my application).
I tried with Aspose.NET but It seems some parts of the documents(such as notes, comments) are getting ignored by this component.
I've also tried to go through Microsoft Office 2010: Primary Interop Assemblies Redistributable. But, as I found to use MS office PIAs, MS office needs to be install in the target computer.
Any ideas where should I look into?
First you should understand, that MSOffice uses a proprietary format, that event he best open-source office software is having problems reading without screwing something up.
My suggestion is - you either take something that does a minimal amount of damage, or require office. One suggestion would be: Microsoft used to make "word reader" and "excel reader", try to see if they are still being released.
Another idea would be to find a free office-to-pdf or office-to-xps conversion software, include it with your program and print.
The most difficult way, in my oppinion, would be to feed the document to some online service, for example skydrive's document reader, and request it to print the file.
Depending on the application, your best bet might be saving the content to Open XML and parsing it (beware there's a lot of bloat in larger documents saved in that format per my experience) or simply saving to PDF.
Another clunkier, but more standalone possibility is to use control.click and such to build an automated clicker that opens content in an external freeware application and prints it. The most compelling option is Microsoft's "Viewer" applications (when available). When that is unavailable for a particular document type, Microsoft suggests OneDrive as a freeware alternative (requires account, internet connection).
Word -- "Viewer" has been retired, look for legacy version or use OneDrive
Excel -- "Viewer" is available
Powerpoint -- "Viewer" is available
If you don't want to use a third party application, that could give you a creative, if clunky route to accomplishing your posted goal. Good luck!

How to generate report in word 2010 using c# , dot net, word templates, xml [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
We have a database application that stores data that we want to report in Microsoft Word.
Suppose all information of my customers is stored on a database system and I am now requested to create hundreds of word letters, reports that will be sent to my customers. These letters have the same content but different customer name, customer address, etc.
I want to make use of Office Word 2010 by creating document template with content controls using c# and .Net, sql as database to replace the content of this template.
I've been looking for articles on automating Word 2010 in C# and dot net and sql. Could someone give me a push in the right direction?
You can use Interop.Word in your program, but keep in mind that the available documentation is very scarce. I managed to develop my application looking at examples like this one from C-SharpCorner or this one from WindowsDevCenter. Even if the examples are old, you can get the main idea and get familiar with the syntax, and write your program afterwards with an updated version of Interop.Word (which has a slightly simpler syntax).
In your case, you should create a neat Word template, with bookmarks located in the places of your document where you will insert the customer information. Then you can open the template from your program and navigate it using those bookmarks, as you insert the information retrieved from your database.
There are other interesting alternatives to Interop.Word that you could try if you don't want to go too deep into Word automation, such as DocX (which doesn't even require Microsoft Word or Office to be installed) or Open XML (to generate .docx files).
I've used the Office.Interop assemblies in the past for this kind of functionality but this method carries a few distinct disadvantages:
Word must be installed on the machine where the code is running
The Interop assemblies actually start up Word in the background, so you have to be careful to dispose of everything properly and handle errors, otherwise you'll end up with Word processes wasting CPU/Memory on the host server
The APIs are not very pleasant to work with and documentation is somewhat scarce
I've also played with DocX and Open XML, both of which have their merits but tend to be slightly limited by comparison with Interop. My advice would be to attempt the functionality using DocX or Open XML and only fall back to Interop if you can't achieve the functionality any other way. There should be plenty of tutorials online for all three APIs.
Microsoft recommends OpenXml for any application running in a server process, and this approach would probably be one of the best for reducing dependencies (as others have mentioned). Here are some links to get you started:
Download OpenXml SDK 2.0: http://www.microsoft.com/en-au/download/details.aspx?id=5124
Useful Tutorials: http://msdn.microsoft.com/en-us/library/ff478255.aspx
So for start DO NOT USE INTEROP, i've been using it for the last 4 years, and i have to tell u it's not a good idea (it's really lost, and u'll hit lots of problems. It's actually written on Microsoft's site that you shouldn't use it for server side generation.
You should use the OpenXML SDK, i've actually just started using it but i have to say that even if it seems a bit harder to use, it's definetly a lot faster that using interop and the best thing is that know i don't need any programs from the Office suite to be installed on my pc, the downside is that i can't export to PDF or XPS anymore without a 3rd party library
You can find the sdk here
http://www.microsoft.com/en-us/download/details.aspx?id=30425
I suggest downloading the tool as well it's pretty useful.
This is a good tutorial to start with it really helped me a lot.
http://msdn.microsoft.com/en-us/library/office/bb448854.aspx
And u can also use the API documentation from the Productivity Tool which is on the same site as the sdk
I agree with others that the OpenXML SDK is a good way to go for the same reasons. I am in the midst of creating a similar kind of report generation as you are. The reports I need to generate unfortunately are very dynamic not only with data but with the layout.
If your layout does not need to change then I would strongly suggest using the SDK Tool, it lets you take any word document and generate the c# code for you to recreate the same exact doc. From that point all you have to do is replace the text with the data you want in the code.
You could make a generic report in word, get the code with the tool, then just do a search for the placeholder text in the code and replace that string with a variable. its as easy as text1.text = reportData;
I also find the SDK Tool a great way to learn the code, you can compare two files side by side and see how they differ in the code.
Your answer is OpenXML SDK.
goto Open XML SDK 2.5 for Microsoft Office
download OpenXMLSDKV25 and OpenXMLSDKToolV25
install sdk and productivity tool
open word and create your template document
open Open XML SDK Productivity Tool
open word document
right click on document name from Document Explorer and select reflect code
copy all generated code to your project
find and edit "Paragraph" or "Run" that you want replace with your data
I have used both interop and syncfusion to create reports (although I was generating an excel report but both technologies can be used to generate word reports also). My feedback :-
Although interop is included in most computers which have visual studio (not sure about non visual studio computers), usage of interop requires the presence of compatible microsoft excel also on the computer generating the report whereas syncfusion does not requires the presence of microsoft excel on the same computer.
If you plan to use asp.net, then interop is not supported (atleast it was not when I worked) whereas syncfusion is supported.
Link for syncfusion :-
http://www.syncfusion.com/products/aspnet/docio
Summary :- If you are developing a console application and server(where the application will be deployed) has microsoft office installed, then interop might be a good idea. Otherwise, you can have a look at syncfusion also.
You can usee Free .NET Word API to generate report in word 97 ~ 2010 using c#.
//Create word document
Document document = new Document();
document.LoadFromFile(#"..\..\..\..\..\..\Data\Fax.doc");
string[] filedNames = new string[]{"Contact Name","Fax","Date"};
string[] filedValues = new string[]{"John Smith","+1 (69) 123456",System.DateTime.Now.Date.ToString()};
document.MailMerge.Execute(filedNames, filedValues);
//Save doc file.
document.SaveToFile("Sample.doc", FileFormat.Doc);

Read content of Word file in C# without using Word Application

I"m looking to read the contents of a Word file on an application running on a webserver - without having word installed. Does a native .net solution for this exist?
Aspose makes a paid solution for doing just about anything with any Office format:
http://www.aspose.com/categories/.net-components/aspose.words-for-.net/default.aspx
There are commercial options too, but that's what OpenXML is all about as long as you are dealing with docx files only. If you need doc files, you will probably need to purchase Aspose's Aspose.Words for .NET.
i have used several SDK, for now, the best is Aspose.words, the openxml sdk 2.5 is also a nice choice, but the api is too low, so if you use openxml sdk that means will be writing more code, and remenber user openxml sdk tool together, it is a nice tool can make coding simple.
you can look this video for a overview:
how to use openxml sdk tool
another choice: GemBox.Document, a commercial option, cheaper than aspose.words.

How to read a word 2003 document without COM in csharp?

Hey all, I need to read many word docs in server.
But you know,the component in .net is based on COM,it would work reliably if I use it.
It is so sick.You know, in word 2007,because of the xml file,there are many ways to read.
I wanna find a open source way to read word 2003,Thanks.
I'd suggest that you use the NPOI library to read .doc files: http://npoi.codeplex.com/
The library is the .NET version of the POI Java project and licensed under the Apache License.

Reading a Excel 2007 Spreadsheet in C#

I've done some googling and there seems to be a plethora of tools for reading excel 2007 spreadsheets using c#. I'd like to know which one performs best and is easy to use.
Frankly, it depends on if you have Excel installed on the machine.
If you have Excel installed, using Microsofts Office APIs is as quick and ( for the price ) painless as you are going to get. That said, if you don't have Excel installed, the question gets much trickier.
Also, note, if you are installing to a web server that is available to the world, using Microsoft's Office APIs often isn't actually legal, as the end user needs to have an office license for you to be legal. If this is the case, and you are developing for redistribution or internet deployment, make sure that the library you are considering has no dependencies on the Office APIs, as their redistribution isn't actually legal either. If you need to, for example, provide a viewer for people that don't have Excel installed, you can't legally use the Office APIs, nor can you use 3rd Parties that depend on that layer. Compliant libraries will make it clear in their description that they don't depend on Excel.
It depends what you're trying to do with the spreadsheet.
If you want to read tabular data, OleDB is the best option.
If you want to read formatting or specific cells, you should use a third-party component. (I can't recommend a specific vendor)
You should avoid using Excel's COM object model unless you want to interact with an open window or print a spreadsheet.
I've had pretty good results with Koogra.
Check the Open XML SDK. It includes a "Productivity Tool" that lets you walk through the structure of a document to help write your code as well.
I looked into the Open XML Format SDK about a year ago and it seemed like a good alternative that does not require Office installed.
I have used GemBox and the Microsoft Office APIs to read in spreadsheets. I have had success with both options but I tend to like GemBox a bit more. It is fast and simple to implement but comes with a price tag.

Categories

Resources