asp.net(c#) Create Excel Worksheet, do i need Excel installed on the server? - asp.net

I have created an application that uses Microsoft.Office.Interop.Excel, in my local and testing environments everything worked fine, but the app does not work in the production environment.
Turns out I have Office installed locally, as does the Test server, however, the production server does not have Excel installed.
I really can't go back and change my code, however, I would really not like to have to install Excel on the production server.
Do I have any other options other than installing Office Excel on the production server to get the application working?
Thanks,
Appreciate your assistance.
Steven

Office Interop does require that Office be installed on the server.
In the more general case, you do not need Excel to create worksheets, and you should avoid any solution that requires it for web use. That includes office interop: it doesn't scale in a web environment.
See this question for more options:
Generating an Excel file in ASP.NET

Did you try to find some free cost excel components for .NET. For example, these two components have free version for creating excel files:
gembox excel component (xlsx and xls files up to 150 rows)
excel jetcell net component (without restriction writes text to excel files xls and xlsx)

The Excel interop libraries work by opening the Excel application in the background to process the spreadsheet. So without updating your code, you will need to have Excel installed on the server. However using interop is a very slow and error prone solution to working with Excel from ASP.NET, the link Joel gave provides several good alternatives.

Related

How to use the Desktop App converter (Desktop Bridge)

Just started on the process of converting my app to the windows store.
Having some hard time trying to figure out how to use the desktop app converter when the program comes in a zip package with additional files that needs to be included (Not just the EXE)
What i mean is typically speaking the users would download the zip file from the website and then extract it and run the EXE file. However in that zip file there's things like Drivers and Languages, I suppose i can make an MSI but i wanted to see if this was possible.
Anyone knows a way to just convert the ZIP file using the desktop app converter?
Thank you!
The Desktop App Converter has an option to create a Windows App Package (.appx) from a regular folder. So you just need to unzip your ZIP file and point the DAC at the folder, specifying what EXE should be the entry point: https://learn.microsoft.com/en-us/windows/uwp/porting/desktop-to-uwp-run-desktop-app-converter#no-installer-conversion - note however, that you can't deploy drivers with a Windows App Package (.appx).

Windows blocking .XLS files downloaded from the Internet where the contents are HTML

We have a legacy ASP.NET application that allows users to export the contents of a GridView control to Excel. This was achieved using this technique.
Recently, users have complained that they are unable to open their downloaded files in Excel. I tried it myself and discovered that Windows was blocking the downloaded file, preventing Excel from opening it.
It looks like Windows now regards XLS files that have been created from web page content as suspect. Is this the result of a recent Windows update? And is this technique of creating Excel files from web pages not recommended?
Correct, recent updates have broken this behavior (thanks to Nikki9696 for the article).
There are three workarounds listed:
Stop using HTML files masquerading as XLS
Unblock access to individual files (client side solution)
or add the source of the files to the Trusted Locations list in Excel (client side solution)
The best thing to do is #1. You should not be serving files with one data type as another file type. It's always generated a warning for users. Many Office clients that otherwise know how to open XLS files (such as Office for iPad) will choke when presented with an HTML file masquerading as XLS.
Instead, use a library to generate a modern XLSX file (which can be opened by Office 2003 and newer). There are several solutions such as EPPlus, NPOI, and Open XML SDK.
In the future, be careful to use supported solutions rather than cobbling together a hack like serving a file with the wrong extension.

Using R to save images & .csv's, can I use R to upload them to website (use filezilla to do it manually)?

First I should say that a lot of this is over my head, so I apologize in advance for using incorrect terminology and potentially asking an unclear question. I'm doing my best.
Also, I saw ThisPost; is RCurl the tool I want to use for this task?
Every day for 4 months I'll be analyzing new data, and generating .csv files and .png's that need to be uploaded to a web site so that other team members will be checking. I've (nearly) automated all of the data collecting, data downloading, analysis, and file saving. The analysis is carried out in R, and R saves the files. Currently I use Filezilla to manually upload the new files to the website. Is there a way to use R to upload the files to the web site, so that I don't have to open Filezilla and drag+drop files?
It'd be nice to run my R-code and walk away, knowing that once it finishes running, the newly saved files will be automatically be put on the website.
Thanks for any help!
You didn't specify which protocol you use to upload your files using FileZilla. I assume it is ftp. If so, you can use the ftpUpload function of RCurl:
library(RCurl)
ftpUpload("yourfile", "ftp://ftp.yourserver.foo/yourfile",
userpwd="username:passwd")
RCurl also had methods for scp and should also support sftp using ftpUpload.

Using ASP.NET with Excel Files

I want to create an excel file from a web page in ASP.NET, I'm using the Microsoft.Office.Interop.Excel library, but I can't delete the file create on the side of the server, because I get in trouble with the times. I want to know if there is a way to create an Excel file with data of a database for example, and then that the client can download that file without saturate the server.
Actually I'm using this code in VB after the file is create in the server, but it doesn't work like I want:
Dim p As Process = New Process()
p.StartInfo = New ProcessStartInfo()
p.StartInfo.UseShellExecute = True
p.StartInfo.FileName = "taskkill.exe"
p.StartInfo.Arguments = "/F /IM EXCEL.exe"
p.Start()
p.WaitForExit()
Thread.Sleep(24)
Response.ContentType = "application/vnd.ms-excel"
Response.AppendHeader("Content-Disposition", "attachment; filename=Reporte.xlsx")
Response.TransmitFile(Server.MapPath("~/Resources/" & HiddenField1.Value.ToString() & ".xlsx"))
'Thread.Sleep(10000)
'Dim fso, f2
'fso = CreateObject("Scripting.FileSystemObject")
'f2 = fso.GetFile(Server.MapPath("~/Resources/" & HiddenField1.Value.ToString() & ".xlsx"))
'f2.Delete()
'Thread.Sleep(24)
Response.End()
Thanks
You might consider using something other than Excel to create the file you want to send.
For example, there is Carlos Aguilar Mares's free Excel XML library: http://www.carlosag.net/tools/excelxmlwriter/.
Also, some reporting tools like SQL Server Reporting Services have the option of exporting native Excel files. That's one way to generate an Excel file, complete with formatting.
Finally, Excel can read other types of files, such as CSV and HTML files. Those are a lot easier to produce and don't require Excel itself to generate.
A good run-through of the options: Generating an Excel file in ASP.NET
Automating excel on a server is not officially supported by Microsoft and I suggest you find an alternative. Microsoft has a lot of good information on this topic here: http://support.microsoft.com/kb/257757.
All current versions of Microsoft Office were designed, tested, and
configured to run as end-user products on a client workstation. They
assume an interactive desktop and user profile. They do not provide
the level of reentrancy or security that is necessary to meet the
needs of server-side components that are designed to run unattended.
Microsoft does not currently recommend, and does not support,
Automation of Microsoft Office applications from any unattended,
non-interactive client application or component (including ASP,
ASP.NET, DCOM, and NT Services), because Office may exhibit unstable
behavior and/or deadlock when Office is run in this environment.
If you are building a solution that runs in a server-side context, you
should try to use components that have been made safe for unattended
execution. Or, you should try to find alternatives that allow at least
part of the code to run client-side. If you use an Office application
from a server-side solution, the application will lack many of the
necessary capabilities to run successfully. Additionally, you will be
taking risks with the stability of your overall solution.
They even offer suggestions on how to avoid using them:
Most server-side Automation tasks involve document creation or
editing. Office 2007 supports new Open XML file formats that let
developers create, edit, read, and transform file content on the
server side. These file formats use the System.IO.Package.IO namespace
in the Microsoft .NET 3.x Framework to edit Office files without using
the Office client applications themselves. This is the recommended and
supported method for handling changes to Office files from a service.
They also have tutorials on using the APIs:
http://msdn.microsoft.com/en-us/library/bb739834.aspx
http://msdn.microsoft.com/en-us/library/bb727373.aspx
We use EPPlus to generate our excel documents.
It gives you quite a bit of control over the output and it's very fast. As John said, automating Excel on the server through a web site is completely unsupported by MS and they suggest you use alternatives.

excel file reading error in C#

i am tring to read excel file but the iis7 is giving this error:
"Microsoft Office Excel cannot access the file 'D:\Demosites\Domaininterface\Keywordsfolder\keywords2172011 23841 PM.xlsx'. There are several possible reasons: • The file name or path does not exist. • The file is being used by another program. • The workbook you are trying to save has the same name as a currently open workbook."
someone know about this?
Since the path is explicit, it sounds like a permissions issue - simply: the account that the application / app-pool is running as (in IIS) doesn't have access to that folder.
However, unless it has changed recently, you should note that Excel is not supported for use on a server - it is desktop software, and you may run into a multitude of issues using it on a server. And I have no idea whether this would be a licensed scenario ;p

Resources