473,672 Members | 2,641 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to make a website that is able to export an excel file?

1 New Member
Hello, I have the following problem:
I created a website project and I want in that website to be make a button, which will export some data in an excel file. This is the code that I have:
Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.UI;
  6. using System.Web.UI.WebControls;
  7. using Excel = Microsoft.Office.Interop.Excel;
  8.  
  9. namespace TU_Sofia_PublicationSystem
  10. {
  11.     public partial class Default : System.Web.UI.Page
  12.     {
  13.         protected void Page_Load(object sender, EventArgs e)
  14.         {
  15.  
  16.         }
  17.  
  18.         protected void ExportToExcel(object sender, EventArgs e)
  19.         {
  20.             Excel.Application excelApp = new Excel.Application();
  21.             excelApp.Workbooks.Add();
  22.             Excel._Worksheet workSheet = excelApp.ActiveSheet;
  23.             workSheet.Cells[1, "A"] = "Make";
  24.             workSheet.Cells[1, "B"] = "Colorqqqqqqqqq";
  25.             workSheet.Cells[1, "C"] = "Pet Namesdvbpofsdajnvbdajbi";
  26.             workSheet.SaveAs(@"C:\Inventory.xlsx", Excel.XlFileFormat.xlWorkbookDefault, Excel.XlSaveAsAccessMode.xlNoChange);
  27.             excelApp.Workbooks.Close();
  28.             excelApp.Quit();
  29.             excelApp = null;
  30.         }
  31.     }
  32.  
Now this will work only if in the SaveAs method I change "C:\Inventory.x lsx" with "Inventory.xlsx " and the file will be saved in My Documents. If I try to specify a path the following error is shown:

Microsoft Excel cannot access the file 'C:\094B4000'. 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.

I suppose that this is tottaly not the way that I have to do it; however I was unable to find some valuable information using Google and a lots of books that I have(from Apress).

Any help like code, or like in which book can I find information is highly appreciated.
Dec 3 '10 #1
0 1400

Sign in to post your reply or Sign up for a free account.

Similar topics

2
2733
by: allyn44 | last post by:
Hi, I have a small databse that outputs 2 excel files to a folder. DoCmd.TransferSpreadsheet acExport, , "randtrack",_ "C:\randomization\Trackrandomization.xls" The person wants to put the database on a Mapped drive which shows as their H drive: path
1
2006
by: sanju | last post by:
hi guyz .. can anyone send sample code to export a excel file into sql server table using web interface . ie programatically read and select some columns of excel and insert into a table. please give me an idea on this thank u very much san auckland
2
1119
by: chalres | last post by:
i'd like to make some word and excel file from webpage this word file is the same as the webpage how can i make it?
3
2592
by: ABC | last post by:
What methods can export excel file from stored procedure with parameters which input from web form?
5
7286
by: vimal.424 | last post by:
Hi......all.... can any body tell me how can we upload excel file & send the excel file data in database. I;m not able to do........please help me...... thanks in advance
1
6684
by: DennisBetten | last post by:
First of all, I need to give some credit to Mahesh Chand for providing me with an excellent basis to export data to excel. What does this code do: As the title says, this code is capable of extracting all tables and it's data from any given database! I was searching the net for a program like this, but I didn't come accross any (free) versions. So I decided to write it myself. To get this code to work, you need to add a reference to...
6
2730
by: slinky | last post by:
I found the following code to transfer datagrid data to an Excel file. Is this written in C#?... I'm a vb.netter. I'm just not sure where to place the code to experiment on it. Should I place it in the event handler for a form button. Is there other ways to accomplish this? I looked at some on the web and usergroups, but was confused as to the functioning. BTW my datagrid is enclosed in a <div></divfor ease of scrolling if that would...
3
3046
by: minhtran | last post by:
Hi all Anyone has any idea how to get a Excel header column in VB.NET. Please, help me. Thank you so much in advance
15
9429
by: patf | last post by:
Hi - experienced programmer but this is my first Python program. This URL will retrieve an excel spreadsheet containing (that day's) msci stock index returns. http://www.mscibarra.com/webapp/indexperf/excel?priceLevel=0&scope=0&currency=15&style=C&size=36&market=1897&asOf=Jul+25%2C+2008&export=Excel_IEIPerfRegional Want to write python to download and save the file. So far I've arrived at this:
3
2188
by: sukhsinghin | last post by:
Hi, I am trying to make a copy of excel file using file.copy(path1,path2). its copying but making a blank file. Data is not getting copied. File.Copy(path, path2) Can anyone help me on this Thanks in advance.
0
8486
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8404
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8931
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8828
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8608
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7446
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5705
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4227
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4418
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.