Export and Import from Excel into a Web page

G

Guest

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.ContentType = "application/vnd.ms-excel";
Response.Charset = "";
this.EnableViewState = false;

System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new
HtmlTextWriter(oStringWriter);

DataGrid1.AllowPaging = false;

DataGrid1.DataBind();
this.ClearControls(DataGrid1);
DataGrid1.RenderControl(oHtmlTextWriter);

Response.Write(oStringWriter.ToString());

Response.End();
DataGrid1.AllowPaging = true;
DataGrid1.DataBind();

//IMPORT
string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" +
strFileNamePath + ";Extended Properties=Excel 8.0;";
OleDbConnection conn = new OleDbConnection(strConn);
string sql = "SELECT * FROM [Sheet1$]";
OleDbCommand cmd = new OleDbCommand(sql, conn);
conn.Open();
OleDbDataReader rd = cmd.ExecuteReader(CommandBehavior.CloseConnection);
DataGrid1.DataSource = rd;
DataGrid1.DataBind();
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 :)
 
G

Guest

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 ;)
 
D

douglas.ross

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top