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

converting to excel - strings that look like numbers

I'm using the following function (I'm displaying the guts of it only) to
convert a datatable to an excel spreadsheet:

For Each mrow In dt.Rows
rowindex += 1
colindex = 0
For Each col In dt.Columns
colindex += 1
objws.Cells(rowindex, colindex) = mrow(col.ColumnName).ToString()
Next
Next

This works fine, but if there's a string which looks like a number, prefix
'0's are dropped - eg, '07' become '7'. Is there any way to avoid this and
have the .xls file display '07'?

Thanks for any help.

Bernie Yaeger
Nov 20 '05 #1
2 1068
Hi Bernie,
You should add a ' as the first char of the values you
pass to Excel, it then will be seen as a string.
OTH
Patrick Penet
"Bernie Yaeger" <be*****@cherwellinc.com> a écrit dans le message de news:eN****************@TK2MSFTNGP12.phx.gbl...
I'm using the following function (I'm displaying the guts of it only) to
convert a datatable to an excel spreadsheet:

For Each mrow In dt.Rows
rowindex += 1
colindex = 0
For Each col In dt.Columns
colindex += 1
objws.Cells(rowindex, colindex) = mrow(col.ColumnName).ToString()
Next
Next

This works fine, but if there's a string which looks like a number, prefix
'0's are dropped - eg, '07' become '7'. Is there any way to avoid this and
have the .xls file display '07'?

Thanks for any help.

Bernie Yaeger

Nov 20 '05 #2
Hi Patrick,

I got this answer somewhat earlier on an Excel newsgroup, and it works fine.

Thanks very much!

Bernie

"Patrick Penet" <ph***********@club-internet.fr> wrote in message
news:40**********************@news.club-internet.fr...
Hi Bernie,
You should add a ' as the first char of the values you
pass to Excel, it then will be seen as a string.
OTH
Patrick Penet
"Bernie Yaeger" <be*****@cherwellinc.com> a écrit dans le message de

news:eN****************@TK2MSFTNGP12.phx.gbl...
I'm using the following function (I'm displaying the guts of it only) to
convert a datatable to an excel spreadsheet:

For Each mrow In dt.Rows
rowindex += 1
colindex = 0
For Each col In dt.Columns
colindex += 1
objws.Cells(rowindex, colindex) = mrow(col.ColumnName).ToString()
Next
Next

This works fine, but if there's a string which looks like a number, prefix '0's are dropped - eg, '07' become '7'. Is there any way to avoid this and have the .xls file display '07'?

Thanks for any help.

Bernie Yaeger


Nov 20 '05 #3

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

Similar topics

7
by: sakitah | last post by:
Hello Everyone, Here's the problem: I have a string that I break down into 3 other strings as such: string1 = "001-202-1234567" and parsing it into: string2 = "001";
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...
4
by: Bernie Yaeger | last post by:
I use the following writexml method to convert a dataset/datatable to .xml: ds.WriteXml(mstrpath, XmlWriteMode.WriteSchema) ds.WriteXmlSchema(mstrpathxsd) The path strings are simple full...
30
by: zexpe | last post by:
I have an extremely cpu/data intensive piece of code that makes heavy use of the following function: void convertToDouble(const std::string& in, double& out) { out = atof(in.c_str()); } I...
1
by: UKuser | last post by:
Hi Guys, I have a program which converts Excel spreadsheets to Javascript and allows interactivity. However it can't convert it to PHP, which is obviously better for users to view (in case J/S...
5
by: Testguy | last post by:
Hi, I was wondering if one the smart people that frequent this group could give me a hand with a small program I am attempting to debug. I am not a highly experienced developer, but can...
6
by: simchajoy2000 | last post by:
Hi, So I do actually know how to read excel into VB.NET using the following approach: With oConn2 .ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data source=" & FilePath & ";Extended...
2
by: CoreyWhite | last post by:
Problem: You have numbers in string format, but you need to convert them to a numeric type, such as an int or float. Solution: You can do this with the standard library functions. The...
3
by: MM | last post by:
Hi to all, I'm trying to import a tab separated values file onto Excel with the following script: import csv from pyExcelerator import * w = Workbook() worksheet = w.add_sheet('sim1')
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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,...
0
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...

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.