473,695 Members | 2,424 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 11503

"samik_tani k" <sa*********@ho tmail.com> wrote in message
news:D8******** *************** ***********@mic rosoft.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.Charse t = ""
response.Conten tType = "applicatio n/vnd.ms-excel"
Dim stringWrite As New System.IO.Strin gWriter
Dim htmlWrite As New System.Web.UI.H tmlTextWriter(s tringWrite)
Dim dg As New DataGrid
dg.DataSource = <datasource>
dg.DataBind()
dg.RenderContro l(htmlWrite)
response.Write( stringWrite.ToS tring)

Please suggest how to honour the leading zeros.

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

"samik_tani k" <sa*********@ho tmail.com> wrote in message
news:D8******** *************** ***********@mic rosoft.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_tani k" <sa*********@ho tmail.com> wrote in message
news:6B******** *************** ***********@mic rosoft.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.Charse t = ""
response.Conten tType = "applicatio n/vnd.ms-excel"
Dim stringWrite As New System.IO.Strin gWriter
Dim htmlWrite As New System.Web.UI.H tmlTextWriter(s tringWrite)
Dim dg As New DataGrid
dg.DataSource = <datasource>
dg.DataBind()
dg.RenderContro l(htmlWrite)
response.Write( stringWrite.ToS tring)

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_tani k" <sa*********@ho tmail.com> wrote in message
news:6B******** *************** ***********@mic rosoft.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.Charse t = ""
response.Conten tType = "applicatio n/vnd.ms-excel"
Dim stringWrite As New System.IO.Strin gWriter
Dim htmlWrite As New System.Web.UI.H tmlTextWriter(s tringWrite)
Dim dg As New DataGrid
dg.DataSource = <datasource>
dg.DataBind()
dg.RenderContro l(htmlWrite)
response.Write( stringWrite.ToS tring)

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_tani k" <sa*********@ho tmail.com> wrote in message
news:6B******** *************** ***********@mic rosoft.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.Charse t = ""
response.Conten tType = "applicatio n/vnd.ms-excel"
Dim stringWrite As New System.IO.Strin gWriter
Dim htmlWrite As New System.Web.UI.H tmlTextWriter(s tringWrite)
Dim dg As New DataGrid
dg.DataSource = <datasource>
dg.DataBind()
dg.RenderContro l(htmlWrite)
response.Write( stringWrite.ToS tring)

Please suggest how to honour the leading zeros.

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

"samik_tani k" <sa*********@ho tmail.com> wrote in message
news:D8******** *************** ***********@mic rosoft.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
4550
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 are needed. I've formated the field to be a text field, general number, and number and still I get the #num! error, or the leading zero is dropped. Can someone help before I pull more of my hair. Thanks a bunch.
6
5301
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 SpecificationName via the Export Wizard without success. Obviously doing something wrong.
5
499
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 anticipation, Regards,
6
19179
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 doesn't create leading zeros. The Format function (format(value,"X") doesn't create leading zeros. I believe there should be a simple way that doesn't involving measuring and padding the string.
3
4564
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. The alphanumberic records keep the leading zeros. If someone could supply the vba it would be much appreciated. Thank you for any help!
7
12298
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 & recs(i) else Response.write recs(i)
6
7757
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 each file that he has us process. He wants this in a Comma Delimited Format.
0
4097
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 = "SELECT * FROM " sConnStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _ Microsoft.VisualBasic.FileIO.FileSystem.GetParentPath(msFile) & _
3
2867
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 zeros: SELECT ' 0000000'+ STR(DATE_FIELD,7,0) as DATEFMT FROM tbl_1
0
9126
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, 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...
0
9002
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8833
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
6500
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
5841
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
4588
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3021
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
2283
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1984
bsmnconsultancy
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...

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.