473,395 Members | 1,443 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,395 software developers and data experts.

Datagrid to Excel: Retain leading zeros?

I need to export a datagrid to Excel.
I could did this. But, also need to keep the leading
zeros in the data.
How can I acheive this?

Any help would be appreciated.

--
Thanking you in anticipation,
Regards,
Samik.
Oct 13 '05 #1
5 11465

"samik_tanik" <sa*********@hotmail.com> wrote in message
news:D8**********************************@microsof t.com...
I need to export a datagrid to Excel.
I could did this. But, also need to keep the leading
zeros in the data.
How can I acheive this?

Any help would be appreciated.

--
Thanking you in anticipation,
Regards,
Samik.


Perhaps the following article and its references will help:

http://support.microsoft.com/default...b;en-us;317719

It sounds like you are trying to export a field containing numbers with
leading zeros and Excel is seeing it as a numeric field. To keep the leading
zeros, you'll need to add string punctuation.
Oct 13 '05 #2
Hi Peter,

Thanks.
Yes, there are integer data.
I am creating the datagrid at runtime and render its data in html.
Please find the code snnipet as below:

response.Charset = ""
response.ContentType = "application/vnd.ms-excel"
Dim stringWrite As New System.IO.StringWriter
Dim htmlWrite As New System.Web.UI.HtmlTextWriter(stringWrite)
Dim dg As New DataGrid
dg.DataSource = <datasource>
dg.DataBind()
dg.RenderControl(htmlWrite)
response.Write(stringWrite.ToString)

Please suggest how to honour the leading zeros.

Thanking you in anticipation,
Regards,
Samik.
"Peter van der Goes" wrote:

"samik_tanik" <sa*********@hotmail.com> wrote in message
news:D8**********************************@microsof t.com...
I need to export a datagrid to Excel.
I could did this. But, also need to keep the leading
zeros in the data.
How can I acheive this?

Any help would be appreciated.

--
Thanking you in anticipation,
Regards,
Samik.


Perhaps the following article and its references will help:

http://support.microsoft.com/default...b;en-us;317719

It sounds like you are trying to export a field containing numbers with
leading zeros and Excel is seeing it as a numeric field. To keep the leading
zeros, you'll need to add string punctuation.

Oct 13 '05 #3

"samik_tanik" <sa*********@hotmail.com> wrote in message
news:6B**********************************@microsof t.com...
Hi Peter,

Thanks.
Yes, there are integer data.
I am creating the datagrid at runtime and render its data in html.
Please find the code snnipet as below:

response.Charset = ""
response.ContentType = "application/vnd.ms-excel"
Dim stringWrite As New System.IO.StringWriter
Dim htmlWrite As New System.Web.UI.HtmlTextWriter(stringWrite)
Dim dg As New DataGrid
dg.DataSource = <datasource>
dg.DataBind()
dg.RenderControl(htmlWrite)
response.Write(stringWrite.ToString)

Please suggest how to honour the leading zeros.

Thanking you in anticipation,
Regards,
Samik.

As I mentioned, you are going to have to convert the integers to strings if
you expect to retain the leading zeros, probably when the fields are
extracted from the datasource. What is the datasource, and are these numbers
stored as integers in it? I'm having a bit of trouble envisioning an integer
field displayed in a DataGrid with leading zeros.
Oct 13 '05 #4
The datasource is either a dataset or a datareader which is populated by a
sqlcommand, calling a stored proc.
Few integer data is shown and I want to add a single quote before each
column value so that they are treated as string by excel.
Can it be done using Regex or any; please suggest.

--
Thanking you in anticipation,
Regards,
Samik.
"Peter van der Goes" wrote:

"samik_tanik" <sa*********@hotmail.com> wrote in message
news:6B**********************************@microsof t.com...
Hi Peter,

Thanks.
Yes, there are integer data.
I am creating the datagrid at runtime and render its data in html.
Please find the code snnipet as below:

response.Charset = ""
response.ContentType = "application/vnd.ms-excel"
Dim stringWrite As New System.IO.StringWriter
Dim htmlWrite As New System.Web.UI.HtmlTextWriter(stringWrite)
Dim dg As New DataGrid
dg.DataSource = <datasource>
dg.DataBind()
dg.RenderControl(htmlWrite)
response.Write(stringWrite.ToString)

Please suggest how to honour the leading zeros.

Thanking you in anticipation,
Regards,
Samik.

As I mentioned, you are going to have to convert the integers to strings if
you expect to retain the leading zeros, probably when the fields are
extracted from the datasource. What is the datasource, and are these numbers
stored as integers in it? I'm having a bit of trouble envisioning an integer
field displayed in a DataGrid with leading zeros.

Oct 14 '05 #5
Jan
Hi Samik,

What you really need it to apply a number format to all the cells you want
to have leading zeros. If you convert all numbers to strings, you will get
Excel "Number stored as text" warnings and that numbers will be treated as
text (and ignored in formulas).

You have few third-party components that can generate native XLS (together
with number format). If amount of data you are exporting is not large (less
than 5 sheets and 150 rows per sheet), you have our ExcelLite Free component
you can freely use in commercial apps. If your worksheet grows in size, you
can easily update to ExcelLite Professional. Check
http://www.gemboxsoftware.com for more information.

Jan

"samik_tanik" <sa*********@hotmail.com> wrote in message
news:6B**********************************@microsof t.com...
Hi Peter,

Thanks.
Yes, there are integer data.
I am creating the datagrid at runtime and render its data in html.
Please find the code snnipet as below:

response.Charset = ""
response.ContentType = "application/vnd.ms-excel"
Dim stringWrite As New System.IO.StringWriter
Dim htmlWrite As New System.Web.UI.HtmlTextWriter(stringWrite)
Dim dg As New DataGrid
dg.DataSource = <datasource>
dg.DataBind()
dg.RenderControl(htmlWrite)
response.Write(stringWrite.ToString)

Please suggest how to honour the leading zeros.

Thanking you in anticipation,
Regards,
Samik.
"Peter van der Goes" wrote:

"samik_tanik" <sa*********@hotmail.com> wrote in message
news:D8**********************************@microsof t.com...
>I need to export a datagrid to Excel.
> I could did this. But, also need to keep the leading
> zeros in the data.
> How can I acheive this?
>
> Any help would be appreciated.
>
> --
> Thanking you in anticipation,
> Regards,
> Samik.


Perhaps the following article and its references will help:

http://support.microsoft.com/default...b;en-us;317719

It sounds like you are trying to export a field containing numbers with
leading zeros and Excel is seeing it as a numeric field. To keep the
leading
zeros, you'll need to add string punctuation.

Oct 14 '05 #6

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

Similar topics

1
by: mmmgood1 | last post by:
Help, I'm linking an excel spreadsheet in access and I have datafields with leading zeros (01021). When the file is linked in access, I get a #num in the field with the leading zeros. The zeros...
6
by: Clint Stowers | last post by:
Using A2k Exporting a query to a CSV file. The problem is any text fields (i.e. 000345) lose any leading zeros. Exporting to an excel file this problem does not exist. Tried to create a...
5
by: samik_tanik | last post by:
I need to export a datagrid to Excel. I could did this. But, also need to keep the leading zeros in the data. How can I acheive this? Any help would be appreciated. -- Thanking you in...
6
by: Rich Raffenetti | last post by:
How can one format an integer into a hex string with leading zeros? Suppose an integer is 512 which in Hex is 200. I wish to print the 4-byte integer as 0200 or even 0x0200. The HEX function...
3
by: ineedahelp | last post by:
Can anyone help me...I am trying to output my access report to excel. One of my fields is formatted as text, but excel is dropping leading zeros...only on the records where all values are numeric. ...
7
by: leninv | last post by:
Hi, I have the following code where 'recs' is a record set. For i=0 to recs.Fields.Count - 1 if i = 0 then pindnt = string(itmlvl*2," ") response.write pindnt &...
6
by: JimmyKoolPantz | last post by:
Task: Customer wants a script of the data that was processed in a "CSV" file. Problem: Zip-Code leading zeros are dropped Basically we have a client that has requested a custom script for...
0
by: Monty | last post by:
Hi All, I am having a problem with leading zeros being stripped from fields in a CSV file when I bring them in using Jet/OleDB. In VB.Net/VS 2008, I am accessing a CSV file like so: sSQL =...
3
by: Jessica Tubbs | last post by:
Hi, I am trying to add leading zeros to a field but the zeros are not displying in the results. The code below will display the added zeros because I have a space at the beginning of my leading...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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...

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.