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
491 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 48

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 500 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
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…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

679 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