Response.Conten tType Excel
I am trying to export a datagrid into an excel sheet.
What it now does is the entire page is saved as an excel sheet in XlHtml file format. I want it in xlWorkbookNorma l format and also have to delete that extra blank space in the excel sheet. Please help out if somebody knows.
Dim dt As DataTable = GetDataTableFro mDatabase()
GridView2.DataS ource = dt
GridView2.DataB ind()
Response.Clear( )
Response.Buffer = True
Response.AddHea der("content-disposition", "attachment;fil ename=OpenRequi sitions.xls")
Response.Conten tType = "applicatio n/vnd.ms-excel"
Response.Charse t = ""
Me.EnableViewSt ate = False
GridView1.Visib le = False ' making other controls on the page invisible
btnDBtoExcel.Vi sible = False
btnExcelLoad.Vi sible = False
Dim oStringWriter As New System.IO.Strin gWriter()
Dim oHtmlTextWriter As New System.Web.UI.H tmlTextWriter(o StringWriter)
Try
GridView2.Rende rControl(oHtmlT extWriter)
Response.Write( oStringWriter.T oString())
Response.End()
Catch ex As Exception
End Try
When I try the reverse operation , since the format is XlHtml and not xlWorkbookNorma l, it is not filling into dataset . I dont get a solution.
Pls Help Out. Here is the code for getting it.
Dim strConn As String
Dim excelobj As New Excel.Applicati on()
Dim sheets As Excel.Sheets
Dim sheetName As String
'strFileName contains the full path of the Excel file
strConn = "Provider=Micro soft.Jet.OLEDB. 4.0;" + "Data Source=" + strFileName + ";" + "Extended Properties=Exce l 8.0;"
Try
Dim theWorkbook As Excel.Workbook
theWorkbook = excelobj.Workbo oks.Open(strFil eName, 0, True, 5, "", "", True, Excel.XlPlatfor m.xlWindows, "\t", False, False, 0, True)
sheets = theWorkbook.Wor ksheets 'get the sheets
sheetName = CType(sheets(1) , Excel.Worksheet ).Name.Trim() 'get the sheet you want
Catch ex As Exception
End Try
Try
'You must use the $ after the object you reference in the spreadsheet
Dim myCommand As New OleDbDataAdapte r("SELECT * from [" + sheetName + "$]", strConn)
Dim myDataSet As New DataSet()
Dim iRowsAffected As Integer = myCommand.Fill( myDataSet, "ExcelInfo" )
GridView1.DataS ource = myDataSet.Table s("ExcelInfo"). DefaultView
GridView1.DataB ind()
GridView2.Visib le = False
btnExcelLoad.Vi sible = False
btnDBtoExcel.Vi sible = False
FileUpload1.Vis ible = False
Catch ex As Exception
Response.Write( "File not in Normal workbook format")
End Try
0 1380 Sign in to post your reply or Sign up for a free account.
Similar topics |
by: mappo |
last post by:
There are about a million posts on how to get rid of the extra space _after_ the
form end-tag, but I can't find any that solve my problem: extra space _in_ the
form tag.
I have a table nestled inside the form and since I want the submit button
underneath the input text field i have a br tag to separate them. For some
reason IE5.5 gives me what seems like two br tags. It looks good in Opera 7,
and in K-Meleon 0.6 (Gecko).
|
by: Stephen |
last post by:
I have a really annoying problem with a datagrid. I have an application which
populates a datagrid on the onclick event of a button. The datagrid is bound
to an ArrayList which holds the values. Everything worked perfectly for me
in my test application however when I copied and pasted the code accross to
my main project something strange started to happen. On the on-click event
of the button (cmdExcAdrContinue) the datagrid is populated...
|
by: Ann Huxtable |
last post by:
Hi,
I am writing a nested table structure to mimic data returned from a
database (actually, a heirarchical recordset).
I am representing the cells where the actual data is stored, by a union:
class Cell {
union {
char* s ; //std::string s ;
|
by: Thomas R. Hummel |
last post by:
Hello all,
I have been working with several databases here that are basically data
marts. A lot of the entities have an attribute that is a particular
year and month. For example, a financial transaction may be posted for
a particular month, regardless of the actual date on which it occurred.
In this system, these year/month combinations have typically been
stored as integers of the form YYYYMM. My question is, how have others
stored...
|
by: Adrian Parker |
last post by:
v1.1 and v2.0
We have a problem with viewstate not being stored.
What's happening is that we create controls in CreateChildControls and add them to a container on the page (whether it be a panel or
a table etc). We only set the data values for the controls if not page.ispostback. But, if either of the textboxes change,
the page posts back and the changed event fires twice.
Protected Overrides Sub CreateChildControls()
Dim...
| |
by: Mark Rae |
last post by:
Hi,
See the following:
http://www.devnewsgroups.net/group/microsoft.public.dotnet.framework/topic38190.aspx
This was a particularly useful feature of the old DataGrid control which
seems to be missing from the new GridView control
What is the "preferred" method of doing this in a GridView?
|
by: (PeteCresswell) |
last post by:
User wants to go this route instead of storing pointers in the DB and the
documents outside.
Only time I tried it was with only MS Word docs - and that was a loooong time
ago - and it seemed to me like there were performance issues at the time.
How about the different types? The MS docs I would expect Access to
differentiate and handle appropriately (i.e. .DOC and .XLS).. but how about
..PDF? and can I stash a .TXT document in the...
|
by: Mark |
last post by:
I'm consuming a webservice that makes a simple object available. The object
class is marked in the web service as . I have a web
application that consumes and uses this web service's class. When I receive
the object from the web service, I'm interested in storing that object in
ViewState in the web application, but I receive the error below. I'm not
shocked that the web application can't serialize the object as the
attribute isn't...
|
by: Jibran |
last post by:
I need some help with extra spaces in HTML form. There is a big white space appearing at the center of the HTML form that I am designing even though there is no <br> tags been used:
http://i116.photobucket.com/albums/o9/Jibran82/Pic1.jpg
The html code is below:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta
http-equiv="Content-Type"
|
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...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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...
|
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();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |