473,761 Members | 3,651 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Export and Import from Excel into a Web page

Siu
Hi,
I use the following code to export and import a file Excel from resp. into a
Web page with the following code:

//EXPORT
Response.Clear( );
Response.Buffer = true;
Response.Conten tType = "applicatio n/vnd.ms-excel";
Response.Charse t = "";
this.EnableView State = false;

System.IO.Strin gWriter oStringWriter = new System.IO.Strin gWriter();
System.Web.UI.H tmlTextWriter oHtmlTextWriter = new
HtmlTextWriter( oStringWriter);

DataGrid1.Allow Paging = false;

DataGrid1.DataB ind();
this.ClearContr ols(DataGrid1);
DataGrid1.Rende rControl(oHtmlT extWriter);

Response.Write( oStringWriter.T oString());

Response.End();
DataGrid1.Allow Paging = true;
DataGrid1.DataB ind();

//IMPORT
string strConn = "Provider=Micro soft.Jet.OLEDB. 4.0;" + "Data Source=" +
strFileNamePath + ";Extended Properties=Exce l 8.0;";
OleDbConnection conn = new OleDbConnection (strConn);
string sql = "SELECT * FROM [Sheet1$]";
OleDbCommand cmd = new OleDbCommand(sq l, conn);
conn.Open();
OleDbDataReader rd = cmd.ExecuteRead er(CommandBehav ior.CloseConnec tion);
DataGrid1.DataS ource = rd;
DataGrid1.DataB ind();
rd.Close();

The export code works fine, whether the import code has a problem,namely:
when I import a Excel file which I have created from scratch with two simple
column, the Import code works.... When I import an Excel file which I've
exported with my Export code, I obtain the following error at the line
conn.Open():

External table is not in the expected format.

I've already check in the exported Excel file,
the name of the sheet which is "Sheet1" and I've also deleted the formatting
namely rows and columns colors... but it doesn't work!!

How can I solve the problem?

Thanks :)
Nov 19 '05 #1
2 3995
Siu
I've discovered that the export code creates a file which has HTML format and
it is visible in Excel: in order to make the import code working I should
manually convert the HTML file into a .xls file.... My question is now:

how can I code this function of conversion from HTML to .xls (... like a
Save As... function) in the codebehind??

Please help me ;)

"Siu" wrote:
Hi,
I use the following code to export and import a file Excel from resp. into a
Web page with the following code:

//EXPORT
Response.Clear( );
Response.Buffer = true;
Response.Conten tType = "applicatio n/vnd.ms-excel";
Response.Charse t = "";
this.EnableView State = false;

System.IO.Strin gWriter oStringWriter = new System.IO.Strin gWriter();
System.Web.UI.H tmlTextWriter oHtmlTextWriter = new
HtmlTextWriter( oStringWriter);

DataGrid1.Allow Paging = false;

DataGrid1.DataB ind();
this.ClearContr ols(DataGrid1);
DataGrid1.Rende rControl(oHtmlT extWriter);

Response.Write( oStringWriter.T oString());

Response.End();
DataGrid1.Allow Paging = true;
DataGrid1.DataB ind();

//IMPORT
string strConn = "Provider=Micro soft.Jet.OLEDB. 4.0;" + "Data Source=" +
strFileNamePath + ";Extended Properties=Exce l 8.0;";
OleDbConnection conn = new OleDbConnection (strConn);
string sql = "SELECT * FROM [Sheet1$]";
OleDbCommand cmd = new OleDbCommand(sq l, conn);
conn.Open();
OleDbDataReader rd = cmd.ExecuteRead er(CommandBehav ior.CloseConnec tion);
DataGrid1.DataS ource = rd;
DataGrid1.DataB ind();
rd.Close();

The export code works fine, whether the import code has a problem,namely:
when I import a Excel file which I have created from scratch with two simple
column, the Import code works.... When I import an Excel file which I've
exported with my Export code, I obtain the following error at the line
conn.Open():

External table is not in the expected format.

I've already check in the exported Excel file,
the name of the sheet which is "Sheet1" and I've also deleted the formatting
namely rows and columns colors... but it doesn't work!!

How can I solve the problem?

Thanks :)

Nov 19 '05 #2
This isn't .NET specific, but a turnkey product to allow Excel-web
interactivity (multiple users updating the same workbooks using only
web browsers) is BadBlue Enterprise. See
http://badblue.com/helpxls.htm - while charts and real-time editing
(with cell-by-cell security for each user) is supported, I"m not sure
formatting of cells comes across.

Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3071
by: frankvfox | last post by:
I need a code sample using VB ASP.Net 2003 which exports a tab delimited text file resident on the server into an Excel spreadsheet which will be saved through the browser to the client's local workstation. I don't need examples of a Windows application where everything is local. I've tried KB306022 which doesn't work. I've included references to Microsoft.Office.Core and Microsoft Excel 11.0 Object Library. When I try to use the...
1
5033
by: Matt | last post by:
I have an ASP page that calls ASP routines that I created that execute a database query and return the results to a recordset. I then iterate through the recordset and display the data in a table. Before I iterate through the recordset I instruct the browser that the content type is Excel using the following line: (Response.ContentType = "application/vnd.ms-excel") This works fine with Excel 2003 but with older versions (I tested Excel...
5
3791
by: Maria L. | last post by:
Hi, I need to export the content of a DataGrid (in Windows application in C#), into an Excel spreadsheet. Anyone knows how to do this? Any code snippets would help! thanks a lot, Maria
8
13253
by: Taffman | last post by:
I've searched this goup for an answer to this, there are many discussions that come close but non that I can find that actually addresses this particular problem. I'm exporting queries to Excel. These queries have memo fields in them Each memo field is trunkated, i.e cuts off after 255 characters. Is there any way either via VBA or otherwise to get all my memo text to export to Excel. I note that there is no such limit when exporting...
13
13240
by: Hemant Sipahimalani | last post by:
The following piece of code is being used to export HTML to excel. HttpContext.Current.Response.ContentType = "application/vnd.ms-excel" HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=ABC.xls") HttpContext.Current.Response.Write(strHTML) HttpContext.Current.Response.End() However when the user tries to save it the Default File Type is Web Page(*.htm; *.html)
7
7810
by: Vanessa | last post by:
hi Everyone, I have two questions on exporting data to Excel using ASP (w/o converting formatted excel file into web page and then plug in the dynamic data): 1. Can we export data into different sheets at Excel? 2. Can we do graph at export? Thanks!!
5
31923
by: Simon | last post by:
Dear reader, With the export command you can export a query to Excel. By activate this command a form pop's up with the following text:
1
1809
by: Arch Stanton | last post by:
I export the contents of my datagrid controls to Excel using the following Sub: Sub WriteToExcel(Sender as Object, E as EventArgs) Response.Clear() Response.ContentType = "application/vnd.ms-excel" Response.AddHeader("content-disposition","attachment;filename=Data.xls") Response.Charset = ""
3
7162
by: =?Utf-8?B?YzY3NjIyOA==?= | last post by:
Hi all, I have a question for you. I have a .csv file which has many lines of data. Each line has many data fields which are delimited by ",". Now I need to extract part of data from this file but save it as an excel file. The data in this excel file will be imported into an Access database. The
0
9522
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
9336
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
9948
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
9902
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,...
1
7327
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6603
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
5364
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3866
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3446
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.