473,657 Members | 2,492 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Excel Import - having difficulties

16 New Member
Hi

I am developing in c# .net 2,0 web forms and having some problems. Code is attached below.

I have written code to export the contents of a Grid View to Excel, this works. The problem occurs when i change the contents of the datagrid such as apply a row filter to it. The new records have been binded to the datasource.

I try to export those results to Excel but seem to the whole datagrid contents into Excel instead of the filtered results.

Example: Filter the datagrid to display three records and then i Export to Excel, Excel should only display those records instead all the records are displayed

Code:
Table objTable = new Table();
StringBuilder str = new StringBuilder() ;

if ((GridView1.Hea derRow) != null)
{
objTable.Rows.A dd(GridView1.He aderRow);
}

foreach (GridViewRow row in GridView1.Rows)
{
str.Append (objTable.Rows. Add(row).GetTyp e());
}

if ((GridView1.Foo terRow) != null)
{
objTable.Rows.A dd(GridView1.Fo oterRow);
}

Response.Clear( );

Response.AddHea der("content-disposition", "attachment;fil ename=FileName. xls");
Response.Charse t = "";

// Response.Cache. SetCacheability (HttpCacheabili ty.NoCache);

Response.Conten tType = "applicatio n/vnd.xls";

System.IO.Strin gWriter stringWrite = new System.IO.Strin gWriter();

System.Web.UI.H tmlTextWriter htmlWrite = new HtmlTextWriter( stringWrite);

//GridView1.Allow Paging = false;
//GridView1.DataB ind();

objTable.Render Control(htmlWri te);

//GridView1.Allow Paging = true;
//GridView1.DataB ind();

Response.Write( stringWrite.ToS tring());

Response.End();

Thanks

Raz
Aug 28 '07 #1
0 1034

Sign in to post your reply or Sign up for a free account.

Similar topics

15
4209
by: daniroy | last post by:
Hello everybody, your help will be very very welcome on a very classic question... I have some Excell Macro background, a little bit of VBA knowledge. I import daily from Internet series of data. They are setup as follow, with a few more columns on the rights as stock prices, dividend and so on as: Date Code Country Adjust Reason Name Shares 25/02/2005 FR0000045072 FR CREDIT AGRICOLE
0
2833
by: Jack | last post by:
Windows 2K Pro Access/Excel 2003 Hi there, I have a large number of password protected Excel Workbooks. The files are protected by code that runs when the workbook opens. The code asks the user to key in a password into an input box, the password is compared to a a partciular cell on a hidden (xlVeryHidden) sheet and if it matches the Workbooks opens. I have not used the usual Excel password protection as I need to provide for several...
9
3910
by: jillandgordon | last post by:
I am trying to import an excel file into Access 97. It looks perfectly all right but, every time I try to import it, I get to the lst step and am told that it was not imported due to an error. There is no further explanation. What are the kinds of things that make this happen? Thanks from an obvious rookie. Gordon
3
1830
by: Mike | last post by:
Hello, I am attempting to export the contents of a datagrid on my webform (using Excel automation) through ASP.NET. I have added the Excel object library to my VS ASP.NET project but I am lost on how to export my datagrid contents to Excel? I am sure it can be done but having difficulties figuring out the code.
12
6012
by: kath | last post by:
How do I read an Excel file in Python? I have found a package to read excel file, which can be used on any platform. http://www.lexicon.net/sjmachin/xlrd.htm I installed and working on the examples, I found its printing of cell's contents in a different manner. print sh.row(rx)
0
2741
by: liam_jones | last post by:
I'm very new to Python, well IronPython to precise, and have been having problems when using Excel. The problem I'm having is the closing of my Excel object. I'm able to successfully quit the Excel Application that I create, but when I open a Workbook in the Application I can't successfully Quit Excel (by this I mean I can quit it, but the Excel process isn't getting killed and I have to manually go this through Task Manager). I've...
0
1527
by: Yvonne | last post by:
I've had on going problems trying to import data from an Excel spreadsheet in to Access 2002. I checked to make sure that the field names were EXACTLY the same, but no go. The only way round it was import to a new table then append this to the table originally intended called tblMain.. Having got fed up of doing that, I just thought I'll do an export to Excel from tblMain and then re-import from Excel back into tblMain. Still wouldn't...
8
2253
by: cgrider | last post by:
I have an access databae that I am creating to import data from the end user from an excel file. And from that generate a report for him to send to a customer. The issue that I am having the report has a group by section based off one of the fields and the field is based off a custom list of options. I.E. not numerical or alphebetical. So what I am trying to do is convert the values of the custom list to a numerical list to provide for easy...
1
5154
by: thadson | last post by:
Hi, I'm trying to import specific cells from MS Excel 2000 spreadsheets to MS Access 2000 tables then move the spreadsheets to a different directory. I'm very new to this and I'm having trouble to implement this. I have worked out so far the code to import certain cells into 1 table, but I do not know how to import some other cells into another tables so the data would be connected and remain together. So lets say that I have 2 tables...
0
8403
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
8316
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,...
1
8509
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,...
0
8610
tracyyun
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...
1
6174
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
5636
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
4327
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2735
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
2
1967
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.