Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Help required Alternative way to export to Excel from a datatable without the MS-office Excel installed on the server

Posted on 2013-05-29
3
Medium Priority
?
546 Views
Last Modified: 2013-06-01
HI All,
One of my requirement was to create a automated job which needs to be placed in the scheduled task of the Server.

I have written the code on Windows Form Load job performs below activities.
1. Calls a 2 stored procedure (MS-SQL)
2. Stores data in couple of  datatables
3. This 2 datatables are passed to function which exports to excel and stores in a path.

I have used  "using Excel = Microsoft.Office.Interop.Excel"
Excel.Application xlApp ;
Excel.Workbook xlWorkBook;
Excel.Worksheet xlWorkSheet1;
Excel.Worksheet xlWorkSheet2;

Where I am storing the output in a workbook with 2 sheets (2 tabs). I have also used some of the Excel features like.
xlWorkSheet1.Cells.Columns.AutoFit();
xlWorkSheet1.Name = "Completed_Projects";

Now everything is working as expected in my local system. When I ran the exe on test server I found that MS-Office Excel needs to be installed on the server to use this Excel object features.

Server Team are not ready to install the MS-Office on server nature of Office it presents additional attack vectors that potentially risk their security and Office may exhibit unstable behavior and/or deadlock when Office is run in server environment.

Could someone let me know alternative way used Export to Excel (with datatable\datagridview as source) and save in particular path?

I need to have features like Auto Alignment of column width, able to store two worksheet in single workbook, name the worksheet.
0
Comment
Question by:anbu210
3 Comments
 
LVL 49

Expert Comment

by:PortletPaul
ID: 39206615
mmmmmm
not sure if this will be appropriate for you, but perhaps look at www.aspose.com (aspose.cells in particular) they have libraries for .net and java that provide server based capabilities that might do what you need.

I haven't used their excel libraries but have used their word library (with java) and it worked for me extremely well on both windows and linux servers - but my needs were very different to what you describe here.
0
 
LVL 44

Accepted Solution

by:
Rainer Jeschor earned 2000 total points
ID: 39207165
Hi,
there are various options - either commercial ones (with less coding) or free ones (with more coding).
As PortletPaul mentioned, Aspose is one of the best in regards to commercial solutions, alternatives are (not a complete list ;-) )
http://www.spreadsheetgear.com/products/spreadsheetgear.net.aspx
http://www.infragistics.com/products/aspnet/excel-exporter/
http://www.componentone.com/SuperProducts/SpreadWin/

For free you can use the Office XML SDK (ONLY FOR XSLX format!!!)
http://msdn.microsoft.com/en-us/library/office/hh180830%28v=office.14%29.aspx

Sample:
http://stackoverflow.com/questions/11811143/export-datatable-to-excel-with-open-xml-sdk-in-c-sharp

HTH
Rainer
0
 

Author Closing Comment

by:anbu210
ID: 39212801
Thanks Rainer!!  giving me an idea of OpenXML . I found a nice article at below link I was able to use it without having Office Excel installed on Server.

http://www.mikesknowledgebase.com/pages/CSharp/ExportToExcel.htm
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Integration Management Part 2

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question