I have an Excel file with a formatted table. Right now I have a database in sql server, I'm pulling the data into my c# asp.net program. I want to know if anyone has an idea of what I should try to use that Excel format to display data from a query at a webpage without having to go in and construct the table from scratch. I tried looking for a good tutorial on how to import an excel file and use it as a template for crystal reports, had no luck. Any advice would be greatly appreciated!
I have used a third party component called ASPOSE.NET to acheive this. ASPOSE provides extensive formatting options and support a wide variety of file formats.
However it is not a free product.
Related
I have an application that is written using C# with ASP.NET MVC framework.
My application has lots of reports, some are data dumps and other are summary with subtotal and grand totals... The Summary report looks like Excel Pivot table
Currently, I am using jQuery TableExport package to allow me to export the html report into Excel. This works, but it will export with no style.
So I wrote my own plugin that would export the HTML table with style by converting the css classes into inline-style which works.
The problem with client side export is that it is slow and takes up too much resources. If there are a large data dump, the browser may crash or the user may have to change the browser setting to allow them to export such large reports.
Question
What are other ways that I can use to export my with ASP.NET MVC application? I don't really want to export the report each time as in many cases the user only want to view the report. But I need to offer both functions in the case the export is needed. Is there a package the solve the reporting problems?
Thank you for your help
My customer gave me some Word and Powerpoint documents which specify how certain 'reports' generated by our product are supposed to look like.
That means, I need to modify those documents (replace placeholders etc.) and then I need to export them as PDF.
How would you solve this problem in C# ?
TL;DR: Editing the office document is no problem at all, but exporting that document to PDF (using Interop) allegedly causes issues when running it as a web server application. That's the whole problem here.
I agree that Interop is not suitable for document manipulation in server environment. I would approach this problem by preparing MS Word template documents with placeholders for data. Then I would use c# to load the data for the reports and merge the data with templates to get final documents (docx, pdf, xps or various image formats). There are 3rd party toolkits which make it quite easy. Here is the code used by one such toolkit needed for merging xml data with the template to get a pdf document:
XElement customers = XElement.Load("Customers.xml");
DocumentGenerator dg = new DocumentGenerator(customers);
DocumentGenerationResult result = dg.GenerateDocument("MyTemplate.docx", "MyReport.pdf");
You can of course also use free libraries and SDKs based on OpenXML but you should expect a steep learning curve, lots of debugging and lots of time invested.
Wkthmltopdf might be an option.
A completely different "report approach" could be, to save those office documents with the placeholders as mht (That's MHTML a web archive format). This could be done directly in MS Office or even programatically.
The placeholders could be easily exchanged by string search and replace. The mht files could directly be used to show the report instead of the PDF. A clear disadvantage of the mht format, is the HTML formatting. With PDF you have a clear and fix positioning.
We are using this kind of report creation. There are some flaws, but it works and the customer could edit the mht templates directly by right-click Open-With the prefered MS Office flavor.
You can use report generators, like FastReport.Net for solving your problems. It can assign different data for placeholders and also allow export to PDF.
I was hoping for a good point in the correct direction, as this is something I have never done, and googling is getting me tied in knots.
I want to create a word document (docx) from C# on a ASP.NET MVC application.
Populating a template with something like mail merge would be great.
I have spent day googling this and keep finding archived documentation.
The following examples are from 2012
https://msdn.microsoft.com/en-us/library/office/bb491088.aspx
Because you will generate documents on the server you should avoid Interop for document manipulation. You can use free libraries and SDKs based on OpenXML but this is difficult to learn and error prone.
It probably makes sense to choose one among 3rd party toolkits to get the job done quick and easy. Start by preparing MS Word template documents with placeholders for data. Then you can use c# to load the data for the reports and merge the data with templates to get final documents (docx, pdf, xps or image formats). Here is the code used by one such toolkit needed for merging data from the database with the template to get a pdf document:
IEnumerable<Customer> customers = DataAccess.GetCustomerById(15);
DocumentGenerator dg = new DocumentGenerator(customers);
DocumentGenerationResult result = dg.GenerateDocument("MyTemplate.docx", "MyReport.pdf");
You can also see these examples for more information.
Maybe Templater can be of help..
This is small library you can use to create word document on ASP.NET looking like mail merge...
Try demo http://templater.info/demo
I need to make the information in the database usable by allowing the user to download it as a PDF or Excel spreadsheet (either one works, both is perfect).
I've looked around at a bunch of options, but I really can't decide which one I should use, let alone if any of those options are actually useful. Most of the options I've found revolve around converting already existing HTML files into PDFs which is not what I need. Also, it needs to be free. My bosses haven't given me a budget to spend on this
I'm not sure what other information I should include here.
Well, any help is greatly appreciated. If you have questions about missing information, I'll get it posted ASAP. I'm here all day, so I'll be able to respond to any comments very quickly.
EDIT: Oh wow! Huge thanks, guys, for the massive response! I got a ton of ideas. This is super-helpful. Thanks!
if you want to generate an Excel (or also a Word) you can use openXml. You can create a new document exactly the way you want from pure code.
OpenXml SDK page
The solution I usually propose to my clients in this situation is to use Sql Server Reporting Services (SSRS). You can use the ReportViewer control included with it in order to generate PDF's, Excel spreadsheets, XML files, CSV files, and others. If you need ad hoc reporting, there is a Report Builder available as well.
Barring that, you can use OpenXml to generate Excel spreadsheets and there are a host of PDF toolkits available.
Have you looked into the reportviewer control, which is part of Visual Studio?
It allows you to export the report in PDF or Excel format.
http://www.carlosag.net/tools/excelxmlwriter/sample
check this might be useful for you
There are lots of reporting solutions out there such as SQL Server Reporting Services(for which you might already have a license). Take a look at Reporting (free || open source) Alternatives to Crystal Reports in Winforms which can likely be applied to the web with a bit of serialization.
I would suggest thinking about rolling your own depending on the situation. You could use pdfsharp for the pdf export and EPPlus for excel. They are both very easy to use and, I'm pretty sure, available in nuget with a couple of clicks.
If you want to go the Excel route, i'd recommend this article from Stephen Walther entitled ASP.NET MVC Tip #2 - Create a custom Action Result that returns Microsoft Excel Documents. This uses an old trick of writing an HTML document with an Excel mime type. This is different than streaming a native Excel file. And it's fairly easy to change the to rendering a CSV file if you want to strip it down, and make it a more universal file. Just remember to double-quote all the fields if there's a possibility of commas showing up.
If what your doing isn't too complicated you can use CSV files. CSV stands for comma separated values, and it is what it sounds like. You can create simple tables and columns using commas. For example paste the following lines into a text file:
heading1,heading2,heading3
info1,info2,info3
info1,info2,info3
Save the text file as a .csv file and voila - an excel spreadsheet. Obviously it is extremely easy to build these looping object collections. Mind you if you need any complicated text formatting etc then it is not really the best option.
I want to export my data from grid view to the excel. Unfortunately i came to know that there is no excel software on server side. Is there any way that i can still export data in excel format without having excel software on server side.
Thanks.
you can create a CSV format text file, which excel can understand.
This question also outlines some other options you might be able to use, with pros and cons of both.
This must be one of the most asked questions on Stackoverflow.
See Create Excel (.XLS and .XLSX) file from C# For lots of suggestions and a whole list of linked questions.
One trick you can use it to export the html table to the client with the extension of .xls. When the user opens the document with Excel and resaves it will become a real excel document. The fun part is it will retain most of the formatting from the HTML view. This works with HTML/TABLES, I'm not sure about DIV/SPAN/CSS.