vb.net - changing the way of coding so that MS Excel is not to be needed to installed on server in asp.net -
i have started deveop website using asp.net.
i need fetch data excel display client.
i hosting site on somee.com can freely host it.
but on server of somee.com excel not installed.
i have written code website display data from excel.
dim xlapp new microsoft.office.interop.excel.application() dim xlworkbook microsoft.office.interop.excel.workbook = xlapp.workbooks.open(fileuploadpath & sender.text) dim xlworksheet microsoft.office.interop.excel._worksheet = xlworkbook.sheets(sheetname) dim xlrange microsoft.office.interop.excel.range = xlworksheet.usedrange dim rowcount integer = xlrange.rows.count dim colcount integer = xlrange.columns.count dim tbl new datatable() integer = 1 rowcount tbl.rows.add() next integer = 1 colcount tbl.columns.add() next if rowcount > 1 or colcount > 1 integer = 1 rowcount j integer = 1 colcount tbl.rows(i - 1)(j - 1) = xlrange.value2(i, j) next j next end if gvreadfiles.autogeneratecolumns = true gvreadfiles.datasource = tbl gvreadfiles.databind() xlapp.activeworkbook.close(false, session(fileuploadpath & sender.text)) xlapp.quit() xlworkbook = nothing xlapp = nothing
now need have changes in code not excel dependent.
can me?
i solved using google more 2 hours.
here code
dim objconn oledbconnection = nothing dim dt system.data.datatable = nothing try dim connstring string = "" if extension = "xls" or extension = ".xls" connstring = "provider=microsoft.jet.oledb.4.0;data source=" & fileuploadpath & sender.text & ";extended properties=" + convert.tochar(34).tostring() + "excel 8.0;hdr=no;imex=1" + convert.tochar(34).tostring() + "" elseif extension = "xlsx" or extension = ".xlsx" connstring = "provider=microsoft.ace.oledb.12.0;data source=" & fileuploadpath & sender.text & ";extended properties=" + convert.tochar(34).tostring() + "excel 12.0;hdr=no;imex=1" + convert.tochar(34).tostring() + "" end if objconn = new oledbconnection(connstring) objconn.open() dt = objconn.getoledbschematable(oledbschemaguid.tables, nothing) dim firstsheetname string = "sheet1" if not dt nothing dim excelsheets [string]() = new [string](dt.rows.count - 1) {} ' add sheet name string array. each row datarow in dt.rows firstsheetname = row("table_name").tostring().substring(0, row("table_name").tostring.length - 1) exit next end if return firstsheetname catch ex exception return "sheet1" if objconn isnot nothing objconn.close() objconn.dispose() end if if dt isnot nothing dt.dispose() end if end try
Comments
Post a Comment