0

I would like to know if it is a good idea to create an excel file using c# in sharepoint?

I've tried to find js libraries but despite ExcelBuilder which seems really complicated to use i can't find anything else. And ActiveX Object work only on IE. So i'm asking myself if i can make Excel files on server side using c# and then send it to the user. I've also found some other solution but i would also put pictures in my excel file and i haven't found solution to that with js so i would like use c#.

Thanks in advance.

3
  • What do you want to do with the Excel file? As in how complicated will the resulting Excel file be? Commented May 7, 2014 at 13:14
  • I've developped a WebPart which allows user to update their Timesheet. I've been asked to make an export of this to Excel/PDF. So basicaly there's a table with all their working hours and stuff. I also have to put the company logo on the excel.
    – Timon
    Commented May 7, 2014 at 13:18
  • If you're finding the excel builder library difficult to work with, please drop me an email - it's on the footer of every page of the site. I help at least a person or two a week with basic implementation details :)
    – Stephen
    Commented May 9, 2014 at 7:26

3 Answers 3

1

Yes you can. You can use the types in the System.Packaging namespace to create Word, Excel or PowerPoint documents.

Just using the .NET types is pretty messy so Microsoft created the OpenXML SDK to make building these documents a little easier. This "How To" from MSDN shows how to create an Excel Spreadsheet using the OpenXML SDK 2.5

How to: Create a spreadsheet document by providing a file name

For more information on the OpenXML file formats check out http://openxmldeveloper.org/

0

One solution is to create CSV files. CSVs are flat files in the form:

column1, column2
columndata1, columndata2
columndata1, columndata2

By default these files open in Excel and display like excel sheets.

The best argument is simplicity, no relying on Office libraries, simply print text into a file and save it somewhere.

Otherwise there are Office Libraries based on which version of office you have installed or are targeting. Some of them require office to be installed on the servers in the farm running the code and some older ones actaully start office in the background to create the documents. (I did this for a project, not a good idea).

Excel 2010

Excel 2013

If you have access to office 365 I believe there may be API based solutions as well.

0

Of course you can use C# to create Excel files.

Take a look at EPPlus (works only for Excel 2007/2010 format files = .xlsx files).

You will find code examples there too.

Not the answer you're looking for? Browse other questions tagged or ask your own question.