473,387 Members | 3,787 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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

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.xlsx" 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 1385

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

Similar topics

2
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...
1
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...
2
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
by: ABC | last post by:
What methods can export excel file from stored procedure with parameters which input from web form?
5
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
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...
6
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...
3
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
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. ...
3
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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,...

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.