473,396 Members | 1,966 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 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 2514
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 through the recordset and display the data in a table....
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 code snippets would help! thanks a lot, Maria
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(); Response.Buffer = true; Response.ContentType =...
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 footer for the worksheet, not for the columns. Is...
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 databases. If someone could help me with this issue I'm...
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 below. Below you will find the simple query I am...
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 ",". Now I need to extract part of data from this...
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 job to delete excel file created by the...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
Oralloy
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.