ASP.NET and OpenXML - Create formatted/styled xlsx file - Best Solution? - c#

This question might be more subjective, but I'm hoping someone with more experience can guide me in the right direction.
I'm brand new to web development, but have been coding C# for a couple years. My job wants me to convert an existing app we have to SharePoint 2013 and part of the app generates an excel report with custom formats and styling. In the original app we used Interop, but apparently since it's 32bit and our server is 64bit, Interop won't work. I thought about just doing a csv, but our customer is adamant about keeping the styling so I found OpenXML.
I don't have any experience with OpenXML, but I saw the tool can convert files into code. I loaded our template into the tool and it generated about 2000 lines of code which seems very excessive. Using Interop it's a fraction of the length and seems much easier to read. I'm tempted to just copy all the code over and stick it in a region (which I know most developers hate and I agree looks bad) and put a note at the top saying that if the template ever changes to just redo that region with the new one.
Is that my best option or is there a better alternative? Unfortunately our dev network is pretty closed off (it's a pain to get approval on third party non Microsoft stuff) so I'm limited on third party libraries I can add as well. If there's an option without doing that, that'd be preferred.

If you have one or more templates, just use OpenXML to create a new workbook from a template for each request. And then use code to enter values into named ranges, datasets into rows, etc.
BTW—ClosedXML makes simple and medium things a lot easier.

Related

What is the most straightforward way of modifying PDF start-up options via C#?

I'd like to know what would be the most straightforward (i.e., preferably without adding DLLs to my solution) way to write a C# code snippet for modifying a PDF document's page layout and magnification options.
I know this is incredibly easy in LaTeX (well, it's easy to set these for a PDF to-be-generated using a single package) through hyperref options.
Modifying an already-created PDF document is a lot more work however. Also, most MS Office print-to-PDF options don't seem to include this ability while it's obviously annoying to keep opening documents up in Acrobat and manually modifying these for the proper (desired) opening settings (layout: single page, and magnification: fit page, for me).
So, I would like to write a code snippet that could do this. What is the most straightforward way of modifying PDF start-up options via C#?
Alternatively, is there a way to force-apply these options when generating PDFs from MS Office software suites?
I looked into PDFSharp and MigraDoc at one point for PDF-making from C#, but that really didn't match what I was hoping for. Plus, it added a DLL set (of ten dependencies) which was sub-optimal with respect to how many ancillary files were included with the build for managing a relatively simple function.
However, as noted in the comments, such a batch modification code is likely to be very difficult without any dependencies, so I'll also accept answers which reference dependencies.
Past topics (but not very good matches):
This is similar but for JavaScript, and actually suggests it shouldn't be done.
This is a bit more elaborate for JavaScript, but not exactly what I am looking for.
This topic seems to be this question for PHP but including some external references...

Best method for generating documents/reports in visual studio

I’m looking at options to send user input data from my application (mainly strings and doubles) into a stylised document (such as a quotation or invoice)
I have done quite a bit of research however am even more confused in which method would suit me best, so am looking for some input, as which direction to go, I have found some of the following options:
Crystal Reports - although I think this is more for reporting data from SQL databases, not to mention it looks as though people struggle with running there applications in different environments on different machines.
MajorSilence Reporting (formerly FyiReporting) - a Crystal Report alternative that’s open source so would alleviate a lot of problems again though I think it’s for databases and hasn’t been worked on since2015
Word Or Excel Document - Seems I would have to have a template file of some sort and I did want to control as much as I could in program not to mention it just seems kind of unprofessional in a way when used by other users at my work.
PrintForm - where I print direct from a form in the application while hiding the buttons but this may be hard to do over two pages.
If anyone has any input on the above or new ideas or even if I’m on the correct track to how this is usually done, I would be very appreciative.

Charting tool that generate on memory

My question seems confusing but I'll let you explain it more clearly. Me and my team we're currently developing a complex report that comprises of words, tables and charts. As of now we generate this report by using a word document template and filling it up with the model we have. As for chart this is where it becomes complicated, we have two application that we're using in business one is a windows/wpf application and a web application. Both application uses the same engine we have for generating chart (ComponentOne) but the engine itself is only compatible for windows application. We use the assembly we generate from windows/wpf application on our web application for us to generate a report.
Our report generator on website will only have filter and parameters on what kind of report they want to generate and on a press of button. What do you think will be the best to tackle this issue so that we can drop using the assembly we have. We don't like to drop using template for this as these greatly help us on maintaining the report when changes is required the only thing that we think right now on how can we generate a chart on memory and convert it into an image so that we can dump it on our template.
It's not confusing, it's just not clear at all. If I get it right you just have a reporting tools ComponentOne that make reports on software side and it's not adapated for web side.
You somewhat tried to tackle it by using software dll in your website and it doesn't work as well as you expected/wanted. And you keep trying as of now.
Your question is basicly "How can I use a dll designed for software into a website?"
And the answer is simple. It's case by case when not outright impossible.
I invite you to look for another solution than using a software designed dll on a website. Even your idea of putting it inside an image is somewhat bad (lose of all controllers / defeat of the purpose of an interactive report.)
I'm pretty sure that ComponentOne would have think of such a problem as web reports and maybe even a solution to link web reports to soft reports. With a little search, I found a C1WebReport and even found some forums talking about C1Report to C1WebReport. Does it answer your problem?

Automatically convert a MindMap to another app (e.g. MS Project)

Here is the situation:
We ran a brainstorming session to find all the tasks we will have to achieve for our project
Now, I want to create a Gantt Planning (for instance) with all these tasks
We already built a MindMap with Xmind (I sometimes use Freemind too, or I could also export the Xmind to a Freemind format).
I would like to create a Gantt Planning in Microsoft Project (this is what we mainly use here).
My questions are:
Has anyone of you ever tried to automate the creation of a Gantt from the MindMap (using each level of the MindMap as Title and each leaf as Tasks)?
Would it be possible with VBA? Or C#? I didn't find much API to Xmind of Freemind, did I miss something?
If you can convert your mind map to Freemind, there is some documentation on the Freemind site which provides a couple of approaches to reformatting the Freemind file as an XML file which MS Project can read.
I maintain MPXJ, a library which can be used to read and write file formats which MS Project works with. I felt sure that someone had already written an add-on for Freemind which allowed you to export mind maps as a project plan using MPXJ... however I can't find a reference to it any more! If you don't mind a bit of coding (in Java, or any of the .Net languages) it wouldn't be too hard to achieve what you want using MPXJ.
Jon
We're doing exactly that with STOIC.

Editing Microsoft Word Documents Programmatically

I want to know if this could be done.
I am building a data dictionary for our software system (school project), and I'm thinking of an automated way to do this. Basically I don't use much of Microsoft Word (2007), I only use it in documenting schools stuff, etc. I want to know if its possible to create/edit a Word document programmatically from a template.
The idea is, I will create a page on Word that contains an empty form that will be repeated on every page. For every data that I will input to my program, it will update the corresponding field in the form and skips to the next form.
The purpose of this, is to eliminate copy-paste methods (my habit) and to speed things up when doing the documentation.
Word automation, as suggested by others, will lead you to a world of hurt for two major reasons:
Office is not intended to be run unattended, so it can pop up message boxes at any time, and
It is (probably) not licensed to enable office functionality for computers which don't have it. If you generate a Word document on a web site using automation, you have to make sure that this functionality cannot be reached by computers which don't have office installed (unless they changed this rule in the last years).
I have used Aspose.Words, it costs a little, but it works well and is intended for this.
Not exactly sure what you really want, but creating word documents with c# shouldn't be any problem:
http://support.microsoft.com/kb/316384
If i find out your purpose correctly you need to visit this microsoft msdn link
Manipulating Word 2007 Files with OpenXML
Definitely possible. A fairly easy way of doing it using Office Automation. See this KB article for a basic sample: How to automate Microsoft Word to create a new document by using Visual C#
I think the main difference to that sample will be that you'll open your template and do SaveAs instead of creating a new document, but I can't remember exactly.
However, depending on your exact requirements, there might be better alternatives. For example, it's not recommended to do Office Automation on servers (including on webservers), so if that's needed you might want to look at something else.
You can use com interop of .net framework.
Understanding the Word Object Model from a .NET Developer's Perspective
Building COM Objects in C#
Using COM programming is not the best way as mentioned by erikkallen, I suggest using OPEN XML. It is really easy to use and your document generation operation will be very fast.
http://blog.goyello.com/2009/08/21/how-to-generate-open-xml-file-in-c-in-4-minutes/
http://msdn.microsoft.com/en-us/library/aa338205(v=office.12).aspx

Categories