Best Way to generate excel report - c#

Actually I'm asking this question because I want to know what is best solution for this base on what I only have. First let me show you what I really want to achieve. My boss want me to generate report in excel file (.xls or xlxs) then inside this report compose of multiple sheets with each respective sheet name. Data are presented in nice and professional way and sometime there are graphs inside that are link with the data within the sheet and it looks like this:
Below is what I only have to generate this output.
Visual Studio 2008
Sql Server 2008 (no SSRS)
Report is generated via
RDLC (naming of sheet is not possible for this but multiple sheet is
doable via pagebreak)
I try to update excel file via Sql Server but
seem too complicated for this specially when dealing with Total
fields.
I have not yet tried to render graph on .rdlc

It sounds like the data lives in SQL server. If you have access to it, why not create an ODBC connection and use this to pull raw data into each one of the sheets you need, and then configure a dashboard tab that automatically pulls data from those sheets (even if you refresh it) and shows the graphs and summary tables in the format that you want?

Related

Excel data connection to API

I have an Excel client and an API and both are under my control. What I want to achieve is a data connection in Excel that can be refreshed by the end user by the click of a button instead of downloading xml/csv/xls files. The benefit would be that the user can have extensive custom charts that don't need to be rebuilt every time a new data set is used, e.g. weekly pivot reports etc.
That is pretty straight forward when using single tenant SQL Server or Access as a data source, however the requirements are a bit different here:
The data has to come through the API as data transformations have to be done.
The user should authenticate with every refresh (i.e. basic auth).
Support for Excel 2010
Data connection "From Web" seems like a good candidate, however this only works with html tables as far as I can tell. OData connections seem to be only offered with Power Query and the Professional Plus packages.
Does it make sense to go down the "From Web" connections route and convert thousands of rows of xml to html or are there other options?
UPDATE
I ended up creating an html table manually which is backwards compatible to Excel 2003 and does not require client-side VBA.
Please check below link it may be help you
http://interoperating.info/courses/perl4data/node/26
http://www.codeproject.com/Tips/463096/Converting-a-datatable-to-CSV-XML-and-HTML-by-usin
You can use ExcelDNA to create an addin that will let the user manipulate (get/set) the data from an Excel sheet, with a C# addin in the background to communicate with the API's XML. The addin works like an advanced VBA addin and can be activated via a button.

Writing to an Excel file from SQL Server Database

Currently, I need to be able to retrieve values from an SQL Server DB, populate an Excel file according to a certain template, and then allow the user to download the file. I also need this this certain template to be customizable, in the sense that the user can add new fields, and remove fields.
I understand that there are a couple of approaches I can take: using .xlt, and using C# directly. With C#, the user will need to interact with a UI, which will then populate a ExcelTemplate table in the SQL Server. This ExcelTemplate table will then be used when the user wishes to download a new Excel file.
I know all this stuff may sound kinda abstract, so please do tell me if there are some places I need to elaborate/clarify. Thanks a bunch, man.
EDIT: Sorry, I kinda missed this part out, but I'd prefer to allow the user to customize these Excel templates via a Silverlight UI.
You can create Data Sources in Excel and pull the data from MS SQL Server.
You can use MS Reporting Services which allow to get reports in MS Excel format. In this case users can use Report Builder to customize the reports.
For pulling down data from SQL Server and dumping it into Excel, you can use Officewriter. It has Reporting Services integration and supports generating .xls and .xlsx documents. There's also a template component that basically does what you're trying to do. The templates are actually Excel documents, so the users can edit them directly in Excel. Not Silverlight, but not bad. You can try an eval for free.
DISCLAIMER: I'm one of the engineers who built the latest version.
at the end of the day I think I'm gonna spend some time building a customized dashboard. It won't be generic, but rather focused on the existing database.
I know this answer is kinda vague and all, but I'd like to say thanks for all the help :) it'd be great if there are dynamic solutions for this in the future! I think...

exporting data from excel to MS Sql

I have saved the specifications of a mobile phone into an Excel spreadsheet. Now I want to copy the data from this Excel sheet into a database programmatically.
How can I do this? Is there any way? I copied the phone specs from gsmarena.com. Please help me.
It's completely possible. There are several ways, not all of which require programming.
If the Excel sheet is in a tabular format (one "record" per row, with static column names), you may be able to use your database management tool (MS Sql Management Studio for Sql Server, for instance) to do a "bulk insert". Consult the documentation for your particular database.
You can also use Excel formulas to create a column in the Excel sheet that contains "Insert" statements that will insert each row into the DB. You simply copy that column out of the sheet and paste it into a SQL command parser, maybe wrap it in a transaction, and then hit "execute". I've done this a few times when doing data migration; it's kind of a one-off, but for a one-time operation that's just fine.
If you want to use a program to solve the problem, you'll need to use OLE automation to open your Excel sheet, and programatically iterate over the rows and columns to create a "record" that you save to the database. The exact wheres and hows are a little in-depth, and depend a lot on the type of database, your version of Excel, the type of Excel document you have (XLS or XLSX), and how your Excel sheet is organized.
Well for starters, is the database properly designed and ready to go? If not, you need to first design one, which I suggest you base on normalizing the Excel data. Once that's complete, you can use the interop libraries for .NET to pull the data from Excel and write to the DB through MySQL, Access or some other DBMS.
You could use a tool such as SSIS, or connect via ADO.Net and OleDb/Jet drivers.

How to import the data from an Excel spreadsheet so it can be manipulated in C#

I have an excel spread sheet (well, hundreds of them) which I need importing into a database.
If the excel data was in a nice uniform format I would simply save them out to CSV, read them in using something like LINQ to CSV and save the required data away.
However, the excel spread sheet is 'uneven' in that different groups of cells contain different data.
I need a way of grabbing the data and then working with cell references to grab the bits I need and save them to the database.
What's the best way to achieve this?
Thanks
UPDATE some more information
I have numerous spread sheets, all identical in structure that need to be imported into a database. The import is not simple in that different chunks of data from the spread sheet will go into different tables. The excel document itself contains a few sections (basically question / answer) type data. For each different section I need to grab the data, shape it into a form that makes sense in terms of the database and save it.
Ideally I would like to create a quick little WPF app that will let me select a spread sheet hit a button and perform the import.
You could use the Excel Object Model to read the data if you do it in a non web environment.
See for example How to automate Microsoft Excel from Microsoft Visual C#.NET.
If it has to be inside a web application. I suggest to use Aspose Cells.
Turn the Excel Spread sheet into an ODBC (Open Database Connectivity) Data Source so you can access it just like you would any database:
http://www.datamystic.com/datapipe/excel_odbc.html
Then access it just like any database using ODBC:
http://msdn.microsoft.com/en-us/library/system.data.odbc.odbcconnection(v=vs.71).aspx
When the data is not uniform, it is often better to keep your approach as simple as possible in the first instance. Start with vba and the "Range" object (which is part of the excel object heirarchy). From there you can increase the level of automation and in most instances reuse this "Range" work.
avariable = Range("A2:A5")
That notiation is not going to change very much. It wont matter what final target language you use (language: C# / vba / etc).
There are a number of other ways of going about this -- java based / xml based / c# based / and a few other really cool ones that only apply to certain niche situations. If you can provide more information about your use case, then perhaps I can suggest some more things to try.
Q & A
example link for automation from C#: http://support.microsoft.com/kb/302084
You should probably take a look at Microsoft's Visual Studio Tools For Office (VSTO), which handles a lot of the unpleasant COM/interop stuff for you.
To those who may be interested I ended up using LinqToExcel:
http://code.google.com/p/linqtoexcel/
Did exactly what I was after with minimal fuss. Excellent

Programmatically generating Excel workbook with pivots and charts

I need to create a workbook which has a raw data on a sheet and a pivot table on another sheet. The pivot is created from the raw data. Then I need to create a chart with this pivot on the same or new sheet.
How can I do this in C# - and is this possible using VSTO?
Easiest way to do it?
Use Open XML SDK 2.0
Build a pre-generated version of the workbook with raw data, pivottable and pivotchart already created.
Install the OpenXML SDK 2.0 setup package
Use the OpenXML SDK 2.0 productivity tool from this install to open the workbook
Select the root element on the left hand pane, and then right click and select Reflect Code
Done - on the left pane is a complete C# class with the necessary code to generate the file.
Well not quite done as you still need to refactor the code to take into account dynamically adding the required data content, however this will get you 97% of the way if you already know C# fairly well.
I've done something similar to this before, but I didn't do it using C#. I used VBA since the language is already built in to Excel.
My approach was this:
Create a worksheet called "RAW DATA." This worksheet has a QueryTable object in it that can be updated via code in VBA.
I manually created a pivot table based on the QueryTable in the RAW DATA worksheet.
I then added code in VBA so that after RAW DATA was updated, Pivot Table was refreshed with the new data.
This method works really well if the layout of your raw data and your pivot table stays the same. I have a workbook that I made for a cowork that updates multiple sheets with pivot tables based on one set of data. She really likes it because just by clicking one button, she has a refreshed view of all of her data.
If this approach works for you and you'd like more details as to how to implement some of those methods, let me know more details of your situation and I can try to help you out.
One option is to connect to database from Excel and refresh the "Raw data" sheet, via VBA or defining an SQL query in Pivot data source. This is not so great as the user who opens the file must be able to connect to the database.
The other option is to fill the "Raw data" sheet programatically via C#. There are numerous libraries that can help you with that, even some free ones, but you can also do it yourself by using the Excel XML format (SpreadsheetML). You can use the Excel 2003 XML format or the new Open XML Excel format. The latter is far more complicated, but with it you can also take advantage of the OpenXML SDK and the Excel Package API.

Categories

Resources