If Im using SqlBulkCopy in .net 4.0 on a sql 2008 R2 database to upload excel data to the database, do I actually need Excel on the box hosting the site for this to work?
The reason I ask is I have a site up and running with this, and the hosting box has excel. The customer wants the site moved to a new box, this one doesnt have Excel and that bulk copy doesnt work. Other than the lack of excel there is no other difference.
thanks
If you are using the Microsoft Excel Object Library (COM Interop) to interface with Excel from .Net 4, then yes you need Excel installed as that is interfacing with the Excel object library.
What are your project references in C#?
Anything link to office automatiion would need taht part of office that is being automated. Also, if .Net 4 that objects may be referenced with the dynamic keyword.
Hard to tell exactly without knowing the project, references, and relevant code.
However, there are several third party libraries that allow interaction with Excel without having Excel installed. So, if you need to work without Excel, investigate using those.
Related
I am trying to find a proper way to migrate a VB project within an Excel Sheet to C#. Migration will not change most of the code apart from the DB calls because it will use a new DB Structure.
Basically the Project makes several DB calls, performs some calculations and fills some pre-created Excel templates with the data retrieved/handled.
I guess ,the quick way to keep sleeping at night and use these Excel Sheets in the new aplication is to change the VB queries only and update the Excel files to a new version.
However, we want to find a way to migrate the project to C# and perhaps use it in the future in Online Excel Sheets. Here is where I get lost. It seems a way to do it could be with Visual Studio Tools for Office (VSTO ) but we have a Community version and they are included in the professional or Ultimate ones, is that correct? Are there any other ways to migrate such a project?
Thanks and regards
We have a .Net/C# based web service.
Within the service, we use a spreadsheet as a calculationr engine.
We're using Apose.Cells for .Net to populate the spreadsheet cells.
Calculations are performed through VB script embedded in the spreadsheet.
To be able to generate results, I need to be able to run/trigger the VB script.
Aspose does not seem to support this functionality.
It can poke/retrieve data and force recalc of any formulae that exist in the spreadsheet, but not run macros/VB script.
Once I've uploaded the desired data into the spreadsheet, how do I run the macros through .Net?
Thanks,
JohnB
Aspose.Cells cannot run macros. Besides, we are afraid, there is no server-side solution for your problem too. However on client-side (local machine) you can execute macros using Microsoft Office APIs. Please use the namespace
i.e
using Excel = Microsoft.Office.Interop.Excel;
Here is an example how to make use of it.
https://social.msdn.microsoft.com/Forums/Lync/en-US/2e33b8e5-c9fd-42a1-8d67-3d61d2cedc1c/how-to-call-excel-macros-programmatically-in-c?forum=exceldev
Note: I am working as Developer Evangelist at Aspose
Is there any free or purchased library or any API which allows me to update excel sheet while it is opened also.
I'm not certain of the nature of your project, but perhaps you could create an Office Add-In? I've had some very good experiences with Add-In-Express: http://www.add-in-express.com/add-in-net/index.php
If just creating an add-in isn't going to work for your application, consider writing a plugin that your application can communicate with to do the work for you behind the scenes.
If you want your Excel spreadsheet to be updated in real time, you have to develop an RTD which can be queried by Excel itself. Please refers to Microsoft documentation for that. Add-In express provides you excellent simplified API to develop that, we are using them and we are very happy with that.
There is no tool that can do that since the file is locked by the operating system.
With COM you should be able to drive a workbook that has been opened by the user.
This question already has answers here:
How do I create an Excel (.XLS and .XLSX) file in C# without installing Microsoft Office?
(47 answers)
Closed 4 years ago.
I am writing a program that generates excel reports, currently using the Microsoft.Interop.Excel reference. My dev computer has Excel on it, but the end user may or may not have Office installed. Will this tool fail if Office isn't installed on the end users computer, or is this interop service separate from the actual application?
If you're interested in making .xlsx (Office 2007 and beyond) files, you're in luck. Office 2007+ uses OpenXML which for lack of a more apt description is XML files inside of a zip named .xlsx
Take an excel file (2007+) and rename it to .zip, you can open it up and take a look. If you're using .NET 3.5 you can use the System.IO.Packaging library to manipulate the relationships & zipfile itself, and linq to xml to play with the xml (or just DOM if you're more comfortable).
Otherwise id reccomend DotNetZip, a powerfull library for manipulation of zipfiles.
OpenXMLDeveloper has lots of resources about OpenXML and you can find more there.
If you want .xls (2003 and below) you're going to have to look into 3rd party libraries or perhaps learn the file format yourself to achieve this without excel installed.
Unless you have Excel installed on the Server/PC or use an external tool (which is possible without using Excel Interop, see Create Excel (.XLS and .XLSX) file from C#), it will fail. Using the interop requires Excel to be installed.
Try EPPlus if you use Excel 2007. Supports ranges, cellstyling, charts, shapes, pictures and a lot of other stuff
There are a handful of options:
NPOI - Which is free and open
source.
Aspose - Is definitely
not free but robust.
Spreadsheet
ML - Basically XML for creating spreadsheets.
Using the Interop will require that the Excel be installed on the machine from which it is running. In a server side solution, this will be awful. Instead, you should use a tool like the ones above that lets you build an Excel file without Excel being installed.
If the user does not have Excel but has a tool that will read Excel (like Open Office), then obviously they will be able to open it. Microsoft has a free Excel viewer available for those users that do not have Excel.
An interop calls something else, it's an interoperability assembly, so you're inter-operating with something...in this case Excel, the actual installed Excel.
In this case yes, it will fail to run because it depends on excel, you're just calling excel functions. If they don't have it installed...out of luck.
There are methods to generate without Excel, provided the 2007 file format is ok, here's a few:
http://excelpackage.codeplex.com/
http://simpleooxml.codeplex.com/
as I said though, this is the 2007 format, normally if anything, that's the deal-breaker.
Use OleDB, you can create, read, and edit excel files pretty easily. Read the MSDN docs for more info:
http://msdn.microsoft.com/en-us/library/aa288452(VS.71).aspx
I've used OleDB to read from excel files and I know you can create them, but I haven't done it firsthand.
You could use the ExcelStorage Class of the FileHelpers library, it's very easy and simple... you will need Excel 2000 or later installed on the machine.
The FileHelpers is a free and easy to
use .NET library to import/export
data from fixed length or delimited
records in files, strings or streams.
I want to know what is the best practice to create a Excel 2007 Workbook using C#, with its datasource being a raw flat file or a table in database.
You can use
"Open XML SDK 2.0 for Microsoft Office"
It's more comfortable than harcore manually hacking OpenXML spec. There are .NET strongly typed wrapper classes so it's not hard to create a simple sheet. You don't need any interop and msoffice installed and it's safe for server soluitions - there are only a few dlls which you can ship in your solution.
I did mail-merge solution and it wasn't so scary.
But as always, when it's possible, I'm prefering plain csv format.
I personally like creating CSV's, which can be opened directly in Excel. It's a lot less work than trying to hack the Office Open XML specification, and you don't need COM interop to Excel (which requires a copy of Excel to work).
You can use the Office Primary Interop Assemblies to completely automate Excel 2007, and create the workbook from within C#.
This gives you the most control, as you have complete control over how you map from DB or flat file -> Excel workbook/worksheet.
I am using
http://www.leniel.net/2009/07/creating-excel-spreadsheets-xls-xlsx-c.html
for creating excel . Seems good so far.