472,331 Members | 1,813 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,331 software developers and data experts.

Export to excel

Hi and TIA! I have an export procedure that exports my data from my
datagrids to excel. The problem is that I lose leading zero's cause excel
removes them and doesn't treat them as text. Is it possible to design an
excel template file, place it in my shared network folder and have the
procedure write data to the template file? I've thought of reading the
recordset line by line, field by field and concatenating an apostrophe at
the beginning of each field, but this seems a little overboard and some of
the recordsets are quit large. I'm open for any advice or if you could
point me in the correct direction I would appreciate it. Thanks!

Oct 2 '08 #1
5 2422
Hi, I had this problem also. This is an asp.net 1.1 solution - I don't know
what version you're working in but I'm sure there'll be something similar in
all versions. You can add a text attribute to your datagrid after it's
databound which ensures Excel treats the data as text and doesn't remove
leading zeros:

For rowPos As Integer = 0 To DataGrid.Items.Count - 1
For colPos As Integer = 0 To
DataGrid.Items(rowPos).Cells.Count - 1

DataGrid.Items(rowPos).Cells(colPos).Attributes.Ad d("class", "text")
Next
Next

Hope this helps.
Julia

"Reggie" wrote:
Hi and TIA! I have an export procedure that exports my data from my
datagrids to excel. The problem is that I lose leading zero's cause excel
removes them and doesn't treat them as text. Is it possible to design an
excel template file, place it in my shared network folder and have the
procedure write data to the template file? I've thought of reading the
recordset line by line, field by field and concatenating an apostrophe at
the beginning of each field, but this seems a little overboard and some of
the recordsets are quit large. I'm open for any advice or if you could
point me in the correct direction I would appreciate it. Thanks!

Oct 2 '08 #2
Julia, Thanks but it still removes the leading zero's when I export the
grid. I'll keep looking and if I come up with something will post back.
Thanks!
"Julia B" <Ju****@discussions.microsoft.comwrote in message
news:98**********************************@microsof t.com...
Hi, I had this problem also. This is an asp.net 1.1 solution - I don't
know
what version you're working in but I'm sure there'll be something similar
in
all versions. You can add a text attribute to your datagrid after it's
databound which ensures Excel treats the data as text and doesn't remove
leading zeros:

For rowPos As Integer = 0 To DataGrid.Items.Count - 1
For colPos As Integer = 0 To
DataGrid.Items(rowPos).Cells.Count - 1

DataGrid.Items(rowPos).Cells(colPos).Attributes.Ad d("class", "text")
Next
Next

Hope this helps.
Julia

"Reggie" wrote:
>Hi and TIA! I have an export procedure that exports my data from my
datagrids to excel. The problem is that I lose leading zero's cause
excel
removes them and doesn't treat them as text. Is it possible to design an
excel template file, place it in my shared network folder and have the
procedure write data to the template file? I've thought of reading the
recordset line by line, field by field and concatenating an apostrophe at
the beginning of each field, but this seems a little overboard and some
of
the recordsets are quit large. I'm open for any advice or if you could
point me in the correct direction I would appreciate it. Thanks!

Oct 2 '08 #3
"Reggie" <ch*********@yahoo.comwrote in message
news:%2******************@TK2MSFTNGP03.phx.gbl...
>>Hi and TIA! I have an export procedure that exports my data from my
DataGrids to Excel. The problem is that I lose leading zeroes because
Excel removes them and doesn't treat them as text. Is it possible to
design

Hi, I had this problem also. This is an ASP.NET 1.1 solution - I don't
know what version you're working in but I'm sure there'll be something
similar in all versions. You can add a text attribute to your DataGrid
after it's
databound which ensures Excel treats the data as text and doesn't remove
leading zeros:

Julia, Thanks but it still removes the leading zeroes when I export the
grid. I'll keep looking and if I come up with something will post back.
Have you tried prefixing the data with an apostrophe...?

E.g. '000123
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Oct 2 '08 #4
I was going to say about the same thing.

I ended up putting an "@" in front of the value.

' would be even more abrupt.

"Mark Rae [MVP]" <ma**@markNOSPAMrae.netwrote in message
news:ez**************@TK2MSFTNGP06.phx.gbl...
"Reggie" <ch*********@yahoo.comwrote in message
news:%2******************@TK2MSFTNGP03.phx.gbl...
>>>Hi and TIA! I have an export procedure that exports my data from my
DataGrids to Excel. The problem is that I lose leading zeroes because
Excel removes them and doesn't treat them as text. Is it possible to
design

Hi, I had this problem also. This is an ASP.NET 1.1 solution - I don't
know what version you're working in but I'm sure there'll be something
similar in all versions. You can add a text attribute to your DataGrid
after it's
databound which ensures Excel treats the data as text and doesn't remove
leading zeros:

Julia, Thanks but it still removes the leading zeroes when I export the
grid. I'll keep looking and if I come up with something will post back.

Have you tried prefixing the data with an apostrophe...?

E.g. '000123
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Oct 2 '08 #5
Mark, That's my next step. Like I said some of these recordsets are quit
large, so was thinking this may be a little slow. I'll try and let u know.
Thanks!

Reggie

"Mark Rae [MVP]" <ma**@markNOSPAMrae.netwrote in message
news:ez**************@TK2MSFTNGP06.phx.gbl...
"Reggie" <ch*********@yahoo.comwrote in message
news:%2******************@TK2MSFTNGP03.phx.gbl...
>>>Hi and TIA! I have an export procedure that exports my data from my
DataGrids to Excel. The problem is that I lose leading zeroes because
Excel removes them and doesn't treat them as text. Is it possible to
design

Hi, I had this problem also. This is an ASP.NET 1.1 solution - I don't
know what version you're working in but I'm sure there'll be something
similar in all versions. You can add a text attribute to your DataGrid
after it's
databound which ensures Excel treats the data as text and doesn't remove
leading zeros:

Julia, Thanks but it still removes the leading zeroes when I export the
grid. I'll keep looking and if I come up with something will post back.

Have you tried prefixing the data with an apostrophe...?

E.g. '000123
--
Mark Rae
ASP.NET MVP
http://www.markrae.net
Oct 2 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Matt | last post by:
I have an ASP page that calls ASP routines that I created that execute a database query and return the results to a recordset. I then iterate...
5
by: Maria L. | last post by:
Hi, I need to export the content of a DataGrid (in Windows application in C#), into an Excel spreadsheet. Anyone knows how to do this? Any...
2
by: Siu | last post by:
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();...
6
by: Elena | last post by:
I'm trying to export data to an Excel worksheet. I can export the data in the cell values perfectly. I need the code to change a header and...
13
by: Hemant Sipahimalani | last post by:
The following piece of code is being used to export HTML to excel. HttpContext.Current.Response.ContentType = "application/vnd.ms-excel"...
5
by: Simon | last post by:
Dear reader, With the export command you can export a query to Excel. By activate this command a form pop's up with the following text:
1
by: smaczylo | last post by:
Hello, I've recently been asked to work with Microsoft Access, and while I feel quite comfortable with Excel, I'm at a complete loss with...
1
by: CoolFactor | last post by:
MY CODE IS NEAR THE BOTTOM I want to export this Access query into Excel using a command button on an Access form in the following way I describe...
3
by: =?Utf-8?B?YzY3NjIyOA==?= | last post by:
Hi all, I have a question for you. I have a .csv file which has many lines of data. Each line has many data fields which are delimited by ","....
2
hemantbasva
by: hemantbasva | last post by:
Note We need to have a template on server for generating report in multiple sheet as we do not had msoffice on server moreover this require a batch...
0
by: tammygombez | last post by:
Hey fellow JavaFX developers, I'm currently working on a project that involves using a ComboBox in JavaFX, and I've run into a bit of an issue....
0
by: tammygombez | last post by:
Hey everyone! I've been researching gaming laptops lately, and I must say, they can get pretty expensive. However, I've come across some great...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...

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.