Below code is windows application..code for excel sheet reader and display coulmns.I want same code in webapplication that is in .aspx file i want.Can anybody change below code into .aspx file.
using
System;using
System.Collections.Generic;using
System.ComponentModel;using
System.Data;using
System.Drawing;using
System.Text;using
ExcelFile;using
System.Windows.Forms;using
System.Collections;using
System.Data.OleDb;namespace
ExcelFile{
public partial class Form1 : Form{
private Microsoft.Office.Interop.Excel.Application ExcelObj = null; public Form1(){
InitializeComponent();
ExcelObj =
new Microsoft.Office.Interop.Excel.Application(); // See if the Excel Application Object was successfully constructed if (ExcelObj == null){
MessageBox.Show("ERROR: EXCEL couldn't be started!");System.Windows.Forms.
Application.Exit();}
}
private void button1_Click(object sender, EventArgs e){
string strSheets = ""; string strCols = ""; if (this.openFileDialog1.ShowDialog() == DialogResult.OK){
Microsoft.Office.Interop.Excel.
Workbook theWorkBook = ExcelObj.Workbooks.Open(this.openFileDialog1.FileName, 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, false, false);Microsoft.Office.Interop.Excel.
Sheets sheets = theWorkBook.Worksheets; for (int i = 1; i <= sheets.Count; i++){
Microsoft.Office.Interop.Excel.
Worksheet worksheet = (Microsoft.Office.Interop.Excel.Worksheet)sheets.get_Item(i);string cn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + this.openFileDialog1.FileName + ";Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=1\""; OleDbConnection cnn = new OleDbConnection(cn); OleDbDataAdapter da;
da =
new OleDbDataAdapter("Select * from [" + worksheet.Name + "$]", cnn); DataTable dt = new DataTable();da.Fill(dt);
foreach (DataColumn dc in dt.Columns){
if (dc.ColumnName.ToLower() != "f1") // if there are no columns in the sheet default it gets the column name as F1{
if (strCols == "")strCols = worksheet.Name +
"." + dc.ColumnName; elsestrCols = strCols +
"," + worksheet.Name + "." + dc.ColumnName;}
}
strCols = strCols +
"-----"; if (strSheets == "")strSheets = worksheet.Name;
elsestrSheets = strSheets +
"," + worksheet.Name;}
}
textBox1.Text = strSheets;
textBox2.Text = strCols;
}
}
}
thanks,
k
k sriPosted Jul 1, 2008, 4:50 PM
ArshadPosted Jul 1, 2008, 4:21 PM
Regards
Khan